Skip to main content

Module migration

Module migration 

Available on crate features event-store or projection-store only.
Expand description

The schema, and the one way it is applied.

§Why a file rather than a sqlx::migrate!

The manifest carries the argument in full. The short form: a migrator’s _sqlx_migrations table is per schema, one per fixture instance, about a history this crate makes moot: every migration is IF NOT EXISTS, so apply runs them all against any schema, fresh or migrated by an older build. Since #420 the log has two, MIGRATION_1 and MIGRATION_3 (named: event-store).

§Why the SQL is include_str!d rather than written inline

happenstance-sqlite keeps its MIGRATION_1 as a &str constant in Rust and mirrors it into a doc comment, then has a test compare the mirror against sqlite_master object by object — because the two copies drift otherwise. A .sql file has no second copy to drift from, gets SQL syntax highlighting in every editor, and is the artefact a DBA asks for when they want to know what this crate will do to their database. include_str! means it is still compiled in, so a published crate carries its own schema and a consumer needs nothing from this repository to apply it.

Constants§

MIGRATION_1event-store
The event log’s first migration, as SQL; MIGRATION_3 follows it.
MIGRATION_2projection-store
The projection store’s schema, as SQL.
MIGRATION_3event-store
The event log’s second migration, as SQL: the write-group columns and their index (#420).
PROJECTION_SCHEMA_VERSIONprojection-store
The projection schema version this crate’s code is written against.
SCHEMA_VERSIONevent-store
The event log’s schema version.

Functions§

applyevent-store
Applies MIGRATION_1 and then MIGRATION_3 to whatever schema executor resolves against.
apply_projectionprojection-store
Applies MIGRATION_2 to whatever schema executor resolves against.