db: game save schema — saves, solar_systems, jump_routes, events (single-player, one save)
This commit is contained in:
+35
-4
@@ -14,12 +14,43 @@ export interface GameDb {
|
||||
file: string;
|
||||
}
|
||||
|
||||
// CREATE TABLE statements mirroring lib/db/schema.ts — keep in sync. Game tables land with
|
||||
// the turn engine; _meta is DB plumbing (not game state): a brand-new sql.js database exports
|
||||
// as ZERO bytes, so without at least one real table there would be nothing valid to persist
|
||||
// on the ./db volume from first boot.
|
||||
// CREATE TABLE statements mirroring lib/db/schema.ts — keep in sync. _meta is DB plumbing
|
||||
// (not game state): a brand-new sql.js database exports as ZERO bytes, so without at least
|
||||
// one real table there would be nothing valid to persist on the ./db volume from first boot.
|
||||
const DDL = `
|
||||
CREATE TABLE IF NOT EXISTS _meta (key TEXT PRIMARY KEY, value TEXT);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS saves (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
seed TEXT NOT NULL,
|
||||
turn INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS solar_systems (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
save_id INTEGER NOT NULL REFERENCES saves(id),
|
||||
name TEXT NOT NULL,
|
||||
x REAL NOT NULL,
|
||||
y REAL NOT NULL,
|
||||
discovered INTEGER NOT NULL DEFAULT 0,
|
||||
is_current INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS jump_routes (
|
||||
from_system INTEGER NOT NULL REFERENCES solar_systems(id),
|
||||
to_system INTEGER NOT NULL REFERENCES solar_systems(id),
|
||||
PRIMARY KEY (from_system, to_system)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
save_id INTEGER NOT NULL REFERENCES saves(id),
|
||||
turn INTEGER NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
`;
|
||||
|
||||
// SPACE_WANDERER_DB_PATH override exists so unit tests can point at a temp file instead
|
||||
|
||||
Reference in New Issue
Block a user