knex: Undefined max_batch when using knexSnakeCaseWrappers (Objection)
Bug
When running knex migrations configured with Objection’s knexSnakeCaseWrappers, the promise handler for the _latestBatchNumber query always returns a default value of 0:
// knex/src/migrate/index.js, lines 329-332
_latestBatchNumber(trx = this.knex) {
return trx.from(getTableName(this.config.tableName, this.config.schemaName))
.max('batch as max_batch').then(obj => obj[0].max_batch || 0);
}
This is because max_batch does not exist in obj. The actual structure of obj, due to knexSnakeCaseWrappers is:
obj = {
maxBatch: 2
}
Defaulting to 0 results in a batch number of 1 always being inserted into the knex_migrations table when using knexSnakeCaseWrappers.
In effect, this makes all of your migrations only use a single batch, which is potentially catastrophic when performing a rollback.
Environment
Knex version: 0.14.6 Database + version: Postgres 10.1 OS: macOS/Linux
Select applicable template from below. If issue is about oracledb support tag @ atiertant. For MSSql tag @ smorey2 . Rest of dialects doesn’t need tags.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 2
- Comments: 32 (16 by maintainers)
okay, we always explicitly specify the knexfile, so will give it a shot, ty for the heads up
Ah okay, I’ve found a big issue -
knexSnakeCaseMappers(and more specifically,postProcessResponseandwrapIdentifier) no longer seem to get applied to migrations. here is my knexfile, which is the same as when using knex0.15.x:When running migrations with
0.16.0-next5:ouch. thanks for bug report. let me do a hotfix and update our testsuite