deckhearth/migrations
varutasu 40402eb287
feat(migrations): reconcile user_cards UNIQUE constraint per Option A (B6) (#149)
* feat(migrations): reconcile user_cards UNIQUE constraint per Option A (B6)

Convoy: reconcile-historical-add-scripts Brief 6.

Operator decision on Finding 1 (ratified 2026-06-14): Option A — keep
the canonical 3-col UNIQUE(user_id, card_id, is_foil) declared by
migrations/1779853647564_initial-schema.js. Drop / treat-as-no-op the
stricter 2-col UNIQUE(user_id, card_id) that the historical
scripts/fix-user-cards-constraints.js job would have installed. Foil
and non-foil copies of the same card are semantically separate rows.

Defensive idempotent shape; safe against all three prod states (fresh
Neon branch, long-lived env that never ran the script, long-lived env
that did run it). down() is a hard-stub throw — re-installing the
2-col constraint would forbid the foil distinction runtime code
relies on.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(migrate): pre-check pg_constraint instead of catching duplicate_object

ADD CONSTRAINT UNIQUE creates a supporting index under the hood; when
the index name already exists from initial-schema's inline UNIQUE,
Postgres raises SQLSTATE 42P07 (duplicate_table), not 42710
(duplicate_object) — so the EXCEPTION block didn't catch it and CI's
Migrations apply gate failed with `relation
"user_cards_user_id_card_id_is_foil_key" already exists`.

Swap to a pg_constraint pre-check: bulletproof against both SQLSTATEs
without overreaching to WHEN OTHERS.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 08:18:22 -05:00
..
1779853647564_initial-schema.js feat(infra): adopt node-pg-migrate + backfill initial schema migration (#32) 2026-05-26 23:01:58 -05:00
1779853647565_add-pg-trgm-card-name-index.js feat(scanner): AI Gateway vision + Layer-1 Tesseract/pg_trgm OCR (#38) 2026-05-27 12:59:59 -05:00
1779853647566_add-scan-tables.js ci: run migrations against Postgres service container in CI (#64) 2026-06-02 11:01:18 -05:00
1779908094455_add-user-cards-scan-image-url.js feat(scanner): persist scan captures to Blob (Brief 3) (#44) 2026-05-27 13:57:26 -05:00
1780378340194_system-collection-description.js ci: run migrations against Postgres service container in CI (#64) 2026-06-02 11:01:18 -05:00
1781000000001_reconcile-cards-columns.js feat(migrations): reconcile cards columns missed by initial-schema backfill (B1) (#148) 2026-06-14 08:11:08 -05:00
1781000000002_reconcile-collections-columns.js feat(migrations): reconcile collections columns missed by initial-schema backfill (B2) (#150) 2026-06-14 08:18:05 -05:00
1781000000004_reconcile-favorites-system.js feat(migrations): reconcile favorites system missed by initial-schema backfill (B4) (#152) 2026-06-14 08:11:26 -05:00
1781000000005_reconcile-user-profile.js feat(migrations): reconcile user profile missed by initial-schema backfill (B5) (#153) 2026-06-14 08:18:20 -05:00
1781000000006_reconcile-user-cards-unique.js feat(migrations): reconcile user_cards UNIQUE constraint per Option A (B6) (#149) 2026-06-14 08:18:22 -05:00
1781440700404_add-scryfall-bulk-columns.js feat(catalog): Scryfall bulk data import + Tagger community tags 2026-06-14 07:51:39 -05:00
1781440721350_add-tagger-tables.js feat(catalog): Scryfall bulk data import + Tagger community tags 2026-06-14 07:51:39 -05:00