feat(ProjectDatabase): implement safe save functionality to prevent data loss#140
feat(ProjectDatabase): implement safe save functionality to prevent data loss#140
Conversation
…e to prevent overwriting changes
…jectDatabaseV2 and save it
…base to prevent data loss
…m for database update
…ctV2toDatabase and save projectV2 to projectDatabase
…em for improved database handling
…tDatabaseSafe for clarity and safety
| throw "Database.number is null or not a positive integer" | ||
| } | ||
|
|
||
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
|
|
||
| if (( ! $item ) -or $Force) { | ||
| "Fetching item [$ItemId] from API" | Write-Verbose | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
| $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
There was a problem hiding this comment.
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-ProjectItemhelper 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
|
|
||
| $prj = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber | ||
| Assert-IsNotNull -Object $prj.safeId | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
| $oldSafeId = $prj.safeId | ||
| Save-ProjectDatabaseSafe -Database $prj | ||
| $prj2 = Get-ProjectFromDatabase -Owner $Owner -ProjectNumber $ProjectNumber | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
|
|
||
| $Owner = "SomeOrg" ; $ProjectNumber = 164 | ||
| MockCall_GitHubOrgProjectWithFields -Owner $owner -ProjectNumber $projectNumber -FileName 'projectV2.json' | ||
|
|
Check notice
Code scanning / PSScriptAnalyzer
Line has trailing whitespace Note
| # 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
|
|
||
| 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
Rename
Save-ProjectDatabasetoSave-ProjectDatabaseSafefunction. Add Safe flag on projectdatabase to detect overiting changes out of the modification database flow.Fixes #138