Skip to content

Unguarded ADD CONSTRAINT in migration 060_marketplace_kind.sql breaks bootstrap re-run #356

Description

@NesiciCoding

Summary

supabase/migrations/060_marketplace_kind.sql adds a check constraint without an existence guard:

ALTER TABLE public.marketplace_listings
  ADD CONSTRAINT marketplace_listings_kind_check CHECK (kind IN ('rubric', 'test', 'deck')) NOT VALID;

Every other statement in this migration (and the surrounding convention across the codebase) is IF NOT EXISTS-guarded, but ADD CONSTRAINT has no such form. Since supabase/bootstrap.sql is a full mechanical concatenation of every migration (see scripts/generate-bootstrap.sh), a second psql -f supabase/bootstrap.sql run against an already-bootstrapped database raises 42710 (constraint already exists) and aborts the rest of the script.

Found while regenerating bootstrap.sql for PR #346 — the migration itself is already merged and unrelated to that PR's actual changes, so it wasn't fixed there per this repo's rule of never modifying an already-applied migration.

Suggested fix

A new forward-only migration:

ALTER TABLE public.marketplace_listings
  DROP CONSTRAINT IF EXISTS marketplace_listings_kind_check;
ALTER TABLE public.marketplace_listings
  ADD CONSTRAINT marketplace_listings_kind_check CHECK (kind IN ('rubric', 'test', 'deck')) NOT VALID;
ALTER TABLE public.marketplace_listings
  VALIDATE CONSTRAINT marketplace_listings_kind_check;

Then regenerate bootstrap.sql via ./scripts/generate-bootstrap.sh.

🤖 Found via Claude Code / CodeRabbit review on PR #346.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions