mud_server.db.schema
Schema creation and invariant trigger wiring for the SQLite backend.
The schema layer is intentionally isolated from gameplay/query code so schema changes are reviewable without wading through unrelated repository logic.
Attributes
Functions
|
Ensure state snapshot columns exist on the |
Create triggers that enforce account-first session invariants. |
|
|
Initialize the SQLite database schema and baseline triggers. |
Module Contents
- mud_server.db.schema.HOT_PATH_INDEX_STATEMENTS = ('CREATE INDEX IF NOT EXISTS idx_characters_user_world ON characters(user_id, world_id)',...
- mud_server.db.schema.ensure_character_state_columns(cursor)[source]
Ensure state snapshot columns exist on the
characterstable.SQLite cannot alter table definitions declaratively inside
CREATE TABLEfor pre-existing databases. We therefore perform additiveALTER TABLEoperations for each required column.
- mud_server.db.schema.create_session_invariant_triggers(conn)[source]
Create triggers that enforce account-first session invariants.
Invariant model: - Account-only session:
character_id IS NULLandworld_id IS NULL- In-world session:character_id IS NOT NULLandworld_id IS NOT NULLwith character ownership and world consistency constraints.
These triggers intentionally protect integrity for both Python helper paths and direct SQL writes.
- mud_server.db.schema.init_database(*, skip_superuser=False)[source]
Initialize the SQLite database schema and baseline triggers.
Behavior: - Creates required tables and indexes if missing. - Seeds the default world row when absent. - Ensures character snapshot columns are present. - Installs session invariant triggers. - Optionally creates a bootstrap superuser from environment variables.
- Parameters:
skip_superuser (bool) – When True, skip bootstrap superuser creation.