Skip to content

Commit

Permalink
Insert lock row fix during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierCavadenti committed Nov 30, 2021
1 parent bd1c31a commit c0bdcf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/migrations/migrate/migration-list-resolver.js
Expand Up @@ -11,12 +11,10 @@ function listAll(migrationSource, loadExtensions) {
async function listCompleted(tableName, schemaName, trxOrKnex) {
await ensureTable(tableName, schemaName, trxOrKnex);

const completedMigrations = await trxOrKnex
return await trxOrKnex
.from(getTableName(tableName, schemaName))
.orderBy('id')
.select('name');

return completedMigrations;
}

// Gets the migration list from the migration directory specified in config, as well as
Expand Down
11 changes: 6 additions & 5 deletions lib/migrations/migrate/table-creator.js
Expand Up @@ -55,11 +55,12 @@ function _createMigrationLockTable(tableName, schemaName, trxOrKnex) {
function _insertLockRowIfNeeded(tableName, schemaName, trxOrKnex) {
const lockTableWithSchema = getLockTableNameWithSchema(tableName, schemaName);
return trxOrKnex
.from(trxOrKnex.raw('?? (??)', [lockTableWithSchema, 'is_locked']))
.insert(function () {
return this.select(trxOrKnex.raw('?', [0])).whereNotExists(function () {
return this.select('*').from(lockTableWithSchema);
});
.select('*')
.from(lockTableWithSchema)
.then((data) => {
return !data.length
? trxOrKnex.from(lockTableWithSchema).insert({ is_locked: 0 })
: null;
});
}

Expand Down

0 comments on commit c0bdcf1

Please sign in to comment.