garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/013-sqlite-migrations-and-server-writer.md

raw

ADR-013: SQLite Migrations and Single Server Writer


Metadata:


Context

Problem: ADR-002 chose SQLite for regions and prims. A networked sim (ADR-007) must avoid corruption from concurrent writers and must evolve schema without breaking deployed worlds.

Requirements:

Decision

cartopolis_simulator is the sole writer to world.db (or configured path). Schema changes go through checked-in migrations applied on startup.

Implementation (cartopolis_simulator/src/db.rs, state.rs):

Rationale

Primary Reasoning:

  1. SQLite expectation: Single writer is the safe default; WAL helps readers but not multi-writer apps.
  2. Operational clarity: The sim owns the world (ADR-007).
  3. Growth: Migrations unlock new columns for networking ids, timestamps, etc.

Alternatives Considered:

AlternativeProsConsRejected Because
Multi-writer SQLiteTheoretical scaleFragileRejected
Client direct DB over NFS“Simple”Corruption + latencyRejected
Move to Postgres (sqlx) in v0Robust multi-nodeBig jumpDefer until needed

Consequences

Positive:

Negative:

Related