From 2f32a4566aa44f2521c9492ec8858a9e01b1b96a Mon Sep 17 00:00:00 2001 From: Sean Li Date: Thu, 15 Oct 2026 00:09:10 +0800 Subject: [PATCH 1/4] fix: restore current migration headers on failed commit --- __tests__/commit.test.ts | 14 ++++++++++++++ src/commands/commit.ts | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/__tests__/commit.test.ts b/__tests__/commit.test.ts index 5bf2321..3eb11dd 100644 --- a/__tests__/commit.test.ts +++ b/__tests__/commit.test.ts @@ -29,6 +29,20 @@ it("aborts if current.sql is empty", async () => { ); }); +it("restores migration headers after a failed commit", async () => { + const original = "--! Message: test-migration\n\nselect 1 + ;\n"; + mockFs({ + "migrations/current.sql": original, + }); + + await expect(commit(settings)).rejects.toThrow(); + + expect(await fsp.readFile("migrations/current.sql", "utf8")).toEqual( + original, + ); + expect(await fsp.readdir("migrations/committed")).toEqual([]); +}); + describe.each([[undefined], ["My Commit Message"]])( "commit message '%s'", (commitMessage) => { diff --git a/src/commands/commit.ts b/src/commands/commit.ts index f7a5752..f3771cd 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -119,7 +119,11 @@ export async function _commit( logDbError(parsedSettings, e); parsedSettings.logger.error("ABORTING..."); - await writeCurrentMigration(parsedSettings, currentLocation, body); + await writeCurrentMigration( + parsedSettings, + currentLocation, + serializeMigration(body, headers), + ); await fsp.unlink(newMigrationFilepath); parsedSettings.logger.error("ABORTED AND ROLLED BACK"); throw e; From c59c70e478cb6f4447213a33c4aff77d2fb23f14 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 14 Oct 2026 17:27:56 +0100 Subject: [PATCH 2/4] Match style in uncommit --- src/commands/commit.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/commands/commit.ts b/src/commands/commit.ts index f3771cd..7c464c5 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -119,11 +119,8 @@ export async function _commit( logDbError(parsedSettings, e); parsedSettings.logger.error("ABORTING..."); - await writeCurrentMigration( - parsedSettings, - currentLocation, - serializeMigration(body, headers), - ); + const completeBody = serializeMigration(body, headers); + await writeCurrentMigration(parsedSettings, currentLocation, completeBody); await fsp.unlink(newMigrationFilepath); parsedSettings.logger.error("ABORTED AND ROLLED BACK"); throw e; From 790ce19111998dc25f352fbe771872c6be62c277 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 14 Oct 2026 17:29:15 +0100 Subject: [PATCH 3/4] Write the original text back again --- src/commands/commit.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 7c464c5..4e98f61 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -119,8 +119,7 @@ export async function _commit( logDbError(parsedSettings, e); parsedSettings.logger.error("ABORTING..."); - const completeBody = serializeMigration(body, headers); - await writeCurrentMigration(parsedSettings, currentLocation, completeBody); + await writeCurrentMigration(parsedSettings, currentLocation, contents); await fsp.unlink(newMigrationFilepath); parsedSettings.logger.error("ABORTED AND ROLLED BACK"); throw e; From 69c7d2dd918fa5acaa73ee701dfeed45afb9015c Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 14 Oct 2026 17:31:00 +0100 Subject: [PATCH 4/4] Add a changeset --- .changeset/fruity-guests-take.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/fruity-guests-take.md diff --git a/.changeset/fruity-guests-take.md b/.changeset/fruity-guests-take.md new file mode 100644 index 0000000..cd2a121 --- /dev/null +++ b/.changeset/fruity-guests-take.md @@ -0,0 +1,6 @@ +--- +"graphile-migrate": patch +--- + +Fix a bug when commit fails: restore the original migration fully (don't drop +`Message` header)