You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fresh self-host install fails: migration 00048 alters a table no migration creates #709
supabase start / supabase db reset fails on a clean database. Migration 00048_gsc_suggestion_support.sql runs ALTER TABLE public.prompt_suggestions, but no migration creates that table.
Reproduce
git clone https://github.com/ansvisor/ansvisor.git
cd ansvisor
npx supabase start
Applying migration 00048_gsc_suggestion_support.sql...
Stopping containers...
{"_tag":"Error","error":{"code":"LegacyMigrationApplyError",
"message":"ERROR: relation \"public.prompt_suggestions\" does not exist (SQLSTATE 42P01)
At statement: 0 ... ALTER TABLE public.prompt_suggestions ADD COLUMN source_data jsonb"}}
Evidence
$ grep -rn "prompt_suggestions" supabase/migrations/
00048_gsc_suggestion_support.sql:12:ALTER TABLE public.prompt_suggestions ADD COLUMN source_data jsonb;
00048_gsc_suggestion_support.sql:15:ALTER TABLE public.prompt_suggestions DROP CONSTRAINT prompt_suggestions_source_check;
00048_gsc_suggestion_support.sql:16:ALTER TABLE public.prompt_suggestions ADD CONSTRAINT prompt_suggestions_source_check
00030_topic_suggestions.sql:4:-- Mirrors prompt_suggestions: rows are generated only on explicit user
00030_topic_suggestions.sql:37:-- Same policy shape as prompt_suggestions: every org member can read,
Only ALTER statements and comments — never a CREATE TABLE. 00030 explicitly describes itself as mirroring a table that is never defined, which suggests the creating migration was lost rather than never written.
supabase/schema.sql inherits the same gap, since build-schema.sh concatenates the migrations — so both documented install paths are affected (SQL Editor paste and db push).
Existing deployments are unaffected: they already have the table from whatever created it originally.
Workaround
Renaming 00048_gsc_suggestion_support.sql so the CLI skips it lets the install complete; the dashboard runs fine on demo seed data. GSC-fed prompt suggestions are presumably degraded.
Confirmed, and thank you — this is an accurate report with everything needed to act on it.
Two things I checked before answering.
Scope. I compared every table in a live database against the CREATE TABLE statements across all 50 migrations. prompt_suggestions is the only one missing, so there is no second landmine waiting behind this one. (Four other tables looked missing at first because 00017, 00022 and 00023 create them without the public. prefix — false alarm.)
Origin. No migration file was ever deleted, so the creating migration wasn't lost — the table was created directly against the hosted database and never written back into a migration. Same class of gap as #652, which we closed by recovering the table's definition into a numbered migration.
The fix is less obvious than #652, in one specific way
Appending a new migration doesn't work here: 00048 runs first and is where the failure happens, so the CREATE TABLE has to precede it. We'll fix this by adding an idempotent CREATE TABLE IF NOT EXISTS to the top of 00048 itself, with a comment explaining why the file was amended. Editing a shipped migration is normally off-limits, but this is a no-op for anyone who already applied it, and it's the only change that makes the file self-consistent for a fresh install.
The trap for whoever writes it: the recovered definition must describe the table as it was before00048, not as it looks in a live database today. 00048 does
ALTERTABLEpublic.prompt_suggestions ADD COLUMN source_data jsonb; -- no IF NOT EXISTSALTERTABLEpublic.prompt_suggestions DROP CONSTRAINT prompt_suggestions_source_check; -- no IF EXISTS
A live database already has source_data and the three-value source check because 00048 ran. Transcribing that current shape into the CREATE makes a fresh install fail one line later on "column already exists". So the created table needs no source_data column, and its check constraint must be the original two-value one ('llm', 'heuristic') — 00048 then adds the column and extends the constraint exactly as it does today.
For reference, the table has 14 columns, three foreign keys (brand_id → brands cascade, topic_id → topics set null, added_prompt_id → prompts set null), two check constraints, two indexes — one of them a partial unique index on (brand_id, lower(suggested_text)) WHERE status = 'new' — plus RLS with a member-read and an admin/manager/analyst-update policy.
Want to take it?
You found it and you already have the environment set up, so it's yours if you want it — say the word and I'll assign you. Given it ships broken in the v0.2.0 tag, we'd like it landing soon, so if you'd rather stay focused on #708 just say so and we'll pick it up today. Either is genuinely fine.
Activity
gkhngyk commentedon Aug 12, 2026
Confirmed, and thank you — this is an accurate report with everything needed to act on it.
Two things I checked before answering.
Scope. I compared every table in a live database against the
CREATE TABLEstatements across all 50 migrations.prompt_suggestionsis the only one missing, so there is no second landmine waiting behind this one. (Four other tables looked missing at first because00017,00022and00023create them without thepublic.prefix — false alarm.)Origin. No migration file was ever deleted, so the creating migration wasn't lost — the table was created directly against the hosted database and never written back into a migration. Same class of gap as #652, which we closed by recovering the table's definition into a numbered migration.
The fix is less obvious than #652, in one specific way
Appending a new migration doesn't work here:
00048runs first and is where the failure happens, so theCREATE TABLEhas to precede it. We'll fix this by adding an idempotentCREATE TABLE IF NOT EXISTSto the top of00048itself, with a comment explaining why the file was amended. Editing a shipped migration is normally off-limits, but this is a no-op for anyone who already applied it, and it's the only change that makes the file self-consistent for a fresh install.The trap for whoever writes it: the recovered definition must describe the table as it was before
00048, not as it looks in a live database today.00048doesA live database already has
source_dataand the three-value source check because00048ran. Transcribing that current shape into theCREATEmakes a fresh install fail one line later on "column already exists". So the created table needs nosource_datacolumn, and its check constraint must be the original two-value one ('llm','heuristic') —00048then adds the column and extends the constraint exactly as it does today.For reference, the table has 14 columns, three foreign keys (
brand_id→brandscascade,topic_id→topicsset null,added_prompt_id→promptsset null), two check constraints, two indexes — one of them a partial unique index on(brand_id, lower(suggested_text)) WHERE status = 'new'— plus RLS with a member-read and an admin/manager/analyst-update policy.Want to take it?
You found it and you already have the environment set up, so it's yours if you want it — say the word and I'll assign you. Given it ships broken in the v0.2.0 tag, we'd like it landing soon, so if you'd rather stay focused on #708 just say so and we'll pick it up today. Either is genuinely fine.
fix(db): recover the prompt_suggestions table definition (ansvisor#711)
ci: flag pull requests that change a migration so the apply step is n…