Skip to content

chore(migrations): squash 137 migrations into one baseline named for the newest - #1188

Merged
sydevs-bot merged 3 commits into
mainfrom
claude/squash-migrations
Nov 17, 2026
Merged

sydevs-bot merged 3 commits into
mainfrom
claude/squash-migrations

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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. If main gains a migration first, this PR must be redone: the baseline's name must be the newest one on main.

The failure this prevents

Production's payload_migrations holds migration names. Boot-time prodMigrations runs every file whose name has no row. A baseline under a new name would look pending in production, try to CREATE TABLE tables that exist, and crash-loop the boot on every restart. CI cannot see this (tests and dev use push, 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

  • 137 migrations (.ts + .json) replaced by src/migrations/20261116_181127_merge_main_snapshot_10.{ts,json} and a one-entry index.ts. The baseline was generated by migrate:create on an empty chain, then renamed. Its .json equals the old newest snapshot in every key except id.
  • The old chain inserted no reference data into a fresh database (data dump of a freshly migrated DB: only payload_migrations rows), so the baseline is DDL only.
  • The baseline's down refuses on a database that applied the old chain (see "Payload behaviour").
  • Deleted tests/int/atlas-drop-time-in-place.int.spec.ts and atlas-clock-copy.int.spec.ts: each imported a one-shot migration's up, which no longer exists. migration-down-cascade.spec.ts now needs only one file.
  • src/migrations/AGENTS.md: new "Squashing the chain" section (when, naming rule, procedure, checks, merge timing, environments, Payload behaviour). DEPLOYMENT.md points to it. Old worked examples are annotated as readable at c70081c0.

Facts settled

  1. Production read (read-only session, default_transaction_read_only=on): SELECT name, batch FROM payload_migrations ORDER BY id DESC LIMIT 6 returns 20261116_181127_merge_main_snapshot_10 (id 137, batch 76) first, then 20261116_171937_storage_prefix. 137 rows; the set of names is identical to the 137 .ts files on main. No write, no server boot against production.
  2. Other databases. A Railway preview "forks configuration, never volume data" (src/fixture/AGENTS.md): a new preview boots an empty Postgres, runs prodMigrations (the baseline), then loads the fixture. Dev and test lanes (including CI's payload_test) use push, never migrations. A local dev DB built by push holds only the dev row (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 with railway environment delete SahajCloud-pr-<n> --yes (the next push recreates it); a stale local migrated DB is dropped and recreated (pnpm payload migrate:fresh works). Documented in the AGENTS.md table.
  3. Payload 3.93 with orphan rows (source read, then run on an old-chain DB):
    • boot / migrate / migrate:status / migrate:create: ignore rows without a file. Nothing errors.
    • migrate:down: takes the latest batch and runs down newest name first. Unguarded, it would run the baseline down and drop the whole schema (reproduced: 141 tables to 0), then throw not 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 baseline down, refused by the guard.
    • migrate:fresh: works (drops and runs the baseline; 1 row).
    • The guard tests names, not a row count (cb5ac3b). migrate:refresh reverses getMigrations' -batch,-name order, so it runs the oldest migration's down first and deletes no row beforehand. A row count therefore refused a healthy post-squash database as soon as a second migration existed; migrate:reset escaped 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 whose name sorts 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.
  4. Open PRs adding migrations: none. gh pr list --state open shows one open PR (chore(sentry): a handler's own 5xx reaches no one #1183), which touches no file under src/migrations/. Nothing to rebase for chaining. Any branch cut earlier that has its own migration will need its .json regenerated against this baseline and its preview reset.

Proof (local Postgres 18, throwaway databases sq_old, sq_new, sq_hazard, sq_boot, all dropped)

  • A. Same schema. pnpm payload migrate on a fresh DB with the old chain (origin/main) vs with the baseline; pg_dump --schema-only --no-owner --no-privileges of each (19,077 lines). After sorting statements and the columns inside each CREATE TABLE (an ADD COLUMN appends where a baseline lists the final order), the only residual is 3 objects named for tables since renamed: sequences form_submissions_id_seq / meditation_transcripts_id_seq and primary keys form_submissions_pkey, form_submissions_submission_data_pkey, meditation_transcripts_pkey in the old DB, now user_submissions_* / transcripts_*. Cosmetic: no query, snapshot or migration names them, and production keeps its old names.
  • B. Old-chain DB, new code. pnpm payload migrate:status: baseline Yes. pnpm payload migrate: no Migrating: line, still 137 rows. Real boot, NODE_ENV=production tsx booting payload.config (the prodMigrations path): BOOTED ok; payload_migrations rows = 137, no migration ran.
  • C. No drift. pnpm db:migrations:create probe --skip-empty < /dev/null writes no files.
  • D. Fresh boot + fixture. NODE_ENV=production boot on an empty DB logs Migrating: 20261116_181127_merge_main_snapshot_10, 1 row; with NEXT_RUNTIME=nodejs and RAILWAY_ENVIRONMENT_NAME=SahajCloud-pr-9999 the fixture logged loaded in 4026 ms: 211 created, 0 updated, 0 deleted, 0 unchanged, 0 failed. migrate:down then migrate round-trips on a baseline DB.
  • E. Gate. .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/down exported. Its tsc step reports TS5112 for every migration (it passes a file with a tsconfig.json present, and TypeScript 6 refuses); a direct pnpm tsc --noEmit --ignoreConfig --target es2022 --module esnext --moduleResolution bundler --skipLibCheck <file> compiles cleanly, as does pnpm tsc --noEmit. The DROP TABLE warnings are the baseline's down.

Owner checks before merge

  • Re-run the production read just before merging (newest name must still be 20261116_181127_merge_main_snapshot_10).
  • Confirm no other migration PR merged since c70081c0.
  • After merge, reset any open preview that deployed before it.

🤖 Generated with Claude Code

…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]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1188 November 17, 2026 19:11 Destroyed
@railway-app

railway-app Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-1188 environment in sahajcloud

Service Status Web Updated
SahajCloud 😴 Sleeping (View Logs) Web Nov 17, 2026 at 8:13 pm UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 17, 2026
@sydevs-bot

sydevs-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 19:37Z address-review · attempt 1 · session · done
  • 19:37Z address-review · attempt 1 · session
  • 19:27Z review-pr · attempt 1 · session · done
  • 19:27Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 17, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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 under migrate: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 .json against origin/main's is identical, 786,960 bytes each. Both carry prevId all-zeros, so the next migrate:create diffs 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.ts lists one entry, and main's copy already had an empty down.
  • Contracts: the contractSync producer sources (src/payload-types.ts, Events responseTypes.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.surfacePaths path is touched and the body cites no preview links.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/migrations/AGENTS.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 17, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1188 November 17, 2026 19:47 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor

Both adversarial-review threads addressed. Pushed cb5ac3b.

Adopted — the down guard misfires on migrate:refresh (d7b752a). It refused on any database holding more than one non-dev row. migrate:refresh runs the oldest migration's down first and deletes no row beforehand, so one more migration would have made it refuse a healthy database. It now counts rows whose name sorts before the baseline's — the pre-squash chain, nothing else. Proven on a throwaway database in three states; the row count refused the third.

Adopted — the squash checks repeat this PR's proof (cb5ac3b). Five conditions, one line each. Rules kept, mechanics dropped, numbers left in the body.

Branch was already level with main, so no merge. Gate green: 276 files, 3742 tests. No integration spec covers this area, so the guard was verified by running its SQL against seeded payload_migrations rows.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 17, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 17, 2026
@sydevs-bot
sydevs-bot enabled auto-merge November 17, 2026 19:58

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 17, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit cb9c611 Nov 17, 2026
43 of 45 checks passed
@sydevs-bot
sydevs-bot deleted the claude/squash-migrations branch November 17, 2026 20:54
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 17, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-1188 — cb5ac3bc Deployed Nov 17, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants