fix(reporters): show number of skipped migrations correctly in command output
This commit is contained in:
parent
69bd88afdb
commit
ef45be9233
4 changed files with 33 additions and 23 deletions
6
.changeset/thick-days-look.md
Normal file
6
.changeset/thick-days-look.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'@emigrate/reporter-pino': patch
|
||||||
|
'@emigrate/cli': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Show number of skipped migrations correctly in the command output
|
||||||
|
|
@ -50,7 +50,6 @@ export const migrationRunner = async <T extends MigrationMetadata | MigrationMet
|
||||||
onError,
|
onError,
|
||||||
migrationFilter = () => true,
|
migrationFilter = () => true,
|
||||||
}: MigrationRunnerParameters<T>): Promise<Error | undefined> => {
|
}: MigrationRunnerParameters<T>): Promise<Error | undefined> => {
|
||||||
const collectedMigrations: Array<MigrationMetadata | MigrationMetadataFinished> = [];
|
|
||||||
const validatedMigrations: Array<MigrationMetadata | MigrationMetadataFinished> = [];
|
const validatedMigrations: Array<MigrationMetadata | MigrationMetadataFinished> = [];
|
||||||
const migrationsToLock: MigrationMetadata[] = [];
|
const migrationsToLock: MigrationMetadata[] = [];
|
||||||
|
|
||||||
|
|
@ -93,8 +92,6 @@ export const migrationRunner = async <T extends MigrationMetadata | MigrationMet
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
collectedMigrations.push(migration);
|
|
||||||
|
|
||||||
if (isFinishedMigration(migration)) {
|
if (isFinishedMigration(migration)) {
|
||||||
skip ||= migration.status === 'failed' || migration.status === 'skipped';
|
skip ||= migration.status === 'failed' || migration.status === 'skipped';
|
||||||
|
|
||||||
|
|
@ -138,7 +135,7 @@ export const migrationRunner = async <T extends MigrationMetadata | MigrationMet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await reporter.onCollectedMigrations?.(collectedMigrations);
|
await reporter.onCollectedMigrations?.(validatedMigrations);
|
||||||
|
|
||||||
let optionError: Error | undefined;
|
let optionError: Error | undefined;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -270,7 +270,6 @@ const getHeaderMessage = (
|
||||||
|
|
||||||
let skippedCount = 0;
|
let skippedCount = 0;
|
||||||
let failedCount = 0;
|
let failedCount = 0;
|
||||||
let unlockableCount = 0;
|
|
||||||
|
|
||||||
for (const migration of migrations) {
|
for (const migration of migrations) {
|
||||||
const isLocked = lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name);
|
const isLocked = lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name);
|
||||||
|
|
@ -284,8 +283,6 @@ const getHeaderMessage = (
|
||||||
failedCount += 1;
|
failedCount += 1;
|
||||||
} else if (migration.status === 'skipped') {
|
} else if (migration.status === 'skipped') {
|
||||||
skippedCount += 1;
|
skippedCount += 1;
|
||||||
} else {
|
|
||||||
unlockableCount += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -293,7 +290,6 @@ const getHeaderMessage = (
|
||||||
const parts = [
|
const parts = [
|
||||||
bold(`${lockedMigrations.length} of ${migrations.length}`),
|
bold(`${lockedMigrations.length} of ${migrations.length}`),
|
||||||
dim(statusText),
|
dim(statusText),
|
||||||
unlockableCount > 0 ? yellow(`(${unlockableCount} locked)`) : '',
|
|
||||||
skippedCount > 0 ? yellowBright(`(${skippedCount} skipped)`) : '',
|
skippedCount > 0 ? yellowBright(`(${skippedCount} skipped)`) : '',
|
||||||
failedCount > 0 ? redBright(`(${failedCount} failed)`) : '',
|
failedCount > 0 ? redBright(`(${failedCount} failed)`) : '',
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
|
||||||
|
|
@ -69,29 +69,40 @@ class PinoReporter implements Required<EmigrateReporter> {
|
||||||
const migrations = this.#migrations ?? [];
|
const migrations = this.#migrations ?? [];
|
||||||
|
|
||||||
if (migrations.length === 0) {
|
if (migrations.length === 0) {
|
||||||
this.#logger.info('No pending migrations found');
|
this.#logger.info('No migrations found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const statusText = this.#command === 'list' ? 'migrations are pending' : 'pending migrations to run';
|
||||||
|
|
||||||
if (migrations.length === lockedMigrations.length) {
|
if (migrations.length === lockedMigrations.length) {
|
||||||
this.#logger.info(
|
this.#logger.info({ migrationCount: lockedMigrations.length }, `${lockedMigrations.length} ${statusText}`);
|
||||||
{ migrationCount: lockedMigrations.length },
|
|
||||||
`${lockedMigrations.length} pending migrations to run`,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nonLockedMigrations = migrations.filter(
|
let skippedCount = 0;
|
||||||
(migration) => !lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name),
|
let failedCount = 0;
|
||||||
);
|
|
||||||
const failedMigrations = nonLockedMigrations.filter(
|
for (const migration of migrations) {
|
||||||
(migration) => 'status' in migration && migration.status === 'failed',
|
const isLocked = lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name);
|
||||||
);
|
|
||||||
const unlockableCount = this.#command === 'up' ? nonLockedMigrations.length - failedMigrations.length : 0;
|
if (isLocked) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('status' in migration) {
|
||||||
|
if (migration.status === 'failed') {
|
||||||
|
failedCount += 1;
|
||||||
|
} else if (migration.status === 'skipped') {
|
||||||
|
skippedCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const parts = [
|
const parts = [
|
||||||
`${lockedMigrations.length} of ${migrations.length} pending migrations to run`,
|
`${lockedMigrations.length} of ${migrations.length} ${statusText}`,
|
||||||
unlockableCount > 0 ? `(${unlockableCount} locked)` : '',
|
skippedCount > 0 ? `(${skippedCount} skipped)` : '',
|
||||||
failedMigrations.length > 0 ? `(${failedMigrations.length} failed)` : '',
|
failedCount > 0 ? `(${failedCount} failed)` : '',
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
this.#logger.info({ migrationCount: lockedMigrations.length }, parts.join(' '));
|
this.#logger.info({ migrationCount: lockedMigrations.length }, parts.join(' '));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue