AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Table Editor Save Falsely Drops And Recreates Primary Key On Rename Or Out-Of-Order Composite Key

updateTable compares PK column names in display order with primary_keys from the database (key order), causing a name change or an out-of-order composite PK to be treated as a PK change. Studio then drops and re-adds the PK in separate transactions, which fails when foreign keys reference it or silently reorders the PK.

highConfidence 82%React

Origin Analysis

updateTable compares PK membership by column names in display order against primary_keys in key order (#39414). This string-based comparison is order-sensitive and ignores stable column identity, so a rename or a composite PK like (b,a) appears different from (a,b) even when the set of columns is identical.
1. Create a table with a composite primary key (b, a) and a foreign key referencing that PK. 2. Open the Supabase Studio Table Editor and modify only a description or column comment without changing the PK. 3. Save the table. 4. Observe: save fails with 'cannot drop constraint ... other objects depend on it' if an FK references the PK, or the PK is silently rebuilt and the order changes to (a, b) if no FK exists.

Fixing Code Block

Edge Case Audit

Ensure column IDs are present and stable for all tables; for imported or legacy schemas with missing IDs, a fallback to name comparison may still reproduce the original bug. The drop/recreate itself still runs in separate transactions, so keep the change minimal and consider a future single-statement ALTER TABLE. Roll back by reverting to the previous order-sensitive comparison or pinning the Studio version if this fix causes unintended behavior.

Ecosystem Topology