forked from jappel/leistungsbilanz-ts
Integrate project building structure
This commit is contained in:
commit
868f48e7ac
44 changed files with 5898 additions and 377 deletions
|
|
@ -6,7 +6,7 @@ import { it } from "node:test";
|
|||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
||||
import { createDatabaseContext } from "../src/db/database-context.js";
|
||||
|
||||
it("upgrades a populated pre-print database without changing its existing records", async () => {
|
||||
it("upgrades a populated pre-print database through the current schema without changing existing records", async () => {
|
||||
const source = path.resolve("src/db/migrations");
|
||||
const staging = mkdtempSync(path.join(tmpdir(), "leistungsbilanz-print-migration-"));
|
||||
const journal = JSON.parse(readFileSync(path.join(source, "meta/_journal.json"), "utf8"));
|
||||
|
|
@ -26,9 +26,12 @@ it("upgrades a populated pre-print database without changing its existing record
|
|||
INSERT INTO projects (id, name, current_revision) VALUES ('p', 'Existing project', 17);
|
||||
INSERT INTO distribution_boards (id, project_id, name, simultaneity_factor)
|
||||
VALUES ('b', 'p', 'Existing board', 0.7);
|
||||
INSERT INTO floors (id, project_id, name, sort_order)
|
||||
VALUES ('f', 'p', 'Existing floor', 3);
|
||||
`);
|
||||
const oldProject = context.sqlite.prepare("SELECT * FROM projects").get() as Record<string, unknown>;
|
||||
const oldBoard = context.sqlite.prepare("SELECT * FROM distribution_boards").get() as Record<string, unknown>;
|
||||
const oldFloor = context.sqlite.prepare("SELECT * FROM floors").get() as Record<string, unknown>;
|
||||
const backup = path.join(staging, "before-print.db");
|
||||
files.push(backup);
|
||||
await context.sqlite.backup(backup);
|
||||
|
|
@ -36,10 +39,14 @@ it("upgrades a populated pre-print database without changing its existing record
|
|||
migrate(context.db, { migrationsFolder: source });
|
||||
const project = context.sqlite.prepare("SELECT * FROM projects").get() as Record<string, unknown>;
|
||||
const board = context.sqlite.prepare("SELECT * FROM distribution_boards").get() as Record<string, unknown>;
|
||||
const floor = context.sqlite.prepare("SELECT * FROM floors").get() as Record<string, unknown>;
|
||||
for (const [key, value] of Object.entries(oldProject)) assert.deepEqual(project[key], value);
|
||||
for (const [key, value] of Object.entries(oldBoard)) assert.deepEqual(board[key], value);
|
||||
for (const [key, value] of Object.entries(oldFloor)) assert.deepEqual(floor[key], value);
|
||||
for (const field of ["site_address", "work_stage", "project_lead", "project_editor"]) assert.equal(project[field], null);
|
||||
for (const field of ["board_number", "location", "fed_from", "remark"]) assert.equal(board[field], null);
|
||||
assert.equal(floor.building_id, null);
|
||||
assert.equal(context.sqlite.prepare("SELECT count(*) AS count FROM buildings").get()!.count, 0);
|
||||
assert.equal(context.sqlite.prepare("SELECT count(*) AS count FROM document_branding_assets").get()!.count, 0);
|
||||
assert.equal(context.sqlite.prepare("SELECT count(*) AS count FROM document_branding_settings").get()!.count, 0);
|
||||
assert.deepEqual(context.sqlite.pragma("foreign_key_check"), []);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue