Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix duplicate triggers #1416

Merged
merged 1 commit into from
Jan 7, 2025
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
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
Loading