server: token records and the entity migration step (#20)
Migration step 4 ("tokens") creates the entity table: the token id, scene, kind,
both names, position, nullable radius/owner/vision_radius, gm_only and flags. A
NULL owner is GM-controlled, so player.remove hands that player's tokens to the GM
through the FK; radius, props and character_id stay out until slices 7-8.
server/tokens.nim holds the record, the 6.1 field rules (12 CSPRNG characters from
a 64-symbol alphabet, trimmed names, kind, positive vision_radius), the write-through
persistence (FULL for GM authoring, NORMAL for a move) and the loader. db_connector
quotes every argument, so the three nullable columns are emitted as numeric literals
while text still goes through ? arguments.
This commit is contained in:
+12
-7
@@ -38,15 +38,17 @@ suite "migrate":
|
||||
check migrate(db) == LatestVersion
|
||||
check LatestVersion == migrations[^1].version
|
||||
check schemaVersion(db) == LatestVersion
|
||||
check LatestVersion == 3
|
||||
check LatestVersion == 4
|
||||
let rows = appliedMigrations(db)
|
||||
check rows.len == 3
|
||||
check rows.len == 4
|
||||
check rows[0][0] == 1
|
||||
check rows[0][1] == "meta"
|
||||
check rows[1][0] == 2
|
||||
check rows[1][1] == "auth"
|
||||
check rows[2][0] == 3
|
||||
check rows[2][1] == "world"
|
||||
check rows[3][0] == 4
|
||||
check rows[3][1] == "tokens"
|
||||
# the steps' own DDL ran: meta and the auth tables exist and are empty
|
||||
check db.getValue(sql"SELECT count(*) FROM meta") == "0"
|
||||
check db.getValue(sql"SELECT count(*) FROM player") == "0"
|
||||
@@ -55,12 +57,14 @@ suite "migrate":
|
||||
# step 3 seeds the single v1 scene (Q3) and no walls
|
||||
check db.getValue(sql"SELECT count(*) FROM scene") == "1"
|
||||
check db.getValue(sql"SELECT count(*) FROM wall") == "0"
|
||||
# step 4 creates the token table (DESIGN 4.4 `entity`), empty
|
||||
check db.getValue(sql"SELECT count(*) FROM entity") == "0"
|
||||
|
||||
test "re-open is a no-op: no step applied, history and timestamps untouched":
|
||||
let d = tmpDir()
|
||||
block:
|
||||
let db = openFresh(d)
|
||||
check migrate(db) == 3
|
||||
check migrate(db) == 4
|
||||
close(db)
|
||||
let db = openFresh(d)
|
||||
defer:
|
||||
@@ -69,7 +73,7 @@ suite "migrate":
|
||||
let before = appliedMigrations(db)
|
||||
check migrate(db) == 0
|
||||
check migrate(db) == 0
|
||||
check schemaVersion(db) == 3
|
||||
check schemaVersion(db) == 4
|
||||
check appliedMigrations(db) == before
|
||||
|
||||
test "history and user_version must agree":
|
||||
@@ -124,7 +128,7 @@ suite "migrate":
|
||||
# the runner's own bookkeeping table may exist, but the failed step left nothing else
|
||||
check db.getValue(sql"SELECT count(*) FROM sqlite_master WHERE name = 'meta'") == "1"
|
||||
|
||||
test "a slice-2 DB migrates to slice 3: the scene is seeded, players and keys survive":
|
||||
test "a slice-2 DB migrates on: the scene is seeded, players and keys survive":
|
||||
let d = tmpDir()
|
||||
let db = openFresh(d)
|
||||
defer:
|
||||
@@ -143,8 +147,9 @@ suite "migrate":
|
||||
check schemaVersion(db) == 2
|
||||
check db.getValue(sql"SELECT count(*) FROM sqlite_master WHERE name = 'scene'") == "0"
|
||||
|
||||
check migrate(db) == 1 # only step 3 runs
|
||||
check schemaVersion(db) == 3
|
||||
check migrate(db) == 2 # steps 3 and 4 run
|
||||
check schemaVersion(db) == 4
|
||||
check db.getValue(sql"SELECT count(*) FROM scene") == "1"
|
||||
check db.getValue(sql"SELECT next_wall_id FROM scene WHERE id = 1") == "1"
|
||||
check db.getValue(sql"SELECT count(*) FROM player WHERE role = 'gm'") == "1"
|
||||
check db.getValue(sql"SELECT count(*) FROM entity") == "0"
|
||||
|
||||
Reference in New Issue
Block a user