Knex.js knex_migrations_lock Scope for Concurrent knex_migrate_latest Calls
0 reputation · 14 Apr 2026, 00:15 UTC
Goal
Serialize knex.migrate.latest() execution across multiple application instances during a rolling deployment so that only one migration process runs at a time.
Constraint
Knex uses a knex_migrations_lock table, but its scope appears to be single-node. It is unclear whether this lock serializes calls from separate instances or whether an external distributed lock is required. Behavior may also vary by Knex.js version and SQL dialect.
Uncertainty
MySQL and MariaDB DDL statements often cause implicit commits, so a failed migration can leave partial schema changes even if the migration row is recorded. It is unclear whether Knex wraps the full migration sequence in a transaction on these dialects.
Does knex.migrate.latest() hold knex_migrations_lock for the entire migration sequence across all supported dialects?
Is knex_migrations_lock sufficient to prevent concurrent migration runs from separate application instances?
What configuration controls transaction wrapping for individual migration files on MySQL?