fix(ci): auto-resync preview branch DB on migration/seed push + reset on reuse#1553
Merged
Merged
Conversation
… on reuse Previews served stale schema/seed because `/preview` only ran migrate+seed at comment time and reused a live Supabase branch without resetting it. drizzle migrate skips already-journaled migrations and the seed scripts skip existing rows, so a regenerated migration looked "not applied" and changed seed data never updated (PR #1388). Later pushes never re-ran migrate/seed at all. - Add preview-sync.yaml: on `pull_request` synchronize, path-filtered to drizzle/** + supabase/seed*, re-sync an already-active branch. Exits 0 when no `pr-<N>` branch exists, preserving the zero-cost "no preview by default" model. - Extract the migrate+seed sequence into the shared preview-migrate-seed.sh so the `/preview` and push-resync paths can never drift; PREVIEW_RESET=1 resets before migrate when reusing a live branch. - preview-create.sh resets on the reuse path (manual restart now applies changes). - reset-preview-db.mjs also clears seeded auth.users (seed-users is skip-if-exists and the profile trigger only fires on INSERT, so a public-schema-only reset left broken login state) + a PROD_PROJECT_REF safety guard. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 21, 2026
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.
Problem
Previews could serve stale schema and seed data. Surfaced on #1388 (Machine Settings PR): a pushed migration looked "not applied" and changed seed data wasn't reflected.
Two root causes, both confirmed in the #1388 run logs:
/previewreused a live Supabase branch without resetting it.drizzle-kit migrateis journaled (skips already-applied migrations, so a regenerated migration never re-applies) and the seed scripts are skip-if-exists (⏭️ admin@test.com already exists). So re-running/previewon a still-living branch was a near no-op for changed migrations/seed.preview-control.yamlisissue_comment-only — only a manual/previewcomment ran the DB setup. Every later push triggered Vercel's own build (new code) against the old branch DB.It's structural, not #1388-specific: any PR that re-runs
/previewon a live branch, or pushes a migration without re-commenting, hits it.Fix
preview-sync.yaml(new): onpull_requestsynchronize, path-filtered todrizzle/**+supabase/seed*, re-sync an already-active preview branch. Exits 0 when nopr-<N>branch exists → preserves the zero-cost "no preview by default" model. Shares preview-control's per-PR concurrency group so a resync and a manual/previewnever mutate the branch DB concurrently.preview-migrate-seed.sh(new): the migrate+seed sequence extracted into one shared script used by both the/previewpath and the push-resync path, so they can't drift again.PREVIEW_RESET=1resets before migrate.preview-create.sh: setsPREVIEW_RESET=1on the reuse path, so a manual/previewrestart on a live branch now applies changes too.reset-preview-db.mjs: now also clears seededauth.users(seed-users is skip-if-exists and the profile-creation trigger only fires on INSERT, so a public-schema-only reset left broken login state), plus aPROD_PROJECT_REFguard that refuses to run against the production project.Trigger model
First
/previewcreates the branch + sets TTL. Subsequent migration/seed pushes auto-resync it (reset → migrate → seed). Code-only pushes leave it alone (and preserve manual test data). Reaper still tears it down on TTL/close.Verification
pnpm run checkgreen: 1255 unit tests, 70 pytest hook tests, all linters (yamllint/actionlint/shellcheck/zizmor/ratchet/ruff)./preview+ migration push on a live PR with the Supabase/Vercel secrets in CI. Recommend smoke-testing on this PR (or feat(machines): Machine Settings tab — owner-defined settings sets (PP-43q3) #1388) after merge.Follow-up for #1388
#1388 added
node supabase/seed-machine-settings.mjsinline inpreview-create.sh. After this merges, that line should move intopreview-migrate-seed.sh's PR-specific seed section (there's a commented example showing the file-existence-guarded pattern). The merge will conflict on that block — resolve by relocating the line.🤖 Generated with Claude Code