Skip to content

fix(db): recover the prompt_suggestions table definition - #711

Merged
gkhngyk merged 1 commit into
mainfrom
fix/709-prompt-suggestions-migration
Aug 12, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/709-prompt-suggestions-migration

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

prompt_suggestions was created directly against the hosted database and never written back into a migration, so 00048's ALTER TABLE statements had nothing to alter on a clean one:

ERROR: relation "public.prompt_suggestions" does not exist (SQLSTATE 42P01)

schema.sql inherits the same gap, being a concatenation of the migrations, so both documented fresh-install paths have been broken since 00048 shipped — including in the v0.2.0 tag. Existing deployments were never affected: they already had the table.

This recovers the definition from the live database. Two decisions worth reviewing:

It goes into 00048 itself, not a new numbered migration. The very next statement alters this table, so anything appended at the end would never be reached. Editing a shipped migration is normally off-limits — build-schema.sh says as much — but every clause here is idempotent, and any database that already applied 00048 will not run it again, so this is a no-op for every existing install and the only change that makes the file self-consistent for a new one.

It is deliberately the table as it was before the ALTERs that follow — no source_data column, and the two-value source check. Transcribing a live database's current shape is the obvious move and is wrong: the live table has source_data and the three-value check precisely because 00048 already ran, so a fresh install would fail one line later on "column source_data already exists".

I also compared every table in a live database against the CREATE TABLE statements in all 50 migrations: this is the only one missing, so there is no second failure waiting behind it.

Related issue

Closes #709

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Verified end to end against a real local stack, both directions.

On main, supabase db reset still fails exactly as reported:

Applying migration 00048_gsc_suggestion_support.sql...
ERROR: relation "public.prompt_suggestions" does not exist (SQLSTATE 42P01)
At statement: 0 ... ALTER TABLE public.prompt_suggestions ADD COLUMN source_data jsonb

On this branch it completes:

Applying migration 00048_gsc_suggestion_support.sql...
Applying migration 00049_cloro_pending_tasks.sql...
Applying migration 00050_content_opportunity_aggregates.sql...
Applying migration 00051_brand_ga_property.sql...
Finished supabase db reset.

All 50 migrations apply on a clean database, and the resulting table matches production exactly: 15 columns, 6 constraints, 3 indexes, 2 policies, RLS enabled — including the three-value source check, which confirms the recovered two-value constraint is correctly replaced by the ALTER that follows it.

Independently of the local stack, the same migration was replayed against a clean table in an isolated schema on a production-shaped database and diffed column by column: every column matches on type, nullability and default, and all six constraints match.

To reproduce:

git checkout fix/709-prompt-suggestions-migration
npx supabase start          # or: npx supabase db reset

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

prompt_suggestions was created directly against the hosted database and
never written back into a migration, so 00048's ALTER statements had
nothing to alter on a clean one. `supabase start` / `db reset` failed with
42P01, and schema.sql inherited the gap because it is a concatenation of
the migrations — every documented fresh-install path has been broken since
00048 shipped, including in the v0.2.0 tag. Existing deployments were
unaffected: they already had the table.

The definition goes into 00048 itself rather than a new numbered file. The
very next statement alters this table, so a migration appended at the end
would never be reached. Editing a shipped migration is normally off-limits;
this one is safe because every clause is idempotent and any database that
already ran 00048 will not run it again.

It is deliberately the table as it was BEFORE the ALTERs that follow: no
source_data column, and the two-value source check. Transcribing a live
database's current shape instead — which is the obvious thing to do — would
leave a fresh install failing one line later on "column already exists".

Verified by replaying the whole of 00048 against a clean table in an
isolated schema, then diffing the result against the live table: all 15
columns match on type, nullability and default, and all six constraints
match.

Closes #709
@gkhngyk gkhngyk self-assigned this Aug 12, 2026
@gkhngyk
gkhngyk merged commit 59bdc58 into main Aug 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fresh self-host install fails: migration 00048 alters a table no migration creates

1 participant