Repository navigation
chore(migrations): squash 137 migrations into one baseline named for the newest - #1188
Conversation
…the newest The baseline carries the name of the newest migration on main (20261116_181127_merge_main_snapshot_10), which production already holds in payload_migrations, so production sees nothing pending. A baseline under a new name would look pending there, CREATE tables that exist and crash-loop the boot. A fresh database runs the baseline whole. Its down refuses on a database that applied the old chain, since rolling back would drop that schema. Two integration specs that imported deleted one-shot migrations go with them. Procedure, checks and reset notes: src/migrations/AGENTS.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1188 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is exactly the size of its problem: 272 migration files deleted, one generated baseline, two specs that imported removed migrations, and the doc pointers the squash invalidated. Nothing is smuggled in, no abstraction is added for one caller, no contract surface is touched. The naming trick is the right one — Payload keys payload_migrations on names, so keeping the newest applied name is what the platform requires, and the PR measures it rather than reasoning. One new piece carries the risk, the down guard, and its heuristic is wrong for the chain this PR creates.
Findings
should-fix— the guard's row count refuses on a healthy post-squash database undermigrate:refresh; test names, not a count (baseline.ts:2929).consider— the new AGENTS.md "Checks" block repeats this PR's one-time proof in an always-loaded guide (AGENTS.md:392).
What was checked
- The snapshot claim holds:
jq -S 'del(.id,.prevId)'of the baseline.jsonagainstorigin/main's is identical, 786,960 bytes each. Both carryprevIdall-zeros, so the nextmigrate:creatediffs against the baseline. - Payload 3.93 read at source, not assumed:
migrateDown.js,migrateReset.js,migrateRefresh.js,getMigrations.js. Down and reset match the body's table; refresh does not. - Every path the body names exists on the branch, both deleted int specs are gone,
index.tslists one entry, andmain's copy already had an emptydown. - Contracts: the
contractSyncproducer sources (src/payload-types.ts, EventsresponseTypes.ts,atlas-url-contract.json) are untouched, so there is no consumer side to follow. - Ladder: the guard is the only new code and Payload offers no equivalent. No new file, type or dependency.
- No
fixture.surfacePathspath is touched and the body cites no preview links.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The `down` guard refused whenever `payload_migrations` held more than one non-dev row. `migrate:refresh` reverses `getMigrations`' `-batch,-name` order, so it runs the oldest migration's `down` first and deletes no row before it — on a healthy post-squash database the baseline's `down` therefore saw every later migration's row and refused. `migrate:reset` escaped only because it walks the files newest-first, deleting each row as it goes, which is why the PR's checks passed with one migration in the chain. It now counts rows whose name sorts before the baseline's, which is exactly the pre-squash chain and nothing else. Proven on a throwaway database in three states: old chain refuses (n=2), baseline alone allows (n=0), baseline plus a later migration allows (n=0) where the row count refused (2 > 1). The dev row stays excluded by name as well as by batch. The name is now a SQL literal in the guard, so the naming rule's "never rename it" has a second reason recorded beside it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjX8ePxq2jyAdvxKtZD
The "Checks" block restated this squash's one-time verification — the commands, the normalisation and the expected residual — in a guide that loads on every read of a migration file. What a future squash needs is the set of conditions, not a transcript of how this one met them. Each check keeps its rule and loses the mechanics a reader can re-derive: setting DATABASE_URL, what a fresh database is, which dump is S_old. The measured results stay in the PR body, where they date themselves. The guard case is named for what it proves rather than appended as an afterthought. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjX8ePxq2jyAdvxKtZD
|
Both adversarial-review threads addressed. Pushed Adopted — the Adopted — the squash checks repeat this PR's proof ( Branch was already level with 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
sydevs-bot
left a comment
There was a problem hiding this comment.
Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run, so it merges through the queue. 🤖 Written by the sydevs autonomous loop — see what this is
Merge timing: read first
Merge only when production has applied
20261116_181127_merge_main_snapshot_10(checked read-only on 2026-11-17: it is the newest row, batch 76), and no other migration-adding PR merges between this PR's base (c70081c0) and its merge. Ifmaingains a migration first, this PR must be redone: the baseline's name must be the newest one onmain.The failure this prevents
Production's
payload_migrationsholds migration names. Boot-timeprodMigrationsruns every file whose name has no row. A baseline under a new name would look pending in production, try toCREATE TABLEtables that exist, and crash-loop the boot on every restart. CI cannot see this (tests and dev usepush, previews boot an empty database).So the single baseline is named exactly like the newest migration on
main. Production sees nothing pending; a fresh database runs the baseline whole.What changes
.ts+.json) replaced bysrc/migrations/20261116_181127_merge_main_snapshot_10.{ts,json}and a one-entryindex.ts. The baseline was generated bymigrate:createon an empty chain, then renamed. Its.jsonequals the old newest snapshot in every key exceptid.payload_migrationsrows), so the baseline is DDL only.downrefuses on a database that applied the old chain (see "Payload behaviour").tests/int/atlas-drop-time-in-place.int.spec.tsandatlas-clock-copy.int.spec.ts: each imported a one-shot migration'sup, which no longer exists.migration-down-cascade.spec.tsnow needs only one file.src/migrations/AGENTS.md: new "Squashing the chain" section (when, naming rule, procedure, checks, merge timing, environments, Payload behaviour).DEPLOYMENT.mdpoints to it. Old worked examples are annotated as readable atc70081c0.Facts settled
default_transaction_read_only=on):SELECT name, batch FROM payload_migrations ORDER BY id DESC LIMIT 6returns20261116_181127_merge_main_snapshot_10(id 137, batch 76) first, then20261116_171937_storage_prefix. 137 rows; the set of names is identical to the 137.tsfiles onmain. No write, no server boot against production.src/fixture/AGENTS.md): a new preview boots an empty Postgres, runsprodMigrations(the baseline), then loads the fixture. Dev and test lanes (including CI'spayload_test) usepush, never migrations. A local dev DB built bypushholds only thedevrow (batch -1). At risk: a database holding some old names but not the baseline's, i.e. a long-lived preview of a branch cut before this merges, or a preview of a PR that adds its own migration after rebasing onto this. Those see the baseline as pending and crash. Handling: reset the preview withrailway environment delete SahajCloud-pr-<n> --yes(the next push recreates it); a stale local migrated DB is dropped and recreated (pnpm payload migrate:freshworks). Documented in the AGENTS.md table.migrate/migrate:status/migrate:create: ignore rows without a file. Nothing errors.migrate:down: takes the latest batch and runsdownnewest name first. Unguarded, it would run the baselinedownand drop the whole schema (reproduced: 141 tables to 0), then thrownot found locally. The baseline's guard now refuses (reproduced: schema intact, 141 tables).migrate:refresh: exits 1 at the oldest orphan (Migration 20260606_050852_initial_schema not found locally), nothing changed.migrate:reset: reaches the baselinedown, refused by the guard.migrate:fresh: works (drops and runs the baseline; 1 row).cb5ac3b).migrate:refreshreversesgetMigrations'-batch,-nameorder, so it runs the oldest migration'sdownfirst and deletes no row beforehand. A row count therefore refused a healthy post-squash database as soon as a second migration existed;migrate:resetescaped only because it walks the files newest-first, deleting each row as it goes, which is why the checks above passed with one file in the chain. The guard now counts rows whosenamesorts before the baseline's — exactly the pre-squash chain. Verified on a throwaway database: old chain refuses (2 stale names), baseline alone allows (0), baseline plus a later migration allows (0) where the row count refused.gh pr list --state openshows one open PR (chore(sentry): a handler's own 5xx reaches no one #1183), which touches no file undersrc/migrations/. Nothing to rebase for chaining. Any branch cut earlier that has its own migration will need its.jsonregenerated against this baseline and its preview reset.Proof (local Postgres 18, throwaway databases
sq_old,sq_new,sq_hazard,sq_boot, all dropped)pnpm payload migrateon a fresh DB with the old chain (origin/main) vs with the baseline;pg_dump --schema-only --no-owner --no-privilegesof each (19,077 lines). After sorting statements and the columns inside eachCREATE TABLE(anADD COLUMNappends where a baseline lists the final order), the only residual is 3 objects named for tables since renamed: sequencesform_submissions_id_seq/meditation_transcripts_id_seqand primary keysform_submissions_pkey,form_submissions_submission_data_pkey,meditation_transcripts_pkeyin the old DB, nowuser_submissions_*/transcripts_*. Cosmetic: no query, snapshot or migration names them, and production keeps its old names.pnpm payload migrate:status: baselineYes.pnpm payload migrate: noMigrating:line, still 137 rows. Real boot,NODE_ENV=production tsxbootingpayload.config(theprodMigrationspath):BOOTED ok; payload_migrations rows = 137, no migration ran.pnpm db:migrations:create probe --skip-empty < /dev/nullwrites no files.NODE_ENV=productionboot on an empty DB logsMigrating: 20261116_181127_merge_main_snapshot_10, 1 row; withNEXT_RUNTIME=nodejsandRAILWAY_ENVIRONMENT_NAME=SahajCloud-pr-9999the fixture loggedloaded in 4026 ms: 211 created, 0 updated, 0 deleted, 0 unchanged, 0 failed.migrate:downthenmigrateround-trips on a baseline DB..claude/skills/pr-prep/check.sh(lint, format, typecheck, unit lane): 276 files / 3742 tests passed. No integration spec remains for the area (the two deleted ones imported removed migrations).migration-validator: snapshot present,up/downexported. Itstscstep reportsTS5112for every migration (it passes a file with atsconfig.jsonpresent, and TypeScript 6 refuses); a directpnpm tsc --noEmit --ignoreConfig --target es2022 --module esnext --moduleResolution bundler --skipLibCheck <file>compiles cleanly, as doespnpm tsc --noEmit. TheDROP TABLEwarnings are the baseline'sdown.Owner checks before merge
20261116_181127_merge_main_snapshot_10).c70081c0.🤖 Generated with Claude Code