|
39 | 39 | operator_match = re.compile('([^:]*):([=><]+)$')
|
40 | 40 |
|
41 | 41 | # use a ddmmyyy timestamp as the version for triggers
|
42 |
| -TRIGGER_VERSION = "23082024" |
| 42 | +TRIGGER_VERSION = "05092024" |
43 | 43 | TRIGGER_NAME_PREFIX = "notify_ui"
|
44 | 44 |
|
45 | 45 |
|
@@ -442,30 +442,31 @@ async def create_trigger_if_missing(db: _AsyncPostgresDB, table_name, trigger_na
|
442 | 442 | cur.close()
|
443 | 443 |
|
444 | 444 | @staticmethod
|
445 |
| - async def cleanup_triggers(db: _AsyncPostgresDB, table_name): |
| 445 | + async def cleanup_triggers(db: _AsyncPostgresDB, table_name, schema=DB_SCHEMA_NAME): |
446 | 446 | "Cleans up old versions of table triggers"
|
447 | 447 | with (await db.pool.cursor()) as cur:
|
448 | 448 | try:
|
449 | 449 | await cur.execute(
|
450 | 450 | """
|
451 |
| - SELECT DISTINCT trigger_name, trigger_schema |
| 451 | + SELECT DISTINCT trigger_name |
452 | 452 | FROM information_schema.triggers
|
453 | 453 | WHERE event_object_table = %s
|
| 454 | + AND trigger_schema = %s |
454 | 455 | """,
|
455 |
| - [table_name] |
| 456 | + [table_name, schema] |
456 | 457 | )
|
457 | 458 | results = await cur.fetchall()
|
458 | 459 |
|
459 | 460 | triggers_to_cleanup = [
|
460 |
| - (res[0], res[1]) for res in results |
| 461 | + res[0] for res in results |
461 | 462 | if res[0].startswith(TRIGGER_NAME_PREFIX) and TRIGGER_VERSION not in res[0]
|
462 | 463 | ]
|
463 | 464 | if triggers_to_cleanup:
|
464 | 465 | logging.getLogger("TriggerSetup").info("Cleaning up old triggers: %s" % triggers_to_cleanup)
|
465 | 466 | commands = []
|
466 |
| - for trigger_name, schema in triggers_to_cleanup: |
| 467 | + for trigger_name in triggers_to_cleanup: |
467 | 468 | commands += [
|
468 |
| - (f"DROP TRIGGER IF EXISTS {trigger_name} ON {table_name}"), |
| 469 | + (f"DROP TRIGGER IF EXISTS {trigger_name} ON {schema}.{table_name}"), |
469 | 470 | (f"DROP FUNCTION IF EXISTS {schema}.{trigger_name}")
|
470 | 471 | ]
|
471 | 472 |
|
|
0 commit comments