Skip to content

Commit

Permalink
Merge pull request #1023 from MaximeMRF/fix/step-option-migrator
Browse files Browse the repository at this point in the history
fix(migrator): step option
  • Loading branch information
thetutlage committed Apr 5, 2024
2 parents 5002dc9 + 781c479 commit b084678
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/migration/runner.ts
Expand Up @@ -482,7 +482,7 @@ export class MigrationRunner extends EventEmitter {
const collected = await this.migrationSource.getMigrations()

if (step === undefined || step <= 0) {
step = 0
step = collected.length
} else {
batch = (await this.getLatestBatch()) - 1
}
Expand All @@ -505,7 +505,8 @@ export class MigrationRunner extends EventEmitter {
}
})

const filesToMigrate = Object.keys(this.migratedFiles).slice(-step)
this.migratedFiles = Object.fromEntries(Object.entries(this.migratedFiles).slice(0, step))
const filesToMigrate = Object.keys(this.migratedFiles)
for (let name of filesToMigrate) {
await this.executeMigration(this.migratedFiles[name].file)
}
Expand Down
11 changes: 3 additions & 8 deletions test/migrations/migrator.spec.ts
Expand Up @@ -704,17 +704,12 @@ test.group('Migrator', (group) => {
})

assert.lengthOf(migrated, 1)
assert.isFalse(hasUsersTable)
assert.isTrue(hasAccountsTable)
assert.isTrue(hasUsersTable)
assert.isFalse(hasAccountsTable)
assert.deepEqual(migratedFiles, [
{
status: 'pending',
file: 'database/migrations/1_accounts_v6',
queries: [],
},
{
status: 'completed',
file: 'database/migrations/0_users_v6',
file: 'database/migrations/1_accounts_v6',
queries: [],
},
])
Expand Down

0 comments on commit b084678

Please sign in to comment.