keiro-migrations: Schema migrations for keiro

[ bsd3, database, library, program ] [ Propose Tags ] [ Report a vulnerability ]

Embedded PostgreSQL schema migrations and a migration runner for the Keiro event-sourcing framework.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
legacy-codd-tools

Build transitional Codd expected-schema, remediation, and ledger-fixup targets. The normal pg-migrate closure excludes these dependencies.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.0.0, 0.3.0.0
Change log CHANGELOG.md
Dependencies aeson (>=2.1 && <2.3), base (>=4.18 && <5), bytestring (>=0.11 && <0.13), codd-extras (>=0.1 && <0.2), containers (>=0.6 && <0.8), hasql (>=1.10 && <1.11), keiro-migrations, kiroku-store-migrations (>=0.3.0.0 && <0.4), optparse-applicative (>=0.17 && <0.20), pg-migrate (>=1.1.0.0 && <1.2), pg-migrate-cli (>=1.1.0.0 && <1.2), pg-migrate-embed (>=1.1.0.0 && <1.2), pg-migrate-import-codd (>=1.1.0.0 && <1.2), template-haskell (>=2.20 && <2.24), text (>=2.0 && <2.2), time [details]
Tested with ghc >=9.12 && <9.13
License BSD-3-Clause
Copyright 2026 Nadeem Bitar
Author Nadeem Bitar
Maintainer nadeem@gmail.com
Uploaded by shinzui at 2026-07-14T15:25:34Z
Category Database
Source repo head: git clone https://github.com/shinzui/keiro.git
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables keiro-write-expected-schema, keiro-migrate
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for keiro-migrations-0.3.0.0

[back to package description]

Keiro database migrations

keiro-migrations exports a native pg-migrate component named keiro. The component owns sixteen embedded SQL migrations and declares one dependency, kiroku. Applications compose Kiroku first and Keiro second; Keiro never embeds or copies Kiroku's SQL.

import Keiro.Migrations (frameworkMigrationPlan, keiroMigrations)
import Kiroku.Store.Migrations qualified as Kiroku

plan = do
  kiroku <- Kiroku.kirokuMigrations
  keiro <- keiroMigrations
  frameworkMigrationPlan kiroku keiro

The keiro-migrate executable builds that plan and exposes the standard pg-migrate commands. Set DATABASE_URL or pass the connection option shown by the command help:

cabal run keiro-migrate -- plan
cabal run keiro-migrate -- status
cabal run keiro-migrate -- verify
cabal run keiro-migrate -- up

status and verify are read-only. up serializes concurrent callers with the pg-migrate advisory lock, applies all Kiroku migrations before Keiro, and reports already-applied migrations without replaying them.

Authoring native migrations

The ordered manifest is keiro-migrations/migrations/manifest. Migration names are stable component-local identifiers such as 0016-keiro-inbox-drop-received-idx; the timestamped files under sql-migrations/ and migrations.lock remain immutable legacy evidence for old Codd databases.

Create new work through the standard CLI and review the manifest append together with the new SQL file:

cabal run keiro-migrate -- new \
  --manifest keiro-migrations/migrations/manifest \
  --description "add order summary"
cabal run keiro-migrate -- check keiro-migrations/migrations/manifest

Never edit a migration that has shipped. Add a new forward migration for every schema correction.

Importing the shared Codd ledger

Keiro.Migrations.History.Codd combines Kiroku's seven mappings with Keiro's sixteen mappings. frameworkCoddSourceConfig selects both histories from the shared codd.sql_migrations or legacy codd_schema.sql_migrations ledger, checks the original SHA-256 manifests and payload bytes, and produces one atomic history import:

config <-
  either (fail . show) pure $
    frameworkCoddSourceConfig provider True reason Confirmed

result <-
  importCoddHistory
    defaultImportOptions
    config
    provider
    plan
    frameworkCoddHistoryMappings

Run the import while legacy migration writers are quiescent, then run strict verify. A partial row, missing payload, changed manifest, or unexpected row in strict mode fails before either target component is imported.

Databases first migrated by keiro-migrations 0.1.0.0 may have keiro_* tables under kiroku. Follow Upgrading To The Keiro Schema before importing their history.

Legacy transition tools

Codd expected-schema snapshots, remediation drills, and sentinel-ledger fixup tests remain available only through the manual legacy-codd-tools flag. They do not enter the normal library, executable, or test-support dependency closure:

cabal test -flegacy-codd-tools \
  keiro-migrations:keiro-migrations-legacy-test
cabal run -flegacy-codd-tools keiro-write-expected-schema

The normal migration suite is:

cabal test keiro-migrations:keiro-migrations-test