Skip to content

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

Closed

Description

@mikam44700

Summary

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.

Environment

  • Ansvisor main @ f60ce8d, v0.2.0
  • Supabase CLI 2.113.0, Docker 29.7.2, Node 24.13.1, macOS 15

Surfaced while preparing #708.

Activity

  1. gkhngyk commented on Aug 12, 2026

    @gkhngyk
    Contributor

    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 before 00048, not as it looks in a live database today. 00048 does

    ALTER TABLE public.prompt_suggestions ADD COLUMN source_data jsonb;                     -- no IF NOT EXISTS
    ALTER TABLE public.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.

  2. added
    bug
    on Aug 12, 2026
  3. added a commit that references this issue on Aug 13, 2026
    59bdc58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions