server: the character, reveal and encountered records and migration step 7 (#23)
This commit is contained in:
@@ -23,6 +23,17 @@
|
||||
## `(token, status, source)` entry, cascading on the token. `radius` was already a column from step 4
|
||||
## (`token.resize` is what makes it reachable); step 6 only makes the buckets and the statuses
|
||||
## persistent.
|
||||
## Step 7 ("characters", M3 slice 8 / #23) creates `character` (DESIGN 8: one owner, which is a real
|
||||
## player id and may be the GM's, both names, `reveal_all`, the three property buckets), `name_reveal`
|
||||
## (per-player reveal of one subject id: a character id or a plain token id, both from the token id
|
||||
## alphabet) and `encountered` (the per-player "met before" snapshot of DESIGN 8: names, optional
|
||||
## character link, no FK cascade so it survives token and character removal). It also adds
|
||||
## `entity.character_id` (NULL = a plain token; the character a token figures) and
|
||||
## `entity.reveal_all` for plain tokens, whose names the GM can reveal to everyone at once.
|
||||
## `character.owner_player_id` has no cascade on purpose: 3.2 hands a removed player's characters to
|
||||
## the GM, and `player.remove` reassigns them before the DELETE (a raw delete raises instead of
|
||||
## orphaning a record). `name_reveal` and `encountered` DO cascade on the player, because 6.1 deletes
|
||||
## that player's reveals and encountered list with them.
|
||||
## One connection, used under the server's global lock (4.3); this module does no locking itself.
|
||||
import std/[strutils, times]
|
||||
import db_connector/db_sqlite
|
||||
@@ -138,6 +149,37 @@ CREATE TABLE entity_status (
|
||||
source TEXT NOT NULL CHECK (source IN ('walls', 'GM')),
|
||||
PRIMARY KEY (entity_id, status, source)
|
||||
)"""]),
|
||||
Migration(version: 7, name: "characters", stmts: @["""
|
||||
CREATE TABLE character (
|
||||
id TEXT PRIMARY KEY, -- same 12-char alphabet and namespace as entity ids (8)
|
||||
owner_player_id INTEGER NOT NULL REFERENCES player(id), -- always a real player id, GM included
|
||||
descriptive_name TEXT NOT NULL,
|
||||
actual_name TEXT NOT NULL,
|
||||
reveal_all INTEGER NOT NULL DEFAULT 0 CHECK (reveal_all IN (0, 1)),
|
||||
props_public TEXT NOT NULL DEFAULT '{}',
|
||||
props_owner TEXT NOT NULL DEFAULT '{}',
|
||||
props_gm TEXT NOT NULL DEFAULT '{}',
|
||||
created_at TEXT NOT NULL
|
||||
)""", """
|
||||
CREATE INDEX character_owner ON character(owner_player_id)""", """
|
||||
CREATE TABLE name_reveal (
|
||||
player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE,
|
||||
subject_id TEXT NOT NULL, -- a character id, or a plain token id (never both for one subject)
|
||||
created_at TEXT NOT NULL,
|
||||
PRIMARY KEY (player_id, subject_id)
|
||||
)""", """
|
||||
CREATE TABLE encountered (
|
||||
player_id INTEGER NOT NULL REFERENCES player(id) ON DELETE CASCADE,
|
||||
entity_id TEXT NOT NULL, -- no FK: the entry outlives the token (8)
|
||||
character_id TEXT, -- NULL for a plain token; no FK, the entry outlives it too
|
||||
descriptive_name TEXT NOT NULL, -- the snapshot of the name this player knows (8)
|
||||
actual_name TEXT, -- NULL = this player has not been told the actual name
|
||||
created_at TEXT NOT NULL,
|
||||
PRIMARY KEY (player_id, entity_id)
|
||||
)""", """
|
||||
CREATE INDEX encountered_character ON encountered(character_id)""", """
|
||||
ALTER TABLE entity ADD COLUMN character_id TEXT REFERENCES character(id)""", """
|
||||
ALTER TABLE entity ADD COLUMN reveal_all INTEGER NOT NULL DEFAULT 0 CHECK (reveal_all IN (0, 1))"""]),
|
||||
]
|
||||
LatestVersion* = migrations[^1].version
|
||||
## Derived, so adding a step cannot leave it stale.
|
||||
|
||||
Reference in New Issue
Block a user