# `mix phoenix_kit.repair_uuid`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v2.13.7/lib/mix/tasks/phoenix_kit.repair_uuid.ex#L1)

Repairs `phoenix_kit_*` tables whose `uuid` column is the wrong type, nullable,
or not the primary key.

V163 performs this repair automatically during `mix ecto.migrate`, but skips
any table large enough that the rewrite's `ACCESS EXCLUSIVE` lock would be an
outage rather than a pause. This task is the deliberate, operator-chosen path
for those — run it in a maintenance window.

    mix phoenix_kit.repair_uuid                       # every table that needs it
    mix phoenix_kit.repair_uuid phoenix_kit_email_events
    mix phoenix_kit.repair_uuid --dry-run             # show the SQL, change nothing
    mix phoenix_kit.repair_uuid --prefix tenant_a

## What it costs

`ALTER COLUMN … TYPE uuid` rewrites the table and holds an `ACCESS EXCLUSIVE`
lock for the duration — no reads, no writes, and behind a connection pooler
that means the pool fills rather than merely waiting. There is no concurrent
form of a type change; the size of the table is the size of the outage.

The primary key is cheaper here than in the migration: outside a transaction
the unique index is built `CONCURRENTLY` and then attached, so the exclusive
lock covers only the attach. That is why this task is not simply "V163 without
the limit".

## Safety

Nothing is destructive except de-duplication, which deletes rows that share a
uuid — on a table that has run without a primary key those are the same
logical row stored twice, and a duplicate makes `ADD PRIMARY KEY` impossible.
`--dry-run` prints every statement, including the delete, without executing.

Values that cannot be cast to `uuid` abort that table with the query to
inspect them; other tables still proceed.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
