From 781c479898991555fbf312e61d7bae4ac0a9a689 Mon Sep 17 00:00:00 2001 From: MaximeMRF Date: Wed, 3 Apr 2024 17:02:15 +0800 Subject: [PATCH] fix(migrator): step option --- src/migration/runner.ts | 5 +++-- test/migrations/migrator.spec.ts | 11 +++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/migration/runner.ts b/src/migration/runner.ts index 8337ecb1..b4f7ac7d 100644 --- a/src/migration/runner.ts +++ b/src/migration/runner.ts @@ -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 } @@ -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) } diff --git a/test/migrations/migrator.spec.ts b/test/migrations/migrator.spec.ts index 4530f57e..b981b2f9 100644 --- a/test/migrations/migrator.spec.ts +++ b/test/migrations/migrator.spec.ts @@ -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: [], }, ])