Warning
This document is for an old release of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
Source code for galaxy.model.migrate.versions.0165_add_content_update_time
"""
Adds timestamps to hdca table. Adds triggers to dataset, hda, hdca tables
to update history.update_time when contents are changed.
"""
import logging
from sqlalchemy import Column, DateTime, MetaData, Table
from galaxy.model.migrate.versions.util import add_column, drop_column
from galaxy.model.orm.now import now
from galaxy.model.triggers import drop_timestamp_triggers, install_timestamp_triggers
log = logging.getLogger(__name__)
metadata = MetaData()
[docs]def upgrade(migrate_engine):
print(__doc__)
metadata.bind = migrate_engine
metadata.reflect()
create_timestamps(metadata, "history_dataset_collection_association")
install_timestamp_triggers(migrate_engine)
[docs]def downgrade(migrate_engine):
metadata.bind = migrate_engine
metadata.reflect()
drop_timestamp_triggers(migrate_engine)
drop_timestamps(metadata, "history_dataset_collection_association")
[docs]def create_timestamps(metadata, table_name):
target_table = Table(table_name, metadata, autoload=True)
if 'create_time' not in target_table.c:
create_time_column = Column("create_time", DateTime, default=now)
add_column(create_time_column, target_table, metadata)
if 'update_time' not in target_table.c:
update_time_column = Column("update_time", DateTime, default=now, onupdate=now)
add_column(update_time_column, target_table, metadata)
[docs]def drop_timestamps(metadata, table_name):
target_table = Table(table_name, metadata, autoload=True)
drop_column("create_time", target_table)
drop_column("update_time", target_table)