kiroku-store-migrations: Schema migrations for kiroku-store

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

Native pg-migrate component, Codd history mapping, and migration executable for installing and upgrading the PostgreSQL schema used by kiroku-store.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 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), containers (>=0.6 && <0.8), filepath (>=1.4 && <1.6), hasql (>=1.10 && <1.11), kiroku-store-migrations, 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) [details]
License BSD-3-Clause
Author Nadeem Bitar
Maintainer nadeem@gmail.com
Uploaded by shinzui at 2026-07-14T14:10:09Z
Category Database, Eventing
Home page https://github.com/shinzui/kiroku
Bug tracker https://github.com/shinzui/kiroku/issues
Source repo head: git clone https://github.com/shinzui/kiroku.git
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Executables kiroku-store-migrate
Downloads 20 total (11 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 kiroku-store-migrations-0.3.0.0

[back to package description]

kiroku-store-migrations

kiroku-store-migrations owns Kiroku's PostgreSQL schema as one native pg-migrate component named kiroku. The component embeds an ordered manifest and seven immutable SQL payloads, so applications can compose it with other libraries without copying Kiroku SQL.

Public API

import Kiroku.Store.Migrations

kirokuMigrations :: Either DefinitionError MigrationComponent
kirokuMigrationPlan :: Either PlanError MigrationPlan

Applications with more than one component should consume kirokuMigrations and build their own explicit dependency-ordered plan. The single-component kirokuMigrationPlan is convenient for Kiroku-only deployments.

Existing databases can import their Codd ledger through Kiroku.Store.Migrations.History.Codd:

kirokuCoddHistoryMappings :: NonEmpty HistoryMapping
kirokuCoddSourcePayloads :: Map FilePath ByteString
kirokuCoddManifestText :: Text

kirokuCoddSourceConfig
  :: ConnectionProvider
  -> Bool
  -> Text
  -> Confirmation
  -> Either CoddDefinitionError CoddSourceConfig

The mapping selects the seven historical timestamped Codd names, verifies the checked-in migrations.lock SHA-256 evidence against the exact embedded native bytes, and maps them to kiroku/0001-kiroku-bootstrap through kiroku/0007-stream-truncate-before. Import writes only the pgmigrate ledger; it never executes already-applied SQL. Consumers with a shared Codd ledger can combine the exported names, payload map, manifest text, and history mappings with their own component evidence before constructing one atomic import.

CLI

kiroku-store-migrate mounts the standard pg-migrate-cli command groups:

kiroku-store-migrate --help
kiroku-store-migrate plan
kiroku-store-migrate list
kiroku-store-migrate check --manifest kiroku-store-migrations/migrations/manifest
kiroku-store-migrate up --database-url "$DATABASE_URL"
kiroku-store-migrate verify --database-url "$DATABASE_URL"
kiroku-store-migrate status --database-url "$DATABASE_URL"

Database commands accept --database-url. When it is omitted the executable uses DATABASE_URL. Local plan, list, check, and new commands need no database environment variable. verify compares the declared plan strictly with the pgmigrate ledger; it is not a live schema snapshot comparison.

For Haskell callers:

import Database.PostgreSQL.Migrate
import Hasql.Connection.Settings qualified as Settings
import Kiroku.Store.Migrations

main :: IO ()
main = do
  plan <- either (fail . show) pure kirokuMigrationPlan
  result <- runMigrationPlan defaultRunOptions (Settings.connectionString databaseUrl) plan
  either (fail . show) (const (pure ())) result

Authoring

The authoritative source is migrations/manifest; each line names one SQL file in execution order. Create the next numeric file with the standard CLI:

kiroku-store-migrate new \
  --manifest kiroku-store-migrations/migrations/manifest \
  --description "add widget index"

The helper exclusively creates the inferred file and atomically appends its name to the manifest. Never edit a released payload. Correct mistakes with a new forward migration. The seven initial payloads intentionally retain their exact historical bytes, including old comments, because Codd import uses SamePayload evidence.

Run the package suite after every migration change:

cabal test kiroku-store-migrations:kiroku-store-migrations-test

It proves manifest order, legacy SHA-256 parity, fresh apply, strict verify, idempotent rerun, concurrent locking, current Codd V5 import, legacy codd_schema import, partial-row rejection, import audit records, and source-ledger preservation. cabal test kiroku-store:kiroku-store-test consumes the same native plan through kiroku-test-support and proves the complete store behavior, including append and read scenarios.

Recovery

Migrations are forward-only. Before a persistent upgrade, take a backup. If an applied migration is bad, either restore that backup or append a corrective migration. Do not delete or rewrite an applied pgmigrate.migrations row except through the reviewed pg-migrate repair workflow.

The historical script under ledger-fixups/ remains checked in only as source evidence for databases that previously needed Codd timestamp repair. New native migrations use component-local numeric identities and do not use timestamped filenames.