Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "prettier --check --cache . && eslint --cache .",
"format": "prettier --write .",
"build": "bun run scripts/run-all.ts build",
"test": "bun test scripts/run-all.test.ts && bun run scripts/run-all.ts test",
"test": "bun test ./scripts/*.test.ts && bun run scripts/run-all.ts test",
"test:e2e": "bun test scripts/e2e",
"dev": "bun run scripts/dev.ts",
"setup": "bun packages/cli/src/index.ts setup",
Expand Down
42 changes: 20 additions & 22 deletions scripts/db-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// the pre-re-pin numbering of workbench's own two migrations) is refused
// with the reset instruction instead of being patched incrementally.
// DB-gated: skipped when DATABASE_URL is unset.
import { afterAll, describe, expect, test } from "bun:test";
import { describe, expect, test } from "bun:test";

import { dbTargetFromUrl, loadPostgres, setupDatabase } from "./db-setup";

Expand All @@ -19,32 +19,30 @@ const OLD_NUMBERING_TAIL = [
describeIfDb(
"setupDatabase against a schema migrated under the old numbering",
() => {
const schema = `db_setup_test_${Date.now().toString(36)}`;
const target = dbTargetFromUrl(databaseUrl);
const client = loadPostgres().then((postgres) =>
postgres({ ...target, max: 1, onnotice: () => undefined }),
);
afterAll(async () => {
const sql = await client;
await sql.unsafe(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`);
await sql.end();
});

test("refuses to apply incrementally and names the reset", async () => {
const sql = await client;
await sql.unsafe(`CREATE SCHEMA "${schema}"`);
await sql.unsafe(
`CREATE TABLE "${schema}"."workbench_setup_migration" (filename text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`,
const schema = `db_setup_test_${Date.now().toString(36)}`;
const target = dbTargetFromUrl(databaseUrl);
const sql = await loadPostgres().then((postgres) =>
postgres({ ...target, max: 1, onnotice: () => undefined }),
);
for (const file of OLD_NUMBERING_TAIL) {
try {
await sql.unsafe(`CREATE SCHEMA "${schema}"`);
await sql.unsafe(
`INSERT INTO "${schema}"."workbench_setup_migration" (filename) VALUES ($1)`,
[file],
`CREATE TABLE "${schema}"."workbench_setup_migration" (filename text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`,
);
for (const file of OLD_NUMBERING_TAIL) {
await sql.unsafe(
`INSERT INTO "${schema}"."workbench_setup_migration" (filename) VALUES ($1)`,
[file],
);
}
await expect(setupDatabase(databaseUrl, { schema })).rejects.toThrow(
/different @intx\/db migration set[\s\S]*db-setup\.ts --reset/,
);
} finally {
await sql.unsafe(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`);
await sql.end();
}
await expect(setupDatabase(databaseUrl, { schema })).rejects.toThrow(
/different @intx\/db migration set[\s\S]*db-setup\.ts --reset/,
);
});
},
);
Loading