Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fruity-guests-take.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"graphile-migrate": patch
---

Fix a bug when commit fails: restore the original migration fully (don't drop
`Message` header)
14 changes: 14 additions & 0 deletions __tests__/commit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function _commit(
logDbError(parsedSettings, e);

parsedSettings.logger.error("ABORTING...");
await writeCurrentMigration(parsedSettings, currentLocation, body);
await writeCurrentMigration(parsedSettings, currentLocation, contents);
await fsp.unlink(newMigrationFilepath);
parsedSettings.logger.error("ABORTED AND ROLLED BACK");
throw e;
Expand Down
Loading