Skip to content

feat(ProjectDatabase): implement safe save functionality to prevent data loss#140

Merged
rulasg merged 10 commits intomainfrom
add-safe-flag-to-db-save
Sep 17, 2025
Merged

feat(ProjectDatabase): implement safe save functionality to prevent data loss#140
rulasg merged 10 commits intomainfrom
add-safe-flag-to-db-save

Conversation

@rulasg
Copy link
Owner

@rulasg rulasg commented Sep 17, 2025

Rename Save-ProjectDatabase to Save-ProjectDatabaseSafe function. Add Safe flag on projectdatabase to detect overiting changes out of the modification database flow.

Fixes #138

throw "Database.number is null or not a positive integer"
}

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

if (( ! $item ) -or $Force) {
"Fetching item [$ItemId] from API" | Write-Verbose

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$dirty = $true
}

return $item, $dirty

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Resolve-ProjectItem' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute. Note

The cmdlet 'Resolve-ProjectItem' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute.
@rulasg rulasg requested a review from Copilot September 17, 2025 14:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements safe save functionality for project databases to prevent data loss from concurrent modifications. The changes rename the Save-ProjectDatabase function to Save-ProjectDatabaseSafe and add a safety mechanism using a safeId flag to detect conflicting changes.

  • Adds safe save functionality with concurrent modification detection
  • Refactors existing code to use the new safe save approach
  • Introduces a new Resolve-ProjectItem helper function to reduce code duplication

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
public/project_item_staged.ps1 Updates function call to use safe save
public/project_item.ps1 Major refactoring to use safe save and new helper function
private/projectDatabase/project_database_update.ps1 Updates function name reference
private/projectDatabase/project_database_call.ps1 Uses new helper function for item resolution
private/projectDatabase/project_database_Sync.ps1 Updates to use safe save
private/projectDatabase/project_database_Item_Resolve.ps1 New helper function for item resolution
private/projectDatabase/project_database_Async.ps1 Updates to use safe save and removes redundant save call
private/projectDatabase/project_database.ps1 Core implementation of safe save mechanism
Test/public/project_item.test.ps1 Removes unused test function
Test/public/projectDatabase/project_database.test..ps1 Adds tests for safe save functionality
Notes.md Updates documentation to reflect function name changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


$Owner = "SomeOrg" ; $ProjectNumber = 164
MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2.json'

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

$prj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber
Assert-IsNotNull -Object $prj.safeId

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$oldSafeId = $prj.safeId
Save-ProjectDatabaseSafe -Database $prj
$prj2 = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

$Owner = "SomeOrg" ; $ProjectNumber = 164
MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2.json'

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Check that safeId has changed
$prj2 = Get-Project -Owner $Owner -ProjectNumber $ProjectNumber
Assert-AreNotEqual -Presented $prj2.safeId -Expected $prj1.safeId

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace

if ( ! $item ) {
"Item [$ItemId] not found in API" | Write-MyError
return $null, $false

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Resolve-ProjectItem' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute. Note

The cmdlet 'Resolve-ProjectItem' returns an object of type 'System.Object[]' but this type is not declared in the OutputType attribute.
@rulasg rulasg merged commit 2d93ddf into main Sep 17, 2025
3 of 4 checks passed
@rulasg rulasg deleted the add-safe-flag-to-db-save branch September 17, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat - Save database save

2 participants