Repository navigation
Apply Supabase migrations from CI - #454
Closed
ericzakariasson wants to merge 2 commits into
Closed
ericzakariasson wants to merge 2 commits into
ericzakariasson wants to merge 2 commits into
Conversation
Pull requests that touch supabase/ apply every migration to a fresh database with supabase db start, so broken SQL fails before merge. Merges to main apply the migrations they added to production with supabase db push, behind the production environment's approval. The job only applies files the push added: if production is missing anything else, or has a version the repo doesn't, it stops instead of replaying older migrations. Manual runs only report what's pending. The production job stays off until the SUPABASE_PROJECT_ID repository variable is set. Co-authored-by: Eric Zakariasson <ericzakariasson@users.noreply.github.com>
Cover the access token, environment secrets and reviewers, lining up production's hand-applied migration history with the repo, and why migrations have to work with both the old and new code. Co-authored-by: Eric Zakariasson <ericzakariasson@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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
Adds a GitHub Actions workflow so database migrations are no longer applied to production by hand.
supabase/apply every migration to a fresh database (supabase db start), so broken SQL fails before merge.mainapply the migrations that merge added to production (supabase db push), once a maintainer approves theproductionenvironment.Safeguards
SUPABASE_PROJECT_IDrepository variable is set.productionenvironment, which pull requests (including forks) never reach.Before turning it on
The full steps are in README → Database migrations:
productionenvironment secrets. Then require reviewers and limit deployment branches tomain.supabase migration listandsupabase migration repair. Migrations so far were applied by hand (Replace Vercel Workflow with Supabase Queues + duplicate detection #389, Fix duplicate companies: enforce unique names + searchable company picker #400), so the history probably doesn't match.SUPABASE_PROJECT_ID, then run the workflow by hand once to confirm nothing is pending.Vercel deploys merges in parallel with this job, so a migration has to work with both the old and the new code. The README spells that out.
Testing
All local, with Supabase CLI 2.121.0 (the version the workflow pins):
supabase db starton an isolated database applied all 14 migrations in about 17 seconds. A migration with a syntax error failed the run (exit code 1).actionlintandshellcheckare clean, andbunx biome ci .passes.