PhoenixKit 1.7.236: Repairing tables whose uuid is not a primary key
PhoenixKit 1.7.236 finds and fixes PhoenixKit tables whose uuid column never became a proper primary key, a state older upgrades could leave behind without anyone noticing.
On one production database, phoenix_kit_email_events had uuid as a nullable text column with no default and no primary key. Migration V163 asks PostgreSQL which phoenix_kit_* tables are in that state and repairs each one: the column type, NOT NULL, the default and the key. Before the key goes on, rows with a duplicate uuid are removed, and the number removed is logged. Tables over two million rows are skipped so a deploy does not lock them.
For those, the new mix phoenix_kit.repair_uuid task does the work in a maintenance window, building the index without a long lock. It has --dry-run and --prefix. mix phoenix_kit.doctor gets a UUID Primary Keys check.
Upgrading
Run mix phoenix_kit.update to apply V163. If its log names tables it deferred, run mix phoenix_kit.repair_uuid for them.
Full release notes: PhoenixKit 1.7.236
1.7.236 · 8 August 2026
Added
- V163 repairs
phoenix_kit_*tables whoseuuidcolumn is not a proper primary key (#688). A production database reached a state the chain claims is impossible:phoenix_kit_email_eventswithuuidascharacter varying(255), nullable, no default, and no primary key at all, while 149 other tables were correct. Three migrations each missed it for a different reason — V40’s guard tests column existence rather than type, so an older release’s Ecto:stringcolumn made V40 skip the table wholesale (backfill,NOT NULLand index included) despite the table being listed in@tables_to_migrate; V56’sensure_all_uuid_columns_native_type/2was added seventeen days after V56 shipped, and a recorded version never re-runs; V74 then dropped the legacy bigintidbut could not promote a wrong-typed nullable column to primary key, and never verified its own documented post-condition. V163 is therefore catalog-driven — it asks PostgreSQL which tables are actually broken instead of consulting a list the table was missing from every time, including the list in the migration written to repair its class of problem. mix phoenix_kit.repair_uuid(#688) — the maintenance-window path for tables V163 defers. Runs outside a transaction, so it builds the unique indexCONCURRENTLYand attaches it, holding the exclusive lock only for the attach. Supports--dry-runand--prefix.mix phoenix_kit.doctorgains a “UUID Primary Keys” check (#688). The existing type check could not see a missing key, which is what the varchar column actually cost. Its remedy is also corrected: the singleALTERit used to suggest restores the type but not theNOT NULL, the default or the key, leaving anyone who followed it literally still broken.
Fixed
- V163’s per-table isolation could never have fired (#688).
Ecto.Migration.execute/1queues a command, so the statements were flushed afterup/1returned — outside therescuethat exists to keep one table’s failure from aborting the rest of the run. A locked table would still have taken down every repair after it and skipped the version marker, the worst outcome available.flush/0runs the pending commands in scope, so the rescue actually catches. The concurrent index name is also derived from the catalog name rather than parsed back out of the quoted qualified string, which would corrupt any name containing a dot or a quote. - V163’s row-count guard now covers every repair class, not just the type
rewrite (#688 post-merge review). The guard deferred a table only when
rewrite_needed?/1was true, so a table that was alreadyuuid-typed but had no primary key skipped it at any size — and then took a full-tableDELETEself-join, aSET NOT NULLscan and a unique-index build, all underACCESS EXCLUSIVE, duringmix ecto.migrate. That is exactly the pool-exhaustion outage the two-million-row limit exists to prevent, on exactly the class of table that prompted the migration. - An interrupted
CREATE UNIQUE INDEX CONCURRENTLYno longer strandsmix phoenix_kit.repair_uuid(#688 post-merge review).CONCURRENTLYleaves anINVALIDindex behind when interrupted;IF NOT EXISTSthen skipped the rebuild on the retry andADD PRIMARY KEY USING INDEXfailed on the invalid index, permanently. The concurrent path now drops any leftover index first (CONCURRENTLY, schema-qualified per the chain’sDROP INDEXrule). mix phoenix_kit.repair_uuid <table>no longer answers a named table with the global all-clear (#688 post-merge review). A typo, a mismatched--prefix, or an already-repaired table produced an empty list and printed “✓ Every phoenix_kit table has a proper uuid primary key” — an assertion about every table, made after checking none. V163’s log tells operators to run this command with a table name, so the two cases are now distinct.- The de-duplicating
DELETEannounces itself (#688 post-merge review). It is the only destructive statement in V163, and neither caller reported how many rows it would remove —--dry-runprinted the SQL, which does not answer that.UUIDIntegrity.duplicate_rows/2counts them before any DDL runs, and both callers log the count.
PhoenixKit 1.7.236. Install or update: {:phoenix_kit, "~> 1.7"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.