Shipping a robust DB migration runner for Chaufr (OCaml + Caqti + Lwt)

Deterministic, auditable database evolution for an OCaml backend using Caqti + Lwt — with checksums, rollback, safe SQL parsing, and a focused CLI.

Today I shipped a production-minded database migration runner for Chaufr. The goal: a deterministic, auditable, and safe way to apply schema changes that integrates with the existing Caqti + Lwt connection infrastructure.


Summary


Components Implemented

1. migrations.ml

2. initial_migration.ml

3. migrate.ml (CLI)

4. Tooling additions


Design Rationale

Goal Implementation Choice
Auditability Checksums + timestamps + persisted records
Safety SQL splitter preserves literal + dollar-quoted regions
Operational parity Uses same pool / masking / logging as runtime
Determinism Explicit up/down SQL + versioned records

Quick Usage

Action Command
Initialize system make migrate-init
Show status make migrate-status
Apply pending make migrate-up
Roll back last make migrate-down
Roll back all make migrate-reset
Current version make migrate-version

Example

# Ensure schema_migrations table exists
dune exec -- ./bin/migrate.exe init
Migration system initialized successfully

Internal Behavior Highlights


Next Steps


Why It Matters (OCaml Ecosystem)


Possible Follow-ups

Hey, this site is part of ring.muhokama.fun!