garage44.eu/jeroen/cartopolis

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

.. /docs/adr/002-sqlite-storage.md

raw

ADR-002: SQLite for Region and Prim Storage


Metadata:


Context

Problem: Need persistent storage for regions (geographic areas with tile coordinates) and prims (3D primitives: boxes, spheres, cylinders, cones, toruses) with position, rotation, scale, and color.

Requirements:

Decision

Use SQLite via rusqlite (bundled) for region and prim storage.

Approach: Single file data/world.db, owned exclusively by cartopolis_simulator and versioned with refinery SQL migrations (crates/cartopolis_simulator/migrations/, applied on startup). It holds prims (geo-anchored, ADR-029), accounts (ADR-016), chat scrollback (ADR-028), and textures. The client keeps no local SQLite: the anonymous Viewer tier (ADR-031) is a streamed map viewer, and all authored state is online and server-authoritative. (Solo/dev mode runs the same cartopolis_simulator in-process against data/world.db — ADR-016.)

Rationale

Primary Reasoning:

  1. Zero-config: Single file, no server
  2. Mature: SQLite is battle-tested and reliable
  3. rusqlite: Rust bindings, no extra dependencies
  4. ACID: Transactions for consistency
  5. Portable: Copy data/ folder to move data

Alternatives Considered:

AlternativeProsConsRejected Because
JSON filesSimpleNo schema, no queryingNeed relational queries
PostgreSQLFull-featuredRequires serverOverkill for local use
sledEmbedded, RustKey-valueNeed relational model
SQLiteEmbedded, SQLSingle writerAcceptable for single-user

Consequences

Positive:

Negative:

Related