Skip to content

Commit

Permalink
fix duplicate triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
kyscott18 committed Jan 7, 2025
1 parent 0a5645c commit 7234384
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/modern-ads-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ponder": patch
---

Fixed a bug causing the error: `trigger "_reorg__xyz" for relation "xyz" already exists`.
21 changes: 21 additions & 0 deletions packages/core/src/database/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,27 @@ test("createTriggers()", async (context) => {
await database.kill();
});

test("createTriggers() duplicate", async (context) => {
const database = createDatabase({
common: context.common,
preBuild: {
databaseConfig: context.databaseConfig,
namespace: "public",
},
schemaBuild: {
schema: { account },
statements: buildSchema({ schema: { account } }).statements,
},
});

await database.setup({ buildId: "abc" });
await database.createTriggers();
await database.createTriggers();

await database.unlock();
await database.kill();
});

test("complete()", async (context) => {
const database = createDatabase({
common: context.common,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ $$ LANGUAGE plpgsql

await sql
.raw(`
CREATE TRIGGER "${tableName.trigger}"
CREATE OR REPLACE TRIGGER "${tableName.trigger}"
AFTER INSERT OR UPDATE OR DELETE ON "${preBuild.namespace}"."${tableName.sql}"
FOR EACH ROW EXECUTE FUNCTION ${tableName.triggerFn};
`)
Expand Down

0 comments on commit 7234384

Please sign in to comment.