Skip to content

Commit

Permalink
fix Error deleting orphaned triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Oct 1, 2024
1 parent 958ffc5 commit 177820c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/PubSubManager/PubSubManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class PubSubManager {

await this.db.tx(t => t.any(`
BEGIN WORK;
/* ${ PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID} */
/* ${PubSubManager.EXCLUDE_QUERY_FROM_SCHEMA_WATCH_ID} */
/* why is this lock level needed? */
--LOCK TABLE prostgles.app_triggers IN ACCESS EXCLUSIVE MODE;
Expand Down
19 changes: 13 additions & 6 deletions lib/PubSubManager/notifListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,19 @@ export async function notifListener(this: PubSubManager, data: { payload: string
const orphanedConditions = condition_ids.filter((condId) => typeof tableTriggers.at(condId) !== "string" );
if(orphanedConditions.length){
this.db
.any(" \
DELETE FROM prostgles.app_triggers \
WHERE table_name = $1 \
AND id IN ($2:csv) \
AND app_id = $3 \
",
.any(`
DELETE FROM prostgles.app_triggers at
WHERE EXISTS (
SELECT 1
FROM prostgles.v_triggers t
WHERE t.table_name = $1
AND t.c_id IN ($2:csv)
AND t.app_id = $3
AND at.app_id = t.app_id
AND at.table_name = t.table_name
AND at.condition = t.condition
)
`,
[table_name, orphanedConditions, this.appId]
)
.catch(e => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.119",
"version": "4.2.120",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 177820c

Please sign in to comment.