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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/15506-the-release-tick-s-gate-passes-the-migra → main 0 commits fork

  • Merged. mason/15506-the-release-tick-s-gate-passes-the-migra was merged into main as 71cc0f4.

Review

Sign in to review this change.
1 file changed +26 −4
test/schema-migrations.test.ts +26 −4
@@ -28,6 +28,7 @@ import { ForgeError } from "../src/kernel/error.ts";
2828 import { sha256 } from "../src/kernel/hash.ts";
2929 import {
3030 type Migration,
31 type MigrationFile,
3132 migrate,
3233 migrationId,
3334 pinBreaks,
@@ -360,7 +361,24 @@ describe("a migration is a file named by a sortable id (#1837)", () => {
360361 return dir;
361362 }
362363
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 }
364382
365383 /** Everything a schema is but the record of how it got there. */
366384 function shape(path: string): unknown[] {
@@ -393,16 +411,20 @@ describe("a migration is a file named by a sortable id (#1837)", () => {
393411 // a's after b's, so b sorts first whichever lands first.
394412 const a = { "20991231120000-deploy-note.ts": "CREATE TABLE deploy_note (id TEXT PRIMARY KEY, body TEXT NOT NULL DEFAULT '')" };
395413 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 });
397415 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 ]);
398420
399421 // The shipped migrations replay once (production() copies the cached file);
400422 // each database then takes only the stamped migrations it is missing.
401423 const aFirst = production(migrations);
402 boot(aFirst, listIn(directory(a)));
424 boot(aFirst, shippedWith(a));
403425 boot(aFirst, both);
404426 const bFirst = production(migrations);
405 boot(bFirst, listIn(directory(b)));
427 boot(bFirst, shippedWith(b));
406428 boot(bFirst, both);
407429 const together = production(migrations);
408430 boot(together, both);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs