Skip to content

Conversation

@potatoqualitee
Copy link
Member

Enhances the -SetSourceOffline parameter to work like -SetSourceReadOnly, setting databases offline BEFORE migration begins (not after) to prevent any connections to source databases during the migration process.

Closes #9156

Generated with Claude Code

…uring migration

This enhances the -SetSourceOffline parameter to work like -SetSourceReadOnly,
setting databases offline BEFORE migration begins (not after) to prevent any
connections to source databases during the migration process.

Changes:
- Start-DbaMigration.ps1: Added parameter and documentation
- Copy-DbaDatabase.ps1: Modified to set offline before migration, online on destination
- Tests updated to include new parameter in validation

(do Start-DbaMigration, Copy-DbaDatabase)

Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
@potatoqualitee
Copy link
Member Author

@claude add an integration test

@claude
Copy link

claude bot commented Nov 30, 2025

Claude finished @potatoqualitee's task —— View job


Integration test added for -SetSourceOffline

  • Read the modified command files to understand the new parameter
  • Read the existing test file to understand test structure
  • Add integration test for -SetSourceOffline parameter
  • Commit and push changes

Summary of changes:
The PR modifies -SetSourceOffline to work like -SetSourceReadOnly - setting databases offline BEFORE migration (not after) to prevent connections during migration. When combined with -Reattach, databases are brought back online after being reattached to the source.

Test added:
Added a new context "When using SetSourceOffline parameter" that verifies:

  • Source database is set offline before migration
  • Migration completes successfully
  • Destination database is brought online
  • Source database remains offline after migration

The test creates a dedicated test database, migrates it with -SetSourceOffline, and verifies the expected behavior at each step.


| Branch: claude/issue-9156-20251128-1729

…eter

(do Start-DbaMigration)

Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
@potatoqualitee
Copy link
Member Author

@claude hullo pls fix the test failures

Path : Start-DbaMigration/When using SetSourceOffline parameter/Should set source database offline before migration and bring destination online
Name : It Should set source database offline before migration and bring destination online
Result : Failed
Message : ErrorRecord: A parameter cannot be found that matches parameter name 'Database'. This error might have been caused by applying the default parameter binding. You can disable the default parameter binding in
$PSDefaultParameterValues by setting $PSDefaultParameterValues["Disabled"] to be $true, and then trying again. The following default parameters were successfully bound for this cmdlet when the error occurred:
-Confirm -WarningVariable
StackTrace :
RawErrorRecord : A parameter cannot be found that matches parameter name 'Database'. This error might have been caused by applying the default parameter binding. You can disable the default parameter binding in
$PSDefaultParameterValues by setting $PSDefaultParameterValues["Disabled"] to be $true, and then trying again. The following default parameters were successfully bound for this cmdlet when the error occurred:
-Confirm -WarningVariable
Uploading artifact DetailedTestFailures_Pester5.json (1,813 bytes)...100%

@claude
Copy link

claude bot commented Nov 30, 2025

Claude finished @potatoqualitee's task —— View job


Test failure fixed

  • Read the failing test to understand the error
  • Read Start-DbaMigration.ps1 to understand correct parameter usage
  • Fix the test to use correct parameters
  • Commit and push the fix

Issue found: The test was using -Database parameter which doesn't exist on Start-DbaMigration. The command migrates all databases and doesn't support filtering to specific databases (only -Exclude for exclusions).

Fix applied:

  • Removed the invalid -Database $offlineTestDb parameter from the test
  • Added proper -Exclude parameter to skip non-database migration objects (same pattern as other tests in the file)
  • Added verification that the test database was included in the migration results
  • Test now migrates all databases and then verifies the specific test database was handled correctly with the -SetSourceOffline behavior

The test will now properly validate that -SetSourceOffline sets databases offline before migration and leaves them offline on the source while bringing them online on the destination.

--- | Branch: claude/issue-9156-20251128-1729

(do Start-DbaMigration)

Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
@potatoqualitee
Copy link
Member Author

@claude failed tests

ls_messages_and_errors.xml.zip (26,876 bytes)...100%
Failed tests summary:
Path : Start-DbaMigration/When using backup restore method/Should copy databases successfully
Name : It Should copy databases successfully
Result : Failed
Message : Test failed but no error message could be extracted. Result: Failed | Test Name: Should copy databases successfully
StackTrace :
RawErrorRecord : No ErrorRecord
Path : Start-DbaMigration/When using backup restore method/Should retain database properties after migration
Name : It Should retain database properties after migration
Result : Failed
Message : Test failed but no error message could be extracted. Result: Failed | Test Name: Should retain database properties after migration
StackTrace :
RawErrorRecord : No ErrorRecord
Path : Start-DbaMigration/When using backup restore method/Should return at least one result
Name : It Should return at least one result
Result : Failed
Message : Test failed but no error message could be extracted. Result: Failed | Test Name: Should return at least one result
StackTrace :
RawErrorRecord : No ErrorRecord
Path : Start-DbaMigration/When using last backup method/Should copy databases successfully
Name : It Should copy databases successfully
Result : Failed
Message : Test failed but no error message could be extracted. Result: Failed | Test Name: Should copy databases successfully
StackTrace :
RawErrorRecord : No ErrorRecord
Path : Start-DbaMigration/When using last backup method/Should retain database properties after migration
Name : It Should retain database properties after migration
Result : Failed
Message : Test failed but no error message could be extracted. Result: Failed | Test Name: Should retain database properties after migration
StackTrace :
RawErrorRecord : No ErrorRecord
Path : Start-DbaMigration/When using last backup method/Should return at least one result
Name : It Should return at least one result
Result : Failed
Message : Test failed but no error message could be extracted. Result: Failed | Test Name: Should return at least one result
StackTrace :
RawErrorRecord : No ErrorRecord
Path : Start-DbaMigration/When using SetSourceOffline parameter/Should set source database offline before migration and bring destination online
Name : It Should set source database offline before migration and bring destination online
Result : Failed
Message : ErrorRecord: Expected a value, but got $null or empty.
StackTrace :
RawErrorRecord : Expected a value, but got $null or empty.

@claude
Copy link

claude bot commented Dec 1, 2025

Claude finished @potatoqualitee's task —— View job


Test failures fixed

  • Read the test file to understand the failing tests
  • Analyze the error messages and patterns
  • Read the command implementation to understand expected behavior
  • Identify the root cause of failures
  • Fix the command to return database migration results
  • Commit and push the fix

Root cause: Start-DbaMigration was calling Copy-DbaDatabase but not returning its output. Tests expected results with Type, Status, and Name properties to verify database migrations, but the function returned nothing.

Fix applied: Modified Start-DbaMigration.ps1:439-441 to output the results from Copy-DbaDatabase. This allows tests to:

  • Verify migration completed successfully
  • Check database migration status
  • Validate specific database properties
  • Test the new -SetSourceOffline parameter behavior

The function now properly returns database migration results for test verification while maintaining all existing functionality.


| Branch: claude/issue-9156-20251128-1729

github-actions bot and others added 5 commits December 1, 2025 06:41
… verification

(do Start-DbaMigration)

Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>
Updated the role filtering logic in Copy-DbaServerRole to exclude the 'public' role in addition to fixed roles. This prevents unintended copying of the 'public' role to the target server.
Enhanced test setup and cleanup to handle offline databases and cross-platform backup paths. Added robust cleanup using T-SQL, improved backup directory handling for Linux/Docker, and refactored tests to ensure accurate migration and status checks. Also updated exclusions and variable usage for clarity and reliability.
SetSourceOffline is now applied before detach for DetachAttach and after backup for BackupRestore to ensure proper connection handling. Added integration tests to verify offline state after migration and cleanup logic for offline databases.

(do Start-DbaMigration)
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.

Add -SetSourceOffline to Start-DbaMigration

1 participant