server: the property buckets, the registry and the status set (#22)

Migration step 6 ("token details") adds the three prop buckets to `entity`
and creates `entity_status`, the `(status, source)` set of 5.5. A token's
status rows are rewritten with its row, so a status change and the `token`
frame that reports it commit together.

server/props.nim owns the buckets, their caps (64 keys per bucket, a key of
1..64 code points, a value of at most 8 KB of serialized JSON) and the
property-schema registry: empty at start with a permissive fallback, because
DESIGN 8 says v1 never interprets props; a key the rules module registers is
enforced (kind and bucket). server/text.nim is the one copy of the 6.5 text
rule, shared by names and prop keys.

tokens.nim gains `props` and `statuses` on the record, the sorted-unique
entry helpers, `isLocked`, `parseRadius`/`parseStatusKind`/`parseStatusSource`,
the prop and status columns in insert/replace, and `loadStatuses` joined on
the scene. Every helper builds a fresh sequence: a copied record shares its
seq buffer, so an in-place edit would reach the authoritative list before
the transaction commits (4.2 step 6).
This commit is contained in:
2026-11-15 11:02:23 +01:00
parent d773a5e2de
commit 67762c1309
5 changed files with 364 additions and 38 deletions
+16
View File
@@ -17,6 +17,12 @@
## (DESIGN 4.4, 8): one row per (player, scene, 64x64-cell chunk), 512 B per row, LSB-first
## row-major bits (server/explored.nim). Both FKs cascade, so removing a player or a scene takes its
## explored cells with it.
## Step 6 ("token details", M3 slice 7 / #22) adds the three property buckets to `entity` (DESIGN 8:
## `props_public`, `props_owner`, `props_gm`, one JSON object each, `'{}'` by default) and creates
## `entity_status` for the `stuck`/`squeezed` model (DESIGN 4.4, 5.5): one row per
## `(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.
## 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
@@ -121,6 +127,16 @@ CREATE TABLE explored_chunk (
cy INTEGER NOT NULL,
bits BLOB NOT NULL CHECK (length(bits) = 512), -- 64x64 cells, LSB-first row-major
PRIMARY KEY (player_id, scene_id, cx, cy)
)"""]),
Migration(version: 6, name: "token details", stmts: @["""
ALTER TABLE entity ADD COLUMN props_public TEXT NOT NULL DEFAULT '{}'""", """
ALTER TABLE entity ADD COLUMN props_owner TEXT NOT NULL DEFAULT '{}'""", """
ALTER TABLE entity ADD COLUMN props_gm TEXT NOT NULL DEFAULT '{}'""", """
CREATE TABLE entity_status (
entity_id TEXT NOT NULL REFERENCES entity(id) ON DELETE CASCADE,
status TEXT NOT NULL CHECK (status IN ('stuck', 'squeezed')),
source TEXT NOT NULL CHECK (source IN ('walls', 'GM')),
PRIMARY KEY (entity_id, status, source)
)"""]),
]
LatestVersion* = migrations[^1].version