package migra
A database migration tool and library for OCaml supporting PostgreSQL, MariaDB/MySQL, and SQLite
Install
dune-project
Dependency
Authors
Maintainers
Sources
migra-2.1.1.tbz
sha256=793336d05c296f0283ee174074933cbebf38c5cd982bc4745f8d1261fa6f1907
sha512=ad32e72875fc4046bc133a8bea15b3ee41cd6985f509221b7d6bb1bfd713b4b2c0b441b89179d09a89067c205bdc0a17ddd2b8ab8eb6a84f747aa04f4ce006f7
doc/CHANGELOG.html
Changelog
All notable changes to this project are documented here. The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
2.1.1
Fixed
migrateand every command that ensures the tracking table no longer fail on MySQL.ensure_migrations_tableranALTER TABLE ... ADD COLUMN IF NOT EXISTS, a MariaDB-only extension that MySQL rejects as a syntax error, so migra was effectively broken againstmysql://servers. The table is now created with thechecksumcolumn directly, with no post-creation backfill.statusand--dry-runno longer take the wrong path when another database (MySQL/MariaDB) or schema (PostgreSQL) on the same server has aschema_migrationstable.table_existsnow resolves on the connection's own database and search_path - PostgreSQL viato_regclass, MySQL/MariaDB viaDATABASE()- instead of matching by table name across the whole server.- An invalid migrations-table name passed to
--table(an empty or extra segment such aspublic.,a..b, ora.b.c) is now rejected with a clear validation error instead of surfacing later as a database parse error. - The
redocommand's--helptext and the README'sredoone-liner now describe its actual behavior: roll back the last migration(s), then run all pending migrations.
2.1.0
Fixed
generateno longer creates a migration file that breaks discovery. An empty or otherwise invalid name (anything outside letters, digits, and underscores) is now rejected, as is a name already used by an existing migration. Such files were previously written - and reported as created - then made every latermigrate,status, androllbackfail until removed by hand.- Two migrations generated in the same second no longer collide silently. Version stamps have one-second resolution, so
generatenow reports the duplicate and exits instead of writing a second file with the same version (which discovery would then reject).
Added
Types.VersionTakenerror variant, returned bygeneratewhen the version it would assign is already used by a migration on disk.
2.0.0
Changed (breaking)
- The engine is no longer shipped as a separate public
migra.enginelibrary. Its modules (runner, SQL parser, dialect, discovery, migration, connection) are now private modules ofmigra, so code that reached intoMigra_engine.*must use the publicMigra.*API. The CLI and theMigra.Database/Migra.Migrator/Migra.Types/Migra.Loggingfacades are unchanged. Migra.Migrator.rollback_strategyis its own type rather than an alias of the engine's strategy type.- Logging is no longer configured as a side effect of loading the library. Linking
migrano longer installs aLogsreporter or sets the level; callMigra.Logging.setup ()to opt in (the CLI does this at startup). - Removed the unused error variants
FileNotFound,DatabaseNotFound, andTransactionFailed, and addedWriteErrorfor migration-file write failures.
Added
generatehonors the--diroption (andMigrator.generate ~migrations_dir).
Fixed
- The database lifecycle commands (
init/setup/drop/reset) acceptsqlite3:pathURLs - the documented form, and whatsqlite3://normalizes to - which previously failed with "invalid path format". mysql://connection URLs are rewritten to themariadb://scheme the Caqti driver registers, so they connect instead of reporting a missing driver.- A connection failure that merely mentions "not found" (a missing host, role, or database) is no longer misreported as a missing database driver.
- Migration version stamps are generated in UTC, so they no longer depend on the developer's timezone or DST.
- The
DELIMITERdirective is honored only for MySQL/MariaDB, so SQL beginning with the word "delimiter" is not misparsed on other dialects. - The SQL splitter handles digit-led dollar tags (
$1$), PostgreSQLE'...'escape strings, and backslash escapes inside MySQL double-quoted strings. - Each migration file is read once when applied, so the recorded checksum always matches the SQL that ran.
statusandmigrate --dry-runare read-only and no longer create the migrations-tracking table.- Conflicting
rollbackselectors (--allwith--toor--step) are rejected instead of silently ignored. - A migration-file write failure is reported as a write error (no longer a read error) and no longer leaks the file descriptor.
- Removed a doubled blank line from applied/rolled-back migration output.
Known limitations
- Migration atomicity has per-dialect limits: MySQL/MariaDB DDL implicitly commits, a
COMMIT/BEGINin a migration's own SQL ends Migra's wrapping transaction early, and on PostgreSQL a statement that returns rows (e.g.SELECT setval(...)) is rejected. See the Transactions notes in the README.
1.0.1
Fixed
rollbackandredonow validate applied migrations against the files on disk before running and returnErroron drift (a modified or missing applied migration), just likemigrate. Previously they could roll back using modified down SQL or silently skip a migration whose file was gone.statusnow includes an applied migration whose file is missing (shown as(migration file missing)) instead of hiding it and understating the applied count.- Database lifecycle commands (
create_database/drop_database) now quote and escape the database identifier in the generated DDL, so PostgreSQL names such asmy-dbwork and MariaDB names containing backticks are handled safely.
1.0.0
First stable release.
Added
- Checksums & validation - each applied migration's file checksum is recorded;
migraterefuses to run if an already-applied migration was modified (ChecksumMismatch) or its file went missing (AppliedFileMissing). - Out-of-order detection - adding a migration older than the latest applied one is rejected (
OutOfOrder). - Configurable migrations table via
--table/Migrator.make ~table. redocommand andMigrator.redo- roll back the last migration(s) and re-apply.--dry-runformigrateandrollback- preview without changing the database.--database-urlflag - overrides theDATABASE_URLenvironment variable.- Library facade -
Migra.Migrator(run/run_or_error/rollback/redo/status/generate, with?on_eventprogress callbacks) andMigra.Database(lifecycle + URL helpers) form the public API; the implementation lives in the internalmigra.enginelibrary. Migra.Migrator.run_or_error- a fail-fast wrapper aroundrunfor the migrate-on-startup path: a migration whose SQL fails is returned asError(MigrationError (ExecutionFailed ...)) rather thanOkwithfailure_count > 0.- Arbitrary SQL support: dollar-quoted bodies,
DELIMITERfor MySQL/MariaDB routines, line/block comments, and literal$/?in statements.
Changed
- Credentials are masked (
*****) instatusoutput and never printed in clear. - Stricter migration filenames: exactly 14 digits then
_<description>.sql; malformed migration-shaped files are reported instead of silently skipped. Migrator.run/rollbackreturnErroronly when migrations could not run; per-migration SQL failures surface asOkwithfailure_count > 0(seeMigrator.succeeded).
Fixed
- Connections are always closed (no leak), even on error paths.
- The admin connection URL preserves passwords, query parameters, and IPv6 hosts.
- Duplicate migration versions are detected and rejected.
Known limitations
- On MySQL/MariaDB, DDL statements implicitly commit and cannot be rolled back, so a multi-statement DDL migration is not atomic there. Keep MySQL/MariaDB migrations to a single DDL change each. (PostgreSQL and SQLite are fully transactional, including DDL.)