migration

Sequential schema migrations applied at startup. Sequential schema migrations for the application database.

Each migration is defined in its own submodule (m00001_*, m00002_*, …) and registered in the MIGRATIONS array. The run function applies any migrations that have not yet been recorded in the _migrations tracking table.

Name Summary
m00001_create_projects Initial projects table recording each known project root.
m00002_create_project_workspaces project_workspaces table mapping additional checkouts to a project.
m00003_create_authors authors table for humans and agents referenced by other records.
m00004_create_tasks tasks table representing work items tracked within a project.
m00005_create_artifacts artifacts table storing long-form documents attached to a project.
m00006_create_iterations iterations table grouping tasks into time-boxed units of work.
m00007_create_tags tags table holding the global set of labels applied to entities.
m00008_create_entity_tags entity_tags join table associating tags with arbitrary entity types.
m00009_create_notes notes table recording free-form comments attached to any entity.
m00010_create_relationships relationships table linking entities via typed directed edges.
m00011_create_iteration_tasks iteration_tasks join table assigning tasks to iteration phases.
m00012_create_transactions transactions table recording user-facing commands for undo history.
m00013_create_transaction_events transaction_events table capturing individual row changes per transaction.
m00014_create_sync_digests sync_digests table tracking content hashes of synced project files.
m00015_add_projects_archived_at Add nullable archived_at timestamp to the projects table.

struct Migration

source

struct Migration

A single versioned schema migration.

Field Type Description
name &'static str Human-readable name for logging.
sql &'static str SQL statements to execute when applying this migration.
version i64 Monotonically increasing version number.

const MIGRATIONS

source

const MIGRATIONS: &[Migration] = &[
  m00001_create_projects::MIGRATION,
  m00002_create_project_workspaces::MIGRATION,
  m00003_create_authors::MIGRATION,
  m00004_create_tasks::MIGRATION,
  m00005_create_artifacts::MIGRATION,
  m00006_create_iterations::MIGRATION,
  m00007_create_tags::MIGRATION,
  m00008_create_entity_tags::MIGRATION,
  m00009_create_notes::MIGRATION,
  m00010_create_relationships::MIGRATION,
  m00011_create_iteration_tasks::MIGRATION,
  m00012_create_transactions::MIGRATION,
  m00013_create_transaction_events::MIGRATION,
  m00014_create_sync_digests::MIGRATION,
  m00015_add_projects_archived_at::MIGRATION,
];

All registered migrations, in the order they must be applied.

fn run

source

pub async fn run(conn: &Connection) -> Result<(), Error>

Run all pending migrations against the given connection.

Creates the internal _migrations table if it does not yet exist, then applies each migration whose version has not been recorded.

Parameter Type Description
conn &Connection the connection to migrate
returns Result<(), Error> Ok(()) once every migration is recorded, or the first libsql error, which stops the run.