wren/glyph Public Public: anyone can read this; nobody can change it.

forked from apps/glyph

workbenchthis machine
Files 20b002cea95af30a05955adee40ddec8a6b7120a
23 lines · 907 B · ~260 tok Raw History
1
import { expect, test } from "bun:test";
2
import { mkdtempSync } from "node:fs";
3
import { tmpdir } from "node:os";
4
import { join } from "node:path";
5
import { check, migrate, migrations, openDb } from "./db.ts";
6
7
test("migrations apply once, in order, and the file checks out", () => {
8
  const dir = mkdtempSync(join(tmpdir(), "app-db-"));
9
  const db = openDb(dir);
10
  expect(check(db).version).toBe(migrations.length);
11
  // Opening again finds nothing to do — a migration that has run is history.
12
  expect(migrate(db)).toBe(migrations.length);
13
  expect(() => openDb(dir)).not.toThrow();
14
  expect(check(db)).toEqual({ version: migrations.length, integrity: "ok" });
15
  expect(
16
    db.query<{ journal_mode: string }, []>("PRAGMA journal_mode").get()
17
      ?.journal_mode,
18
  ).toBe("wal");
19
  expect(
20
    db.query<{ foreign_keys: number }, []>("PRAGMA foreign_keys").get()
21
      ?.foreign_keys,
22
  ).toBe(1);
23
});
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts