fix(reporters): use better wording in the header in the default reporter
Also show the number of skipped migrations
This commit is contained in:
parent
cbc35bd646
commit
98adcda37e
2 changed files with 34 additions and 12 deletions
5
.changeset/smart-ducks-cheer.md
Normal file
5
.changeset/smart-ducks-cheer.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@emigrate/cli': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Use better wording in the header in the console output from the default reporter
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { black, blueBright, bold, cyan, dim, faint, gray, green, red, redBright, yellow } from 'ansis';
|
import { black, blueBright, bold, cyan, dim, faint, gray, green, red, redBright, yellow, yellowBright } from 'ansis';
|
||||||
import logUpdate from 'log-update';
|
import logUpdate from 'log-update';
|
||||||
import elegantSpinner from 'elegant-spinner';
|
import elegantSpinner from 'elegant-spinner';
|
||||||
import figures from 'figures';
|
import figures from 'figures';
|
||||||
|
|
@ -232,26 +232,43 @@ const getHeaderMessage = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (migrations.length === 0) {
|
if (migrations.length === 0) {
|
||||||
return ' No pending migrations found';
|
return ' No migrations found';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const statusText = command === 'list' ? 'migrations are pending' : 'pending migrations to run';
|
||||||
|
|
||||||
if (migrations.length === lockedMigrations.length) {
|
if (migrations.length === lockedMigrations.length) {
|
||||||
return ` ${bold(migrations.length.toString())} ${dim('pending migrations to run')}`;
|
return ` ${bold(migrations.length.toString())} ${dim(statusText)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nonLockedMigrations = migrations.filter(
|
let skippedCount = 0;
|
||||||
(migration) => !lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name),
|
let failedCount = 0;
|
||||||
);
|
let unlockableCount = 0;
|
||||||
const failedMigrations = nonLockedMigrations.filter(
|
|
||||||
(migration) => 'status' in migration && migration.status === 'failed',
|
for (const migration of migrations) {
|
||||||
);
|
const isLocked = lockedMigrations.some((lockedMigration) => lockedMigration.name === migration.name);
|
||||||
const unlockableCount = 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;
|
||||||
|
} else {
|
||||||
|
unlockableCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const parts = [
|
const parts = [
|
||||||
bold(`${lockedMigrations.length} of ${migrations.length}`),
|
bold(`${lockedMigrations.length} of ${migrations.length}`),
|
||||||
dim`pending migrations to run`,
|
dim(statusText),
|
||||||
unlockableCount > 0 ? yellow(`(${unlockableCount} locked)`) : '',
|
unlockableCount > 0 ? yellow(`(${unlockableCount} locked)`) : '',
|
||||||
failedMigrations.length > 0 ? redBright(`(${failedMigrations.length} failed)`) : '',
|
skippedCount > 0 ? yellowBright(`(${skippedCount} skipped)`) : '',
|
||||||
|
failedCount > 0 ? redBright(`(${failedCount} failed)`) : '',
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
return ` ${parts.join(' ')}`;
|
return ` ${parts.join(' ')}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue