Public: anyone can read this; the crew can change it.
The release tick's gate passes the migration-order test: "two pulls' migrations land in either order" must not depend on a 6.5 s wait #15508
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15506-the-release-tick-s-gate-passes-the-migra → main 0 commits fork
1 file
changed +26
−4
test/schema-migrations.test.ts +26 −4
| @@ -28,6 +28,7 @@ import { ForgeError } from "../src/kernel/error.ts"; | ||
| 28 | 28 | import { sha256 } from "../src/kernel/hash.ts"; |
| 29 | 29 | import { |
| 30 | 30 | type Migration, |
| 31 | type MigrationFile, | |
| 31 | 32 | migrate, |
| 32 | 33 | migrationId, |
| 33 | 34 | pinBreaks, |
| @@ -360,7 +361,24 @@ describe("a migration is a file named by a sortable id (#1837)", () => { | ||
| 360 | 361 | return dir; |
| 361 | 362 | } |
| 362 | 363 | |
| 363 | const listIn = readMigrations; | |
| 364 | /** | |
| 365 | * The shipped migrations with `extra` beside them, in the order | |
| 366 | * `readMigrations` gives one directory holding both. Only the extras are | |
| 367 | * written and read: copying the whole directory and requiring each of its | |
| 368 | * files anew was most of the test's time, and under load past Bun's | |
| 369 | * timeout (#15506). The test below reads stamped and shipped files in one | |
| 370 | * directory. | |
| 371 | */ | |
| 372 | function shippedWith(extra: Record<string, string>): MigrationFile[] { | |
| 373 | const dir = join(root, `extra-${++n}`); | |
| 374 | mkdirSync(dir); | |
| 375 | for (const [name, sql] of Object.entries(extra)) | |
| 376 | writeFileSync(join(dir, name), `export default ${JSON.stringify(sql)};\n`); | |
| 377 | const file = (m: MigrationFile): string => `${m.name}.ts`; | |
| 378 | return [...migrationFiles, ...readMigrations(dir)].sort((x, y) => | |
| 379 | file(x) < file(y) ? -1 : file(x) > file(y) ? 1 : 0, | |
| 380 | ); | |
| 381 | } | |
| 364 | 382 | |
| 365 | 383 | /** Everything a schema is but the record of how it got there. */ |
| 366 | 384 | function shape(path: string): unknown[] { |
| @@ -393,16 +411,20 @@ describe("a migration is a file named by a sortable id (#1837)", () => { | ||
| 393 | 411 | // a's after b's, so b sorts first whichever lands first. |
| 394 | 412 | const a = { "20991231120000-deploy-note.ts": "CREATE TABLE deploy_note (id TEXT PRIMARY KEY, body TEXT NOT NULL DEFAULT '')" }; |
| 395 | 413 | const b = { "20991231110000-user-motto.ts": "ALTER TABLE user ADD COLUMN motto TEXT NOT NULL DEFAULT ''; CREATE INDEX user_motto ON user(motto)" }; |
| 396 | const both = listIn(directory({ ...a, ...b })); | |
| 414 | const both = shippedWith({ ...a, ...b }); | |
| 397 | 415 | expect(both.length).toBe(migrations.length + 2); |
| 416 | expect(both.slice(-2).map((m) => m.name)).toEqual([ | |
| 417 | "20991231110000-user-motto", | |
| 418 | "20991231120000-deploy-note", | |
| 419 | ]); | |
| 398 | 420 | |
| 399 | 421 | // The shipped migrations replay once (production() copies the cached file); |
| 400 | 422 | // each database then takes only the stamped migrations it is missing. |
| 401 | 423 | const aFirst = production(migrations); |
| 402 | boot(aFirst, listIn(directory(a))); | |
| 424 | boot(aFirst, shippedWith(a)); | |
| 403 | 425 | boot(aFirst, both); |
| 404 | 426 | const bFirst = production(migrations); |
| 405 | boot(bFirst, listIn(directory(b))); | |
| 427 | boot(bFirst, shippedWith(b)); | |
| 406 | 428 | boot(bFirst, both); |
| 407 | 429 | const together = production(migrations); |
| 408 | 430 | boot(together, both); |
new above
offline