Repository navigation
chore(migrations): squash 43 incremental migrations into single baseline - #308
Merged
Merged
Conversation
Add seeds/squash-migrations.sh as a data-preserving counterpart to the existing seeds/reset-migrations.sh. Dumps prod schema, generates a fresh baseline locally, verifies schema equivalence via diff against a throwaway local D1, then rewrites prod's payload_migrations table in a single transaction — no DDL, no row data touched. DEPLOYMENT.md gains a "Squashing Migrations (Preserve Data)" section under the existing Fresh Start section: coordination checklist, drift-diff interpretation guide, rollback procedure, and post-merge dev-reset snippet. AGENTS.md Database Migrations section gets a one-line banner pointing at the runbook and calling out the required `pnpm reset --local && pnpm payload migrate` after pulling any squash commit. The actual squash (deleting 42 incremental migrations and replacing them with a single baseline) lands in a follow-up commit once the dry-run diff has been reviewed. Refs #300 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Collapses 43 migration files (20260122_065154 through 20260423_083018)
into a single baseline '20260424_035639_initial_schema' generated via
pnpm db:migrations:create. Prod's payload_migrations table was rewritten
in a separate cutover step (wrangler d1 execute against the sahajcloud
database) — no DDL was run against prod, row data untouched.
Drift diff (199 lines; artifacts saved to /tmp/squash-300/) was reviewed
before cutover. All differences are benign Drizzle formatting: inline
ALTER TABLE ADD COLUMN artifacts vs clean multi-line CREATE TABLE, inline
REFERENCES vs explicit FOREIGN KEY lines, backtick vs double-quote
identifier quoting, and two stale-named unique indexes from the historical
cards -> app-cards rename (index names are internal to SQLite; no
application code referenced them). Schema on prod is unchanged.
Post-cutover verification (all pre-cutover counts match):
payload_migrations: 43 -> 1 (name: 20260424_035639_initial_schema)
meditations: 79 = 79
managers: 3 = 3
pages: 79 = 79
lectures: 6 = 6
files: 264 = 264
admin login page: 200
/api/health: 200 {status: ok}
Also folds in two script fixes discovered during the dry-run:
- Use sahajcloud-dev binding for local wrangler d1 export (env.dev
declares the dev D1 as sahajcloud-dev, not sahajcloud).
- Drop BEGIN/COMMIT from the payload_migrations rewrite SQL — D1
rejects explicit transactions (Durable Objects own them); wrangler
atomically coalesces --file input instead.
Developers pulling this commit must run `pnpm reset --local && pnpm
payload migrate` — their .wrangler DB still carries the pre-squash
payload_migrations rows and future migrations will behave inconsistently
without the reset. Documented in AGENTS.md banner + DEPLOYMENT.md.
Closes #300
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
tests/unit/unify-index-blocks-migration.spec.ts and tests/int/unify-index-blocks-migration-runner.int.spec.ts both imported helpers from src/migrations/20260409_180000_unify_index_blocks, which was deleted in the prior squash commit. The unify-index-blocks transform was a one-shot Lexical-block migration (meditations-index/pages-index → content-index) that already ran against prod. Its helper functions have no callers outside the deleted migration and aren't part of the ongoing codebase, so there's nothing left to test. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Ardnived
added a commit
that referenced
this pull request
Nov 2, 2026
…1061) Backfills (owner confirmed both are done): delete scripts/backfill-region-breadcrumb-urls.ts (#640) and scripts/backfill-schedule-last-date.ts (#604), the src/lib routines only they used, their int specs, and the doc rows pointing at them. New writes fill breadcrumbs[].url and schedule.lastDate on their own, and region-canonical-url / events specs cover that live behaviour. seeds/tests harness: test-storyblok.sh and test-meditations.sh run importers that have had no CLI entry point since #156, so each "test" exited 0 having done nothing; check-db-stats.ts queried the music collections renamed in #180. Delete them with setup-test-db.ts and test-payload.config.ts (used only by them), rewrite the folder guide around the spec that stays, and drop the third buildConfig site from the systemEntities / access.md / postgresTestPool comments. Smaller: meditation-duration's "backfill migration logic" block re-implemented a migration deleted in #308 and called none of our code; seed-pagination's PaginationOptions block only read back an object literal; lemonfox-client's comment named transcribe.ts's old path. Co-authored-by: Claude Opus 5.5 <[email protected]>
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
Collapses 43 migration files (
20260122_065154→20260423_083018) into a single schema-equivalent baseline migration (20260424_035639_initial_schema). Prod data is untouched — onlypayload_migrationswas rewritten.Cutover has already been executed against prod under user supervision (the selected scope for this PR was "tooling + live prod squash"). Post-cutover verification confirms schema unchanged and all canary row counts match.
Closes #300
What changed
seeds/squash-migrations.sh(new)seeds/reset-migrations.sh. Dumps prod schema, generates fresh baseline locally, verifies equivalence via diff against a throwaway local D1 (backs up/restores.wrangler), rewrites prodpayload_migrationsin one wrangler--filewrite. Supports--dry-run.DEPLOYMENT.mdAGENTS.mdpnpm reset --local && pnpm payload migrateafter pulling.src/migrations/20260424_035639_initial_schema.{ts,json}added,index.tsrewritten to single-entry.tests/{unit,int}/unify-index-blocks-migration*.spec.tsDeveloper action required after merge
Every dev must reset their local DB before pulling this branch — otherwise
.wranglerretains the pre-squashpayload_migrationsrows and future migrations behave inconsistently:Announced via the AGENTS.md banner so future agents follow the same rule.
Drift diff — benign, categorized
The dry-run produced a 199-line diff; all categorizable as expected Drizzle formatting / pre-existing prod artifacts. No functional schema drift.
ALTER TABLE ADD COLUMNvs clean multi-line CREATE TABLEREFERENCESvs explicitFOREIGN KEYclausesCREATE TABLE IF NOT EXISTS(prod) vsCREATE TABLE(baseline)cards_locales_*vsapp_cards_locales_*(from the historicalcards→app-cardsrename)Squash intentionally does not touch prod schema — prod keeps its live shape. Fresh environments built from the new baseline get clean formatting + corrected index names. Going forward, nothing in application code depends on either version.
Artifacts are saved locally at
/tmp/squash-300/(prod-schema.sql, baseline-schema.sql, schema-drift.diff, pre-cutover-payload-migrations.json) in case deeper review is requested.Live cutover — already done
Executed 2026-04-24 under user supervision after dry-run review.
Pre-cutover snapshot
Cutover SQL (ran via
wrangler d1 execute sahajcloud --remote --file=...)(No explicit
BEGIN/COMMIT— D1 rejects them because Durable Objects own the transaction. Wrangler atomically coalesces--fileinput instead; failure rolls back cleanly. Documented in the new DEPLOYMENT.md section.)Post-cutover verification
Prod is healthy. Admin login page and health endpoint both reachable.
Coordination checklist (pre-cutover)
--dry-runoutput reviewed; diff categorized above.payload_migrationscolumn types verified against prod schema.Test Results
Rollback
If prod shows any latent issue, rollback is straightforward — the snapshot at
/tmp/squash-300/pre-cutover-payload-migrations.jsonhas every original row; rebuilding them into an INSERT statement + runningwrangler d1 execute --remote --file=returns prod to its pre-squashpayload_migrationsshape. The prod schema was never touched, so no structural rollback is needed. See the "Rollback" subsection of the new DEPLOYMENT.md section for details.🤖 Generated with Claude Code