Skip to content

Propagate column renames to FK and unique constraints in the table dialog (#9060)#10046

Merged
asheshv merged 3 commits into
pgadmin-org:masterfrom
dpage:fix-9060-column-rename-fk-unique
Jun 12, 2026
Merged

Propagate column renames to FK and unique constraints in the table dialog (#9060)#10046
asheshv merged 3 commits into
pgadmin-org:masterfrom
dpage:fix-9060-column-rename-fk-unique

Conversation

@dpage

@dpage dpage commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9060.

In the Create Table dialog, renaming a column already propagated to the primary key definition, but foreign key and unique constraint definitions kept referencing the old column name — producing wrong/broken DDL.

Fix: mirror the existing PK rename-propagation logic in the foreign_key and unique_constraint depChange handlers — on a column name SET_VALUE in a new table, rewrite the old name to the new name in each FK's columns[].local_column and each unique constraint's columns[].column. Also added 'columns' to the unique constraint's deps so its depChange fires on column edits (FK already had it).

Changes

  • table.ui.js (one file)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Create Table dialog now correctly propagates column renames to foreign key and unique constraint references so constraints reflect updated column names.
  • Documentation

    • Release notes updated to document the bug fix.
  • Tests

    • Added a test verifying rename propagation updates constraint references during table creation.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d838519-04f4-4da0-adff-33be92c0f389

📥 Commits

Reviewing files that changed from the base of the PR and between 0924f9c and 9a45a32.

📒 Files selected for processing (1)
  • docs/en_US/release_notes_9_16.rst
✅ Files skipped from review due to trivial changes (1)
  • docs/en_US/release_notes_9_16.rst

Walkthrough

This PR fixes a bug where renaming a column in the Create Table dialog failed to update references to that column within foreign key and unique constraint definitions by extending depChange handlers to propagate the new column name; tests and release notes were added.

Changes

Column Rename Propagation in Constraints

Layer / File(s) Summary
Foreign Key and Unique Constraint depChange handlers
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js
Extended depChange logic to detect SCHEMA_STATE_ACTIONS.SET_VALUE on columns[*].name and remap dependent constraint references: foreign key local_column, unique constraint columns[*].column, and unique_constraint include entries. Handlers now receive source, topState, and actionObj.
Test coverage for column rename propagation
web/regression/javascript/schema_ui_files/table.ui.spec.js
Added Jest test depChange column rename propagation verifying rename propagation for foreign key local columns, unique constraint columns, and unique_constraint INCLUDE lists in create-path scenarios.
Release notes documentation
docs/en_US/release_notes_9_16.rst
Added Issue #9060 bullet under Version 9.16 Bug fixes documenting the Create Table fix where renaming a column updates constraint references.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • pgadmin-org/pgadmin4#10042: Related changes around handling stale foreign_key.local_column when computing attnum to avoid ERD delete crashes; touches foreign key handling.

Suggested reviewers

  • adityatoshniwal
  • asheshv
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: propagating column renames to FK and unique constraints in the table dialog, with the issue reference.
Linked Issues check ✅ Passed The pull request addresses all coding requirements from issue #9060: column renames now propagate to foreign key and unique constraint definitions in the Create Table dialog.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #9060: the main logic fix in table.ui.js, release notes update, and comprehensive test coverage for the rename propagation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@dpage dpage force-pushed the fix-9060-column-rename-fk-unique branch 2 times, most recently from 8c5f1c7 to eb9f462 Compare June 9, 2026 11:36
In the new-table dialog, the primary key already updated its column
references when a column was renamed, but foreign key and unique
constraint definitions did not, leaving them pointing at the old name.
Mirror the PK rename-propagation in the foreign_key and unique_constraint
depChange handlers (and add 'columns' to the unique constraint deps so it
fires on column changes).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dpage dpage force-pushed the fix-9060-column-rename-fk-unique branch from eb9f462 to c41ec7a Compare June 9, 2026 11:37
@asheshv asheshv requested a review from Copilot June 10, 2026 14:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes column-rename propagation in the Create Table dialog so constraint definitions don’t keep referencing stale column names (Issue #9060), preventing incorrect/broken generated DDL.

Changes:

  • Propagate renamed column names into foreign_key[].columns[].local_column when editing table columns in the Create Table dialog.
  • Propagate renamed column names into unique_constraint[].columns[].column and ensure the unique-constraint handler is triggered on table column edits by adding columns to deps.
  • Document the fix in the v9.16 release notes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js Adds rename-propagation logic for FK + unique constraints when a table column name changes.
docs/en_US/release_notes_9_16.rst Adds a bug-fix entry referencing Issue #9060.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/en_US/release_notes_9_16.rst Outdated
- Remap unique constraint INCLUDE columns on rename. The INCLUDE list
  holds bare name strings (not {column} objects), so renaming an
  included column previously emitted stale DDL. Now mirrors the
  primary key INCLUDE handling.
- Add regression tests covering rename propagation in depChange for
  foreign_key and unique_constraint, including the unique constraint
  INCLUDE case.
- Correct the release note wording from "Create/Edit Table" to
  "Create Table"; the propagation only runs on the new-table path
  (state.oid === undefined).

@asheshv asheshv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approach is right and the new tests cover the headline cases. Two scope items worth addressing here rather than in a follow-up:

  1. Exclusion constraints have an include list of bare column-name strings — same shape as the unique-constraint include you just fixed. The exclusion case isn't covered by the outer depChange, leaving it half-fixed for INCLUDE-clause constraints.
  2. The outer columns mapping for FK and unique in table.ui.js is largely redundant — the inner depChange handlers in foreign_key.ui.js and unique_constraint.ui.js already update local_column / column in place in create-table mode. The net-new fix is really the unique include map (and would-be exclusion include). Worth trimming so the propagation isn't claimed in two places.

@asheshv asheshv merged commit 0b4bb3e into pgadmin-org:master Jun 12, 2026
34 checks passed
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.

Updating column name does not update it on the foreign key and unique constraint columns

3 participants