diff --git a/.changeset/thick-days-look.md b/.changeset/thick-days-look.md new file mode 100644 index 0000000..4cea0e8 --- /dev/null +++ b/.changeset/thick-days-look.md @@ -0,0 +1,6 @@ +--- +'@emigrate/reporter-pino': patch +'@emigrate/cli': patch +--- + +Show number of skipped migrations correctly in the command output diff --git a/packages/cli/src/migration-runner.ts b/packages/cli/src/migration-runner.ts index 1aeea3f..645bea2 100644 --- a/packages/cli/src/migration-runner.ts +++ b/packages/cli/src/migration-runner.ts @@ -50,7 +50,6 @@ export const migrationRunner = async true, }: MigrationRunnerParameters): Promise => { - const collectedMigrations: Array = []; const validatedMigrations: Array = []; const migrationsToLock: MigrationMetadata[] = []; @@ -93,8 +92,6 @@ export const migrationRunner = async lockedMigration.name === migration.name); @@ -284,8 +283,6 @@ const getHeaderMessage = ( failedCount += 1; } else if (migration.status === 'skipped') { skippedCount += 1; - } else { - unlockableCount += 1; } } } @@ -293,7 +290,6 @@ const getHeaderMessage = ( const parts = [ bold(`${lockedMigrations.length} of ${migrations.length}`), dim(statusText), - unlockableCount > 0 ? yellow(`(${unlockableCount} locked)`) : '', skippedCount > 0 ? yellowBright(`(${skippedCount} skipped)`) : '', failedCount > 0 ? redBright(`(${failedCount} failed)`) : '', ].filter(Boolean); diff --git a/packages/reporter-pino/src/index.ts b/packages/reporter-pino/src/index.ts index a6c519c..1e2a141 100644 --- a/packages/reporter-pino/src/index.ts +++ b/packages/reporter-pino/src/index.ts @@ -69,29 +69,40 @@ class PinoReporter implements Required { const migrations = this.#migrations ?? []; if (migrations.length === 0) { - this.#logger.info('No pending migrations found'); + this.#logger.info('No migrations found'); return; } + const statusText = this.#command === 'list' ? 'migrations are pending' : 'pending migrations to run'; + if (migrations.length === lockedMigrations.length) { - this.#logger.info( - { migrationCount: lockedMigrations.length }, - `${lockedMigrations.length} pending migrations to run`, - ); + this.#logger.info({ migrationCount: lockedMigrations.length }, `${lockedMigrations.length} ${statusText}`); return; } - const nonLockedMigrations = migrations.filter( - (migration) => !lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name), - ); - const failedMigrations = nonLockedMigrations.filter( - (migration) => 'status' in migration && migration.status === 'failed', - ); - const unlockableCount = this.#command === 'up' ? nonLockedMigrations.length - failedMigrations.length : 0; + let skippedCount = 0; + let failedCount = 0; + + for (const migration of migrations) { + const isLocked = lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name); + + if (isLocked) { + continue; + } + + if ('status' in migration) { + if (migration.status === 'failed') { + failedCount += 1; + } else if (migration.status === 'skipped') { + skippedCount += 1; + } + } + } + const parts = [ - `${lockedMigrations.length} of ${migrations.length} pending migrations to run`, - unlockableCount > 0 ? `(${unlockableCount} locked)` : '', - failedMigrations.length > 0 ? `(${failedMigrations.length} failed)` : '', + `${lockedMigrations.length} of ${migrations.length} ${statusText}`, + skippedCount > 0 ? `(${skippedCount} skipped)` : '', + failedCount > 0 ? `(${failedCount} failed)` : '', ].filter(Boolean); this.#logger.info({ migrationCount: lockedMigrations.length }, parts.join(' '));