Testversion im Browser und Sicherung einspielen
Die Testversion bündelt Oberfläche und Server-Logik mit PGlite (Postgres als WebAssembly). POST /api/import/stand spielt einen kompletten Stand mit allen IDs in ein leeres Programm ein; damit ziehen die Daten später auf den Server um. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
This commit is contained in:
32
demo/kern.ts
Normal file
32
demo/kern.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
// Startet die echte Server-Logik (src/server/app.ts) auf PGlite, ohne Netzwerk.
|
||||
import type { PGlite } from "@electric-sql/pglite";
|
||||
import { baueApp } from "../src/server/app.js";
|
||||
import { alsPool } from "./pool.js";
|
||||
import m001 from "../src/server/migrations/001_grundlage.sql";
|
||||
import m002 from "../src/server/migrations/002_v70_uebernahme.sql";
|
||||
import m003 from "../src/server/migrations/003_vorgangsnummer.sql";
|
||||
import m004 from "../src/server/migrations/004_besetzung.sql";
|
||||
|
||||
const MIGRATIONEN: [string, string][] = [
|
||||
["001_grundlage.sql", m001], ["002_v70_uebernahme.sql", m002], ["003_vorgangsnummer.sql", m003], ["004_besetzung.sql", m004],
|
||||
];
|
||||
|
||||
export async function starte(db: PGlite, v70?: unknown) {
|
||||
await db.exec("create table if not exists schema_version (name text primary key, eingespielt_am timestamptz not null default now())");
|
||||
const da = new Set((await db.query<{ name: string }>("select name from schema_version")).rows.map((r) => r.name));
|
||||
for (const [name, sql] of MIGRATIONEN) {
|
||||
if (da.has(name)) continue;
|
||||
await db.transaction(async (t) => {
|
||||
await t.exec(sql);
|
||||
await t.query("insert into schema_version (name) values ($1)", [name]);
|
||||
});
|
||||
}
|
||||
const app = (await baueApp({ pool: alsPool(db) as any })) as unknown as {
|
||||
verarbeite(methode: string, adresse: string, body?: unknown, headers?: Record<string, string>): Promise<Response>;
|
||||
};
|
||||
if (v70 && (await db.query("select 1 from projekt limit 1")).rows.length === 0) {
|
||||
const r = await app.verarbeite("POST", "/api/import/v70", v70);
|
||||
if (!r.ok) throw new Error(`Übernahme der V70-Daten: ${await r.text()}`);
|
||||
}
|
||||
return app;
|
||||
}
|
||||
Reference in New Issue
Block a user