Skip to content

Fixed an issue where unique/primary key constraint columns were shown in wrong order in Properties#9635

Open
balodis wants to merge 1 commit intopgadmin-org:masterfrom
balodis:fix/constraint-column-order
Open

Fixed an issue where unique/primary key constraint columns were shown in wrong order in Properties#9635
balodis wants to merge 1 commit intopgadmin-org:masterfrom
balodis:fix/constraint-column-order

Conversation

@balodis
Copy link

@balodis balodis commented Feb 14, 2026

Bug

When viewing a unique constraint or primary key in the Properties tab,
the Columns field shows columns in table-definition order instead of
the actual constraint-defined column order. For example, a constraint
UNIQUE (user_id, client_order_id) displays as client_order_id, user_id.

The SQL tab shows the correct order; only the Properties tab is wrong.

Root Cause

The fromRaw formatter in unique_constraint.ui.js and
primary_key.ui.js used _.filter(allOptions, ...), which iterates
over allOptions (table columns) and keeps matches -- preserving
allOptions order rather than backendVal order. The backend SQL
and Python code correctly return columns in constraint-defined order.

Fix

Replaced _.filter(allOptions, ...) with a .map(... _.find(...))
over backendVal, preserving the constraint column order from the backend.

Tests

Added 6 new Jest tests (3 per file) covering:

  • Cell formatter display string output
  • Type formatter fromRaw verifying constraint column order is preserved
  • Type formatter toRaw round-trip correctness

All 18 tests pass. ESLint clean.

Related

Related: #6345 (similar column ordering issue for foreign keys, fixed
separately in 7.3). This PR addresses the same class of bug in the
unique constraint and primary key Properties view.

Summary by CodeRabbit

  • Bug Fixes

    • Primary key and unique constraint columns now preserve the original constraint order when viewed and edited.
  • Tests

    • Added tests validating column formatters (display and data conversion) preserve order and handle empty/null inputs.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

This PR preserves backend-provided column order in the primary key and unique constraint UI formatters by mapping backend entries directly to option objects in fromRaw. It also adds unit tests validating cell/type formatters and toRaw behavior, including empty/null cases.

Changes

Cohort / File(s) Summary
Formatter fixes - Column order preservation
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/primary_key.ui.js, web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/unique_constraint.ui.js
Adjusted fromRaw for multi-column selects to map each backend column key to its matching option object (value === column) and filter out non-matches, preserving backend order. No change to toRaw.
Test coverage - Formatter behavior
web/regression/javascript/schema_ui_files/primary_key.ui.spec.js, web/regression/javascript/schema_ui_files/unique_constraint.ui.spec.js
Added tests for cell formatter output, type formatter preserving backend column order, and toRaw conversions; includes edge cases for empty/null inputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main fix: addressing incorrect column order display in constraint Properties. It is specific, avoids vague terms, and directly reflects the primary change across the modified files.
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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

The fromRaw formatter for the Columns field in unique constraint and
primary key properties used _.filter(allOptions, ...), which preserved
the order of allOptions (table column position) rather than the
constraint-defined column order from backendVal. Replaced with _.find
mapped over backendVal to preserve the correct constraint column order.

Added unit tests for cell and type formatter functions to verify
column ordering is preserved.
@balodis balodis force-pushed the fix/constraint-column-order branch from 5d9012a to ae4b146 Compare February 17, 2026 23:56
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.

2 participants