From 46b9104cda0869f10027fc4a326394266c4fe07b Mon Sep 17 00:00:00 2001 From: Joakim Carlstein Date: Thu, 16 Nov 2023 10:59:54 +0100 Subject: [PATCH] fix(cli): don't run any migrations if any previous migration have failed --- .changeset/clean-balloons-run.md | 5 +++++ packages/cli/src/up-command.ts | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/clean-balloons-run.md diff --git a/.changeset/clean-balloons-run.md b/.changeset/clean-balloons-run.md new file mode 100644 index 0000000..ee9a929 --- /dev/null +++ b/.changeset/clean-balloons-run.md @@ -0,0 +1,5 @@ +--- +'@emigrate/cli': patch +--- + +Don't run any migrations if there's a failed migration in the migration history diff --git a/packages/cli/src/up-command.ts b/packages/cli/src/up-command.ts index 124dcb3..0be6e07 100644 --- a/packages/cli/src/up-command.ts +++ b/packages/cli/src/up-command.ts @@ -35,6 +35,10 @@ export default async function upCommand({ directory, dry, plugins = [] }: Config .map((file) => file.name); for await (const migrationHistoryEntry of storage.getHistory()) { + if (migrationHistoryEntry.status === 'failed') { + throw new Error(`Migration ${migrationHistoryEntry.name} is in a failed state, please fix it first`); + } + if (migrationFiles.includes(migrationHistoryEntry.name)) { migrationFiles.splice(migrationFiles.indexOf(migrationHistoryEntry.name), 1); } @@ -114,6 +118,9 @@ export default async function upCommand({ directory, dry, plugins = [] }: Config throw error; } } + } catch (error) { + console.error(error); + process.exitCode = 1; } finally { await cleanup(); }