Databases

[ AxiomCore · Documentation ]

Databases

Declare PostgreSQL or SQLite schemas in Acore, apply versioned migrations with the Axiom CLI and give a backend typed storage.

An Acore database contract declares the schema you want and its version. The Axiom CLI checks and builds it offline, applies it to a PostgreSQL or SQLite database as a versioned migration, and reports status and history. An Acore backend then reads and writes those tables through typed storage declarations instead of SQL strings.

The contract lifecycle

A database contract from Acore source to typed application storage
A database contract from Acore source to typed application storage
Diagram source
flowchart TD
  A[Schema and version in Acore] --> B[axiom database check and build]
  B --> C[axiom database migrate]
  C --> D[status and history]
  D --> E{Next change}
  E -->|Edit the schema| F[New version in source]
  F --> B
  E -->|Undo| G[rollback publishes a new version]
  G --> D
  D --> H[Backend storage declarations]
  H --> I[Typed application storage]
  1. Declare the schema in an .acore file beside an AxiomDeps.toml with type = "database". project(id: ..., version: ...) names the contract and its version.
  2. Check and build offline with axiom database check and axiom database build. Neither connects to a database.
  3. Migrate with axiom database migrate (or axiom run). The change is validated on a disposable copy, then applied as one versioned migration.
  4. Observe with status (applied and working versions, pending changes, drift) and history (migrations, compensating rollbacks, failed attempts).
  5. Change or undo. Every schema change needs a new version. rollback publishes another new version; it never rewrites history or restores deleted values.
  6. Use the tables from a backend through storage declarations. The CLI checks them against the compiled schema and migrates the linked database before the backend accepts requests.

Validation and review always come before a change reaches your database. Keep backups and test recovery for data you need to retain.

From a request to a table

How the task app's list endpoint reaches its SQLite table
How the task app's list endpoint reaches its SQLite table
Diagram source
flowchart LR
  A[GET /tasks endpoint] --> B[listTasks action]
  B --> C[Resources.tasks.list operation]
  C --> D[storage tasks: select list]
  D --> E[main.tasks table]

In the task app, the endpoint calls a managed action. The action awaits a resource operation, and the storage declaration implements that operation as a typed select on main.tasks. The runtime binds every input as a parameter and adds the authenticated tenant to the query. You never write SQL text for application queries.

Choose an engine

SQLitePostgreSQL
Supported versionsSQLite 3.37 or newerPostgreSQL 17 and 18
TargetA local file. migrate and run create it.An existing server you can reach. The CLI never provisions, starts or restarts it.
Connection--database-file, a sqlite: URL, or the project's default file--database-url, DATABASE_URL, or host, port, database and user fields
Pre-apply validationOn a copy of the file, including a populated backup for table rebuildsOn a disposable PostgreSQL of the same major version: bundled with the Linux CLI archives (PostgreSQL 17), otherwise a matching local installation
Checked platformsmacOS arm64 and Linux arm64 acceptanceDeclared Unix platforms

Both engines use the same commands, version rules and storage declarations. Windows, hosted-provider capabilities and nontransactional migration stages keep their own qualification gates. There is no MySQL or MariaDB adapter.

Where database work runs

PathWhat it showsStatus
Axiom CLI against SQLite or PostgreSQLReal migrations, history and typed application storage on your targetExperimental
Browser preview in the playgroundSimulated storage and history; no native migration, file or connectionExperimental
Fleet deliveryReviewed, frozen rollout to many enrolled targetsExperimental
Named PostgreSQL production profileAdmission for one exact build, platform and recovery procedureAvailable

A passing browser preview does not prove database persistence, and a local run does not qualify a production deployment.

Next steps