Skip to content

chore(migrations): squash 43 incremental migrations into single baseline - #308

Merged
Ardnived merged 3 commits into
mainfrom
chore/squash-migrations-300
Apr 24, 2026
Merged

Ardnived merged 3 commits into
mainfrom
chore/squash-migrations-300

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

Collapses 43 migration files (20260122_065154 → 20260423_083018) into a single schema-equivalent baseline migration (20260424_035639_initial_schema). Prod data is untouched — only payload_migrations was 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

File Change
seeds/squash-migrations.sh (new) Operator-interactive companion to 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 prod payload_migrations in one wrangler --file write. Supports --dry-run.
DEPLOYMENT.md New "Squashing Migrations (Preserve Data)" section under the existing Fresh Start section: coordination checklist, drift-diff interpretation guide, D1 transaction note, rollback procedure, and post-merge dev-reset snippet.
AGENTS.md One-line banner in Database Migrations section pointing at the runbook + reminding operators about pnpm reset --local && pnpm payload migrate after pulling.
src/migrations/ 43 files removed, 20260424_035639_initial_schema.{ts,json} added, index.ts rewritten to single-entry.
tests/{unit,int}/unify-index-blocks-migration*.spec.ts Removed — both imported helpers from a deleted migration file. The transform was a one-shot Lexical block rewrite that's already applied to prod data; no ongoing-codebase consumers.

Developer action required after merge

Every dev must reset their local DB before pulling this branch — otherwise .wrangler retains the pre-squash payload_migrations rows and future migrations behave inconsistently:

pnpm reset --local
pnpm payload migrate

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.

Category Count Safe?
Inline ALTER TABLE ADD COLUMN vs clean multi-line CREATE TABLE majority ✅ Same columns, types, constraints
Inline REFERENCES vs explicit FOREIGN KEY clauses many ✅ Same FKs, different syntax
CREATE TABLE IF NOT EXISTS (prod) vs CREATE TABLE (baseline) several ✅ No runtime difference
Backtick vs double-quote identifier quoting several ✅ Both valid SQLite
Stale index names cards_locales_* vs app_cards_locales_* (from the historical cards → app-cards rename) 2 ✅ Index names internal to SQLite; no app code references them

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

payload_migrations: 43 rows (IDs 1..43, batches 1..33)
meditations: 79    managers: 3    pages: 79    lectures: 6    files: 264

Cutover SQL (ran via wrangler d1 execute sahajcloud --remote --file=...)

DELETE FROM payload_migrations;
INSERT INTO payload_migrations (name, batch)
  VALUES ('20260424_035639_initial_schema', 1);

(No explicit BEGIN/COMMIT — D1 rejects them because Durable Objects own the transaction. Wrangler atomically coalesces --file input instead; failure rolls back cleanly. Documented in the new DEPLOYMENT.md section.)

Post-cutover verification

payload_migrations: 1 row (name='20260424_035639_initial_schema', batch=1)
meditations: 79 ✓ (pre: 79)
managers: 3 ✓ (pre: 3)
pages: 79 ✓ (pre: 79)
lectures: 6 ✓ (pre: 6)
files: 264 ✓ (pre: 264)

GET https://cloud.sydevelopers.com/api/health → 200 {"status":"ok",...}
GET https://cloud.sydevelopers.com/admin/login → 200

Prod is healthy. Admin login page and health endpoint both reachable.

Coordination checklist (pre-cutover)

  • --dry-run output reviewed; diff categorized above.
  • Pre-cutover canary counts captured.
  • payload_migrations column types verified against prod schema.
  • Team Slack announcement ≥24h prior. (operator action — skipped for this PR because the user elected to execute under direct supervision during the PR's own cutover window. Slack announcement belongs on the next squash, when there's no operator-on-call.)
  • No other open migration PRs at cutover time.
  • Deploys paused for cutover window (window was ~5 minutes; no deploy attempts collided).

Test Results

  • Unit tests: 228 passed (11 files)
  • Integration tests: 343 passed (25 files)
  • Total: 571 passed, 0 failures, 0 skipped
  • Build: ✓ Success
  • Lint: ✓ Clean
  • Pre-existing failures fixed: none

Rollback

If prod shows any latent issue, rollback is straightforward — the snapshot at /tmp/squash-300/pre-cutover-payload-migrations.json has every original row; rebuilding them into an INSERT statement + running wrangler d1 execute --remote --file= returns prod to its pre-squash payload_migrations shape. 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

Ardnived and others added 3 commits April 24, 2026 11:50
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
Ardnived merged commit ee9007b into main Apr 24, 2026
@Ardnived
Ardnived deleted the chore/squash-migrations-300 branch April 24, 2026 05:09
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(migrations): squash 42 incremental migrations into a single baseline (preserve prod data)

1 participant