feat(reporter-pino): adapt to the new Reporter interface

This commit is contained in:
Joakim Carlstein 2024-01-26 15:05:43 +01:00 committed by Joakim Carlstein
parent 94ad9feae9
commit 86e0d52e5c
2 changed files with 16 additions and 25 deletions

View file

@ -0,0 +1,5 @@
---
'@emigrate/reporter-pino': minor
---
Adapt to the new Reporter interface, i.e. the removal of the "remove" command related methods

View file

@ -104,27 +104,14 @@ class PinoReporter implements Required<EmigrateReporter> {
); );
} }
onMigrationRemoveStart(migration: MigrationMetadata): Awaitable<void> {
this.#logger.debug({ migration: migration.relativeFilePath }, `Removing migration: ${migration.name}`);
}
onMigrationRemoveSuccess(migration: MigrationMetadataFinished): Awaitable<void> {
this.#logger.info({ migration: migration.relativeFilePath }, `Successfully removed migration: ${migration.name}`);
}
onMigrationRemoveError(migration: MigrationMetadataFinished, error: Error): Awaitable<void> {
this.#logger.error(
{ migration: migration.relativeFilePath, [this.errorKey]: error },
`Failed to remove migration: ${migration.name}`,
);
}
onMigrationStart(migration: MigrationMetadata): Awaitable<void> { onMigrationStart(migration: MigrationMetadata): Awaitable<void> {
this.#logger.info({ migration: migration.relativeFilePath }, `${migration.name} (running)`); const status = this.#command === 'up' ? 'running' : 'removing';
this.#logger.info({ migration: migration.relativeFilePath }, `${migration.name} (${status})`);
} }
onMigrationSuccess(migration: MigrationMetadataFinished): Awaitable<void> { onMigrationSuccess(migration: MigrationMetadataFinished): Awaitable<void> {
this.#logger.info({ migration: migration.relativeFilePath }, `${migration.name} (${migration.status})`); const status = this.#command === 'up' ? 'done' : 'removed';
this.#logger.info({ migration: migration.relativeFilePath }, `${migration.name} (${status})`);
} }
onMigrationError(migration: MigrationMetadataFinished, error: Error): Awaitable<void> { onMigrationError(migration: MigrationMetadataFinished, error: Error): Awaitable<void> {
@ -174,16 +161,15 @@ class PinoReporter implements Required<EmigrateReporter> {
} }
} }
const result =
this.#command === 'remove'
? { removed: done, failed, skipped, pending, total }
: { done, failed, skipped, pending, total };
if (error) { if (error) {
this.#logger.error( this.#logger.error({ result, [this.errorKey]: error }, `Emigrate "${this.#command}" failed`);
{ result: { failed, done, skipped, pending, total }, [this.errorKey]: error },
`Emigrate "${this.#command}" failed`,
);
} else { } else {
this.#logger.info( this.#logger.info({ result }, `Emigrate "${this.#command}" finished successfully`);
{ result: { failed, done, skipped, pending, total } },
`Emigrate "${this.#command}" finished successfully`,
);
} }
} }
} }