Repository navigation
fix(db): recover the prompt_suggestions table definition - #711
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prompt_suggestionswas created directly against the hosted database and never written back into a migration, so00048'sALTER TABLEstatements had nothing to alter on a clean one:schema.sqlinherits 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
00048itself, 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.shsays as much — but every clause here is idempotent, and any database that already applied00048will 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_datacolumn, and the two-value source check. Transcribing a live database's current shape is the obvious move and is wrong: the live table hassource_dataand the three-value check precisely because00048already 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 TABLEstatements 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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Verified end to end against a real local stack, both directions.
On
main,supabase db resetstill fails exactly as reported:On this branch it completes:
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
ALTERthat 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 resetChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)