From c2ed5685c13388dc4ba085aaae816b4b7669e8c8 Mon Sep 17 00:00:00 2001 From: John Davis Date: Wed, 12 Apr 2023 15:19:56 -0400 Subject: [PATCH] Apply transaction context manager to select revisions Wrap multiple sql statements in a transaction to ensure per-revision transactional control. --- .../6a67bf27e6a6_deferred_data_tables.py | 11 ++++-- ...9540a051226e_preferred_object_store_ids.py | 21 +++++----- ...04_add_skipped_state_to_collection_job_.py | 16 ++++---- .../d0583094c8cd_add_quota_source_labels.py | 39 +++++++++++-------- ...bb173ee6_add_column_deleted_to_api_keys.py | 6 ++- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/6a67bf27e6a6_deferred_data_tables.py b/lib/galaxy/model/migrations/alembic/versions_gxy/6a67bf27e6a6_deferred_data_tables.py index 1ef9ae7b3b4..4f5a4f0e38f 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/6a67bf27e6a6_deferred_data_tables.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/6a67bf27e6a6_deferred_data_tables.py @@ -13,6 +13,7 @@ from sqlalchemy import ( from galaxy.model.migrations.util import ( add_column, drop_column, + transaction, ) # revision identifiers, used by Alembic. @@ -23,10 +24,12 @@ depends_on = None def upgrade(): - add_column("history_dataset_association", Column("metadata_deferred", Boolean(), default=False)) - add_column("library_dataset_dataset_association", Column("metadata_deferred", Boolean(), default=False)) + with transaction(): + add_column("history_dataset_association", Column("metadata_deferred", Boolean(), default=False)) + add_column("library_dataset_dataset_association", Column("metadata_deferred", Boolean(), default=False)) def downgrade(): - drop_column("history_dataset_association", "metadata_deferred") - drop_column("library_dataset_dataset_association", "metadata_deferred") + with transaction(): + drop_column("history_dataset_association", "metadata_deferred") + drop_column("library_dataset_dataset_association", "metadata_deferred") diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/9540a051226e_preferred_object_store_ids.py b/lib/galaxy/model/migrations/alembic/versions_gxy/9540a051226e_preferred_object_store_ids.py index 47ec17da97c..1656c6dae92 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/9540a051226e_preferred_object_store_ids.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/9540a051226e_preferred_object_store_ids.py @@ -14,6 +14,7 @@ from galaxy.model.custom_types import JSONType from galaxy.model.migrations.util import ( add_column, drop_column, + transaction, ) # revision identifiers, used by Alembic. @@ -24,15 +25,17 @@ depends_on = None def upgrade(): - preferred_object_store_type = String(255) - add_column("galaxy_user", Column("preferred_object_store_id", preferred_object_store_type, default=None)) - add_column("history", Column("preferred_object_store_id", preferred_object_store_type, default=None)) - add_column("job", Column("preferred_object_store_id", preferred_object_store_type, default=None)) - add_column("job", Column("object_store_id_overrides", JSONType)) + with transaction(): + preferred_object_store_type = String(255) + add_column("galaxy_user", Column("preferred_object_store_id", preferred_object_store_type, default=None)) + add_column("history", Column("preferred_object_store_id", preferred_object_store_type, default=None)) + add_column("job", Column("preferred_object_store_id", preferred_object_store_type, default=None)) + add_column("job", Column("object_store_id_overrides", JSONType)) def downgrade(): - drop_column("galaxy_user", "preferred_object_store_id") - drop_column("history", "preferred_object_store_id") - drop_column("job", "preferred_object_store_id") - drop_column("job", "object_store_id_overrides") + with transaction(): + drop_column("galaxy_user", "preferred_object_store_id") + drop_column("history", "preferred_object_store_id") + drop_column("job", "preferred_object_store_id") + drop_column("job", "object_store_id_overrides") diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/c39f1de47a04_add_skipped_state_to_collection_job_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/c39f1de47a04_add_skipped_state_to_collection_job_.py index ff543ae55ff..5cb2555104d 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/c39f1de47a04_add_skipped_state_to_collection_job_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/c39f1de47a04_add_skipped_state_to_collection_job_.py @@ -7,6 +7,8 @@ Create Date: 2023-01-16 11:53:59.783836 """ from alembic import op +from galaxy.model.migrations.util import transaction + # revision identifiers, used by Alembic. revision = "c39f1de47a04" down_revision = "3100452fa030" @@ -88,14 +90,12 @@ GROUP BY jobstates.hdca_id def upgrade(): - op.execute("BEGIN") - op.execute(f"DROP VIEW IF EXISTS {view_name}") - op.execute(f"CREATE VIEW {view_name} AS {new_aggregate_query}") - op.execute("END") + with transaction(): + op.execute(f"DROP VIEW IF EXISTS {view_name}") + op.execute(f"CREATE VIEW {view_name} AS {new_aggregate_query}") def downgrade(): - op.execute("BEGIN") - op.execute(f"DROP VIEW IF EXISTS {view_name}") - op.execute(f"CREATE VIEW {view_name} AS {previous_aggregate_query}") - op.execute("END") + with transaction(): + op.execute(f"DROP VIEW IF EXISTS {view_name}") + op.execute(f"CREATE VIEW {view_name} AS {previous_aggregate_query}") diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/d0583094c8cd_add_quota_source_labels.py b/lib/galaxy/model/migrations/alembic/versions_gxy/d0583094c8cd_add_quota_source_labels.py index e8aa3126d92..4c8ada95549 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/d0583094c8cd_add_quota_source_labels.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/d0583094c8cd_add_quota_source_labels.py @@ -22,6 +22,7 @@ from galaxy.model.migrations.util import ( drop_index, drop_table, drop_unique_constraint, + transaction, ) # revision identifiers, used by Alembic. @@ -32,23 +33,27 @@ depends_on = None def upgrade(): - add_column("quota", Column("quota_source_label", String(32), default=None)) - create_table( - "user_quota_source_usage", - Column("id", Integer, primary_key=True), - Column("user_id", Integer, ForeignKey("galaxy_user.id"), index=True), - Column("quota_source_label", String(32), index=True), - # user had an index on disk_usage - does that make any sense? -John - Column("disk_usage", Numeric(15, 0)), - ) - add_unique_constraint("uqsu_unique_label_per_user", "user_quota_source_usage", ["user_id", "quota_source_label"]) - drop_index("ix_default_quota_association_type", "default_quota_association") - create_index("ix_quota_quota_source_label", "quota", ["quota_source_label"]) + with transaction(): + add_column("quota", Column("quota_source_label", String(32), default=None)) + create_table( + "user_quota_source_usage", + Column("id", Integer, primary_key=True), + Column("user_id", Integer, ForeignKey("galaxy_user.id"), index=True), + Column("quota_source_label", String(32), index=True), + # user had an index on disk_usage - does that make any sense? -John + Column("disk_usage", Numeric(15, 0)), + ) + add_unique_constraint( + "uqsu_unique_label_per_user", "user_quota_source_usage", ["user_id", "quota_source_label"] + ) + drop_index("ix_default_quota_association_type", "default_quota_association") + create_index("ix_quota_quota_source_label", "quota", ["quota_source_label"]) def downgrade(): - drop_index("ix_quota_quota_source_label", "quota") - create_index("ix_default_quota_association_type", "default_quota_association", ["type"], unique=True) - drop_unique_constraint("uqsu_unique_label_per_user", "user_quota_source_usage") - drop_table("user_quota_source_usage") - drop_column("quota", "quota_source_label") + with transaction(): + drop_index("ix_quota_quota_source_label", "quota") + create_index("ix_default_quota_association_type", "default_quota_association", ["type"], unique=True) + drop_unique_constraint("uqsu_unique_label_per_user", "user_quota_source_usage") + drop_table("user_quota_source_usage") + drop_column("quota", "quota_source_label") diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/e0e3bb173ee6_add_column_deleted_to_api_keys.py b/lib/galaxy/model/migrations/alembic/versions_gxy/e0e3bb173ee6_add_column_deleted_to_api_keys.py index c890ba677a1..f7282e94172 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/e0e3bb173ee6_add_column_deleted_to_api_keys.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/e0e3bb173ee6_add_column_deleted_to_api_keys.py @@ -14,6 +14,7 @@ from galaxy.model.migrations.util import ( add_column, drop_column, drop_index, + transaction, ) # revision identifiers, used by Alembic. @@ -33,5 +34,6 @@ def upgrade(): def downgrade(): - drop_index("ix_api_keys_deleted", table_name) - drop_column(table_name, column_name) + with transaction(): + drop_index("ix_api_keys_deleted", table_name) + drop_column(table_name, column_name)