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:
@@ -49,21 +49,23 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
||||
const first = await startServer({ stateDir })
|
||||
const firstLog = first.log()
|
||||
await stopServer(first)
|
||||
assert.match(firstLog, /db_ready .*schema_version=3 applied=3/, firstLog)
|
||||
assert.match(firstLog, /db_ready .*schema_version=4 applied=4/, firstLog)
|
||||
assert.ok(fs.existsSync(first.dbPath), 'state.db was not created')
|
||||
|
||||
const db = new DatabaseSync(first.dbPath)
|
||||
try {
|
||||
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 3)
|
||||
assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 4)
|
||||
const rows = db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all()
|
||||
assert.deepEqual(rows.map(r => [Number(r.version), r.name]),
|
||||
[[1, 'meta'], [2, 'auth'], [3, 'world']])
|
||||
[[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens']])
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM meta').get().n), 0)
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM player').get().n), 0)
|
||||
// step 3 seeds the single v1 scene (Q3) with no walls and a counter at 1
|
||||
assert.deepEqual(db.prepare('SELECT id, next_wall_id FROM scene').all()
|
||||
.map(r => [Number(r.id), Number(r.next_wall_id)]), [[1, 1]])
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM wall').get().n), 0)
|
||||
// step 4 creates the token table (DESIGN 4.4 `entity`), empty
|
||||
assert.equal(Number(db.prepare('SELECT count(*) AS n FROM entity').get().n), 0)
|
||||
assert.equal(db.prepare('PRAGMA journal_mode').get().journal_mode, 'wal')
|
||||
} finally {
|
||||
db.close()
|
||||
@@ -72,7 +74,7 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async ()
|
||||
const second = await startServer({ stateDir })
|
||||
const secondLog = second.log().slice(firstLog.length)
|
||||
await stopServer(second)
|
||||
assert.match(secondLog, /db_ready .*schema_version=3 applied=0/, secondLog)
|
||||
assert.match(secondLog, /db_ready .*schema_version=4 applied=0/, secondLog)
|
||||
assert.doesNotMatch(secondLog, /applied=[1-9]/)
|
||||
} finally {
|
||||
fs.rmSync(stateDir, { recursive: true, force: true })
|
||||
|
||||
Reference in New Issue
Block a user