Skip to content

Compare-DbaDbSchema - Add new command for schema comparison via sqlpackage#10299

Open
andreasjordan wants to merge 4 commits intodevelopmentfrom
claude/issue-5342-20260331-0657
Open

Compare-DbaDbSchema - Add new command for schema comparison via sqlpackage#10299
andreasjordan wants to merge 4 commits intodevelopmentfrom
claude/issue-5342-20260331-0657

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Implements Compare-DbaDbSchema using sqlpackage's DeployReport action to compare a source DACPAC against a target database or DACPAC file, returning structured schema difference objects.

Closes #5342

Generated with Claude Code

…ckage

Implements Compare-DbaDbSchema using sqlpackage's DeployReport action to
compare a source DACPAC against a target database or DACPAC file, returning
structured schema difference objects.

Closes #5342

(do Compare-DbaDbSchema)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

@claude tests fail.

Output:

Running C:\github\dbatools\tests\Compare-DbaDbSchema.Tests.ps1 ...[11:22:16][Compare-DbaDbSchema] sqlpackage failed: *** Operation DeployReport requires a target database name.
[11:22:17][Compare-DbaDbSchema] sqlpackage failed: *** Operation DeployReport requires a target database name.
Completed C:\github\dbatools\tests\Compare-DbaDbSchema.Tests.ps1 in 76670ms


Failed tests summary:
Path           : Compare-DbaDbSchema/Compare DACPAC against a live database/Returns schema differences when source has objects not in target
Name           : It Returns schema differences when source has objects not in target
Result         : Failed
Message        : ErrorRecord: Expected 'Table' to be found in collection SqlTable, but it was not found.
StackTrace     : 
RawErrorRecord : Expected 'Table' to be found in collection SqlTable, but it was not found.
Path           : Compare-DbaDbSchema/Compare two DACPAC files/Keeps the report file when -KeepReport is specified
Name           : It Keeps the report file when -KeepReport is specified
Result         : Failed
Message        : ErrorRecord: Expected a value, but got $null or empty.
StackTrace     : 
RawErrorRecord : Expected a value, but got $null or empty.
Path           : Compare-DbaDbSchema/Compare two DACPAC files/Returns schema differences between two DACPAC files
Name           : It Returns schema differences between two DACPAC files
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
Copy Markdown

claude bot commented Mar 31, 2026

Claude finished @andreasjordan's task in 1m 50s —— View job


Fixed test failures

  • Read implementation and test files
  • Diagnose the failures
  • Fix the implementation
  • Push changes

Two bugs fixed in Compare-DbaDbSchema.ps1:

  1. DACPAC-to-DACPAC: missing /tdn: argument (public/Compare-DbaDbSchema.ps1:164)
    sqlpackage's DeployReport action requires a target database name even when the target is a DACPAC file (not a live database). Fixed by extracting the base filename of the target DACPAC and passing it as /tdn:.

  2. Type field had "Sql" prefix (public/Compare-DbaDbSchema.ps1:213)
    sqlpackage reports types as SqlTable, SqlProcedure, etc. The test expected Table, and Table is also cleaner for end users. Fixed by stripping the leading "Sql" prefix with -replace "^Sql", "".
    |

- Add /tdn: argument when comparing two DACPAC files (sqlpackage requires
  a target database name even for offline DACPAC-to-DACPAC comparisons)
- Strip 'Sql' prefix from Type field (sqlpackage returns 'SqlTable' etc.
  but 'Table' is cleaner for end users and matches test expectations)

(do Compare-DbaDbSchema)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

@claude tests fail.

Output:

Failed tests summary:
Path           : Compare-DbaDbSchema/Compare two DACPAC files/Keeps the report file when -KeepReport is specified
Name           : It Keeps the report file when -KeepReport is specified
Result         : Failed
Message        : ErrorRecord: Expected a value, but got $null or empty.
StackTrace     : 
RawErrorRecord : Expected a value, but got $null or empty.
Path           : Compare-DbaDbSchema/Compare two DACPAC files/Returns schema differences between two DACPAC files
Name           : It Returns schema differences between two DACPAC files
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
Copy Markdown

claude bot commented Mar 31, 2026

Claude finished @andreasjordan's task in 1m 45s —— View job


Fixed remaining test failures

  • Read failing test output
  • Read implementation and test files
  • Diagnose the failures
  • Fix the test file
  • Push changes

Root cause: Test state pollution — the "Returns no differences" test calls Publish-DbaDacPackage to populate $dbTargetName. The DACPAC-comparison tests then exported that now-populated DB, producing a DACPAC identical to source, so Compare-DbaDbSchema returned no differences.

Fix (tests/Compare-DbaDbSchema.Tests.ps1): Export the empty target DB to a DACPAC in the shared BeforeAll block, before any tests can modify it. The "Compare two DACPAC files" tests now use this pre-exported $emptyTargetDacpac variable directly.

…get DACPAC in BeforeAll

Export the empty target DB to a DACPAC in the shared BeforeAll block before any
tests can modify the target DB (via Publish-DbaDacPackage). This prevents the
DACPAC-to-DACPAC comparison tests from getting zero differences because the target
DB was already populated by the 'Returns no differences' test.

(do Compare-DbaDbSchema)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan andreasjordan marked this pull request as ready for review March 31, 2026 15:36
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.

Compare-DbaDbSchema - use of sqlpackage to do schema compare

1 participant