Skip to content

Fixed an issue where Schema Diff emitted column alterations before DR… - #10941

Closed
hrkn wants to merge 1 commit into
pgadmin-org:masterfrom
hrkn:fix/schema-diff-constraint-drop-order
Closed

hrkn wants to merge 1 commit into
pgadmin-org:masterfrom
hrkn:fix/schema-diff-constraint-drop-order

Conversation

@hrkn

@hrkn hrkn commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

…OP CONSTRAINT for removed or recreated constraints. #10940

  • Emit DROP CONSTRAINT statements before column changes in BaseTableView.get_sql().

  • Record the target constraint definition in deleted when SchemaDiffTableCompare.table_constraint_comp() recreates a constraint.

  • Add unit tests covering constraint drop ordering and recreated constraint deleted entries.

Summary by CodeRabbit

  • Bug Fixes
    • Table updates now drop deleted constraints before changing columns and add or recreate constraints afterward, reducing migration errors.
    • Recreated constraints now use the target table’s definition, including its columns and included columns.
    • SQL generation now handles deletions separately from additions and changes for foreign key, primary key, unique, check, and exclusion constraints.

…OP CONSTRAINT for removed or recreated constraints. pgadmin-org#10940

- Emit DROP CONSTRAINT statements before column changes in BaseTableView.get_sql().

- Record the target constraint definition in deleted when SchemaDiffTableCompare.table_constraint_comp() recreates a constraint.

- Add unit tests covering constraint drop ordering and recreated constraint deleted entries.
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Schema Diff now generates constraint-drop SQL before column changes. Constraint comparisons record target definitions as deleted when constraints are recreated. Tests cover drop ordering, recreated constraints, and SQL formatting.

Changes

Schema Diff constraint updates

Layer / File(s) Summary
Constraint deletion data and SQL
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/schema_diff_table_utils.py, web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/*/utils.py, web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/tests/test_index_constraint_delete_sql_unit.py, web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_constraint_drop_order_unit.py
When a constraint is recreated, the target definition is recorded as deleted. Constraint utilities expose delete-only SQL helpers and an include_deleted option, which defaults to True. Tests cover delete-only SQL and recreated-constraint diff data.
Table update drop ordering
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py, web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_constraint_drop_order_unit.py
Table updates emit deleted-constraint SQL before column changes, then exclude deleted constraints from later constraint SQL generation. Tests cover drop ordering, reverse migrations, and SQL formatting.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

Suggested reviewers: dpage

Merge Risk: Minimal · up to 59be7

Schema Diff now drops constraints before altering columns, which matches the ordering PostgreSQL requires. Recreated constraints also produce correct drop definitions. No merge-blocking risk was identified, and the tests cover the changed ordering and formatting behaviour.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says Schema Diff emitted column alterations before DROP statements, which is the ordering bug this PR fixes. The changeset moves DROP CONSTRAINT statements for deleted or recreated constrain…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title says Schema Diff emitted column alterations before DROP statements, which is the ordering bug this PR fixes. The changeset moves DROP CONSTRAINT statements for deleted or recreated constraints ahead of column changes in BaseTableView.get_sql(), and adds tests for that ordering. The title is truncated mid-word ("DR…"), which reduces clarity, but the main change is still identifiable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 55bb06e and 59be780.

Files selected for processing: 8

  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/utils.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/utils.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/utils.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/tests/test_index_constraint_delete_sql_unit.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/utils.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/schema_diff_table_utils.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/tests/test_table_constraint_drop_order_unit.py
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@hrkn

hrkn commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Closing this PR as #10940 is a duplicate of #10891, which was already fixed in #10892 (5ef9ad360c4). Thank you!

@hrkn hrkn closed this Dec 3, 2026
@hrkn
hrkn deleted the fix/schema-diff-constraint-drop-order branch December 3, 2026 23:16
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.

1 participant