Add migration to re-add the triggers

Make sure that any BEFORE/AFTER trigger is removed.
This commit is contained in:
Nicola Soranzo
2021-04-15 12:09:21 +01:00
parent a414444a59
commit ef03871a74
2 changed files with 34 additions and 3 deletions
@@ -0,0 +1,28 @@
"""
Re-add triggers to update history.update_time when contents are changed.
"""
import logging
from sqlalchemy import MetaData
from galaxy.model.triggers import (
drop_timestamp_triggers,
install_timestamp_triggers,
)
log = logging.getLogger(__name__)
metadata = MetaData()
def upgrade(migrate_engine):
print(__doc__)
metadata.bind = migrate_engine
metadata.reflect()
install_timestamp_triggers(migrate_engine)
def downgrade(migrate_engine):
metadata.bind = migrate_engine
metadata.reflect()
drop_timestamp_triggers(migrate_engine)
+6 -3
View File
@@ -71,7 +71,9 @@ def get_timestamp_install_sql(variant):
def get_timestamp_drop_sql(variant):
"""generate a list of statements to drop the timestammp update triggers"""
"""
Generate a list of statements to drop the timestamp update triggers
"""
sql = []
@@ -79,8 +81,9 @@ def get_timestamp_drop_sql(variant):
sql.append("DROP FUNCTION IF EXISTS update_history_update_time() CASCADE;")
else:
for operation in ['INSERT', 'UPDATE', 'DELETE']:
sql.append(build_drop_trigger(operation, 'history_dataset_association'))
sql.append(build_drop_trigger(operation, 'history_dataset_collection_association'))
for when in ['BEFORE', 'AFTER']:
sql.append(build_drop_trigger(operation, 'history_dataset_association', when))
sql.append(build_drop_trigger(operation, 'history_dataset_collection_association', when))
return sql