further protect, work aroung PG13 missing OR REPLACE for triggers
gitea/wcs/pipeline/head There was a failure building this commit
Details
gitea/wcs/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
2615fcc7bd
commit
4e228fb3ed
10
wcs/sql.py
10
wcs/sql.py
|
@ -100,6 +100,12 @@ def _table_exists(cur, table_name):
|
|||
rows = cur.fetchall()
|
||||
return len(rows) > 0;
|
||||
|
||||
def _trigger_exists(cur, table_name, trigger_name):
|
||||
cur.execute("SELECT 1 FROM pg_trigger WHERE tgrelid = %s::regclass AND tgname = %s;", (table_name, trigger_name))
|
||||
rows = cur.fetchall()
|
||||
return len(rows) > 0;
|
||||
|
||||
|
||||
class WcsPgConnection(psycopg2.extensions.connection):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
@ -1754,12 +1760,12 @@ BEGIN
|
|||
END;
|
||||
$function$;""")
|
||||
|
||||
if _table_exists(cur, 'wcs_all_forms'):
|
||||
if _table_exists(cur, 'wcs_all_forms') and not _trigger_exists(cur, 'wcs_all_forms', 'wcs_all_forms_fts_trg_upd'):
|
||||
# Second part: insert and update triggers for wcs_all_forms
|
||||
cur.execute("CREATE TRIGGER wcs_all_forms_fts_trg_ins AFTER INSERT ON wcs_all_forms FOR EACH ROW WHEN (NEW.fts IS NOT NULL) EXECUTE PROCEDURE wcs_search_tokens_trigger_fn();")
|
||||
cur.execute("CREATE TRIGGER wcs_all_forms_fts_trg_upd AFTER UPDATE OF fts ON wcs_all_forms FOR EACH ROW WHEN (NEW.fts IS NOT NULL) EXECUTE PROCEDURE wcs_search_tokens_trigger_fn();")
|
||||
|
||||
if _table_exists(cur, 'searchable_formdefs'):
|
||||
if _table_exists(cur, 'searchable_formdefs') and not _trigger_exists(cur, 'searchable_formdefs', 'searchable_formdefs_fts_trg_upd'):
|
||||
# Third part: insert and update triggers for searchable_formdefs
|
||||
cur.execute("CREATE TRIGGER searchable_formdefs_fts_trg_ins AFTER INSERT ON searchable_formdefs FOR EACH ROW WHEN (NEW.fts IS NOT NULL) EXECUTE PROCEDURE wcs_search_tokens_trigger_fn();")
|
||||
cur.execute("CREATE TRIGGER searchable_formdefs_fts_trg_upd AFTER UPDATE OF fts ON searchable_formdefs FOR EACH ROW WHEN (NEW.fts IS NOT NULL) EXECUTE PROCEDURE wcs_search_tokens_trigger_fn();")
|
||||
|
|
Loading…
Reference in New Issue