From 281a23a217b1d03131d2a78ef65e1894d2860e2d Mon Sep 17 00:00:00 2001 From: John Davis Date: Sun, 14 May 2023 01:36:39 -0400 Subject: [PATCH 1/6] Add automated naming convention for db constraints --- lib/galaxy/model/__init__.py | 18 +++++++++++++++++- lib/galaxy/model/migrations/util.py | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 78c7d0a6f597..5d9f570cd196 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -69,6 +69,7 @@ inspect, Integer, join, + MetaData, not_, Numeric, or_, @@ -215,6 +216,20 @@ class _HasTable: _HasTable = object +# Naming convention applied to database constraints and indexes. +# All except "ix" are conventions used by PostgreSQL by default. +# We keep the "ix" template consistent with historical Galaxy usage. +# +# NOTE: If editing, also update model.migrations.utils.DbObjectNames. +NAMING_CONVENTION = { + "pk": "%(table_name)s_pkey", + "fk": "%(table_name)s_%(column_0_name)s_fkey", + "uq": "%(table_name)s_%(column_0_name)s_key", + "ck": "%(table_name)s_%(column_0_name)s_check", + "ix": "ix_%(table_name)s_%(column_0_name)s", +} + + def get_uuid(uuid: Optional[Union[UUID, str]] = None) -> UUID: if isinstance(uuid, UUID): return uuid @@ -225,8 +240,9 @@ def get_uuid(uuid: Optional[Union[UUID, str]] = None) -> UUID: class Base(_HasTable, metaclass=DeclarativeMeta): __abstract__ = True + metadata = MetaData(naming_convention=NAMING_CONVENTION) + mapper_registry.metadata = metadata registry = mapper_registry - metadata = mapper_registry.metadata __init__ = mapper_registry.constructor @classmethod diff --git a/lib/galaxy/model/migrations/util.py b/lib/galaxy/model/migrations/util.py index da15b720ed52..267f3c45ea81 100644 --- a/lib/galaxy/model/migrations/util.py +++ b/lib/galaxy/model/migrations/util.py @@ -450,3 +450,26 @@ def transaction(): except OperationalError: op.execute("ROLLBACK") raise + + +class DbObjectNames: + """ + Helper methods for generating names for database constraints and indexes. + This format is based on the naming convention specified in the galaxy.model module. + """ + + @staticmethod + def foreign_key(table_name, column_name): + return f"{table_name}_{column_name}_fkey" + + @staticmethod + def unique_constraint(table_name, column_name): + return f"{table_name}_{column_name}_key" + + @staticmethod + def check_constraint(table_name, column_name): + return f"{table_name}_{column_name}_check" + + @staticmethod + def index(table_name, column_name): + return f"ix_{table_name}_{column_name}" From 450f31cb795a8e59ff37d432aa4de158efba6136 Mon Sep 17 00:00:00 2001 From: John Davis Date: Sun, 14 May 2023 02:07:09 -0400 Subject: [PATCH 2/6] Use model's metadata in alembic (adds naming convention) --- lib/galaxy/model/migrations/alembic/env.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/migrations/alembic/env.py b/lib/galaxy/model/migrations/alembic/env.py index 7634448338e7..5c3ec11f8298 100644 --- a/lib/galaxy/model/migrations/alembic/env.py +++ b/lib/galaxy/model/migrations/alembic/env.py @@ -11,6 +11,7 @@ from alembic.script.base import Script from sqlalchemy import create_engine +from galaxy.model import Base from galaxy.model.migrations import ( GXY, ModelId, @@ -18,7 +19,7 @@ ) config = context.config -target_metadata = None # Not implemented: used for autogenerate, which we don't use here. +target_metadata = Base.metadata log = logging.getLogger(__name__) From c76a18dd695c1634dfe86df1a9d82ca613b08efc Mon Sep 17 00:00:00 2001 From: John Davis Date: Sun, 14 May 2023 19:22:04 -0400 Subject: [PATCH 3/6] Use index name helpers for db objects in revisions --- ...dd_index_wf_r_s_s__workflow_invocation_.py | 7 ++++--- ...dd_index_wf_r_i_p__workflow_invocation_.py | 7 ++++--- .../d0583094c8cd_add_quota_source_labels.py | 19 +++++++++++-------- ...bb173ee6_add_column_deleted_to_api_keys.py | 4 +++- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py index 3ee69a43c746..cdc873a55b12 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py @@ -7,6 +7,7 @@ """ from galaxy.model.migrations.util import ( create_index, + DbObjectNames, drop_index, ) @@ -17,12 +18,12 @@ depends_on = None table_name = "workflow_request_step_states" -columns = ["workflow_invocation_id"] -index_name = "ix_workflow_request_step_states_workflow_invocation_id" +column_name = "workflow_invocation_id" +index_name = DbObjectNames.index(table_name, column_name) def upgrade(): - create_index(index_name, table_name, columns) + create_index(index_name, table_name, [column_name]) def downgrade(): diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py index 8932fd5fd88f..ff12065c2bb4 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py @@ -7,6 +7,7 @@ """ from galaxy.model.migrations.util import ( create_index, + DbObjectNames, drop_index, ) @@ -18,12 +19,12 @@ table_name = "workflow_request_input_parameters" -columns = ["workflow_invocation_id"] -index_name = "ix_workflow_request_input_parameters_workflow_invocation_id" +column_name = "workflow_invocation_id" +index_name = DbObjectNames.index(table_name, column_name) def upgrade(): - create_index(index_name, table_name, columns) + create_index(index_name, table_name, [column_name]) def downgrade(): 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 368953517d7f..900137db088a 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 @@ -18,6 +18,7 @@ create_index, create_table, create_unique_constraint, + DbObjectNames, drop_column, drop_constraint, drop_index, @@ -31,6 +32,10 @@ branch_labels = None depends_on = None +old_index_name = DbObjectNames.index("default_quota_association", "type") +new_index_name = DbObjectNames.index("quota", "quota_source_label") +unique_constraint_name = "uqsu_unique_label_per_user" # leave unchanged + def upgrade(): with transaction(): @@ -43,17 +48,15 @@ def upgrade(): # user had an index on disk_usage - does that make any sense? -John Column("disk_usage", Numeric(15, 0)), ) - create_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"]) + create_unique_constraint(unique_constraint_name, "user_quota_source_usage", ["user_id", "quota_source_label"]) + drop_index(old_index_name, "default_quota_association") + create_index(new_index_name, "quota", ["quota_source_label"]) def downgrade(): with transaction(): - drop_index("ix_quota_quota_source_label", "quota") - create_index("ix_default_quota_association_type", "default_quota_association", ["type"], unique=True) - drop_constraint("uqsu_unique_label_per_user", "user_quota_source_usage") + drop_index(new_index_name, "quota") + create_index(old_index_name, "default_quota_association", ["type"], unique=True) + drop_constraint(unique_constraint_name, "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 f7282e94172c..3463993fd089 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 @@ -12,6 +12,7 @@ from galaxy.model.migrations.util import ( add_column, + DbObjectNames, drop_column, drop_index, transaction, @@ -27,6 +28,7 @@ # database object names used in this revision table_name = "api_keys" column_name = "deleted" +index_name = DbObjectNames.index(table_name, column_name) def upgrade(): @@ -35,5 +37,5 @@ def upgrade(): def downgrade(): with transaction(): - drop_index("ix_api_keys_deleted", table_name) + drop_index(index_name, table_name) drop_column(table_name, column_name) From 8812ba7191e9b4170b43217b8b7d277e9883ab5a Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 15 May 2023 10:14:36 -0400 Subject: [PATCH 4/6] Move db object naming code into separate module --- lib/galaxy/model/__init__.py | 15 +-------- lib/galaxy/model/database_object_names.py | 31 +++++++++++++++++++ ...dd_index_wf_r_s_s__workflow_invocation_.py | 4 +-- ...dd_index_wf_r_i_p__workflow_invocation_.py | 4 +-- .../d0583094c8cd_add_quota_source_labels.py | 6 ++-- ...bb173ee6_add_column_deleted_to_api_keys.py | 4 +-- lib/galaxy/model/migrations/util.py | 23 -------------- 7 files changed, 41 insertions(+), 46 deletions(-) create mode 100644 lib/galaxy/model/database_object_names.py diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 5d9f570cd196..f0f51c306c8a 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -123,6 +123,7 @@ TrimmedString, UUIDType, ) +from galaxy.model.database_object_names import NAMING_CONVENTION from galaxy.model.item_attrs import ( get_item_annotation_str, UsesAnnotations, @@ -216,20 +217,6 @@ class _HasTable: _HasTable = object -# Naming convention applied to database constraints and indexes. -# All except "ix" are conventions used by PostgreSQL by default. -# We keep the "ix" template consistent with historical Galaxy usage. -# -# NOTE: If editing, also update model.migrations.utils.DbObjectNames. -NAMING_CONVENTION = { - "pk": "%(table_name)s_pkey", - "fk": "%(table_name)s_%(column_0_name)s_fkey", - "uq": "%(table_name)s_%(column_0_name)s_key", - "ck": "%(table_name)s_%(column_0_name)s_check", - "ix": "ix_%(table_name)s_%(column_0_name)s", -} - - def get_uuid(uuid: Optional[Union[UUID, str]] = None) -> UUID: if isinstance(uuid, UUID): return uuid diff --git a/lib/galaxy/model/database_object_names.py b/lib/galaxy/model/database_object_names.py new file mode 100644 index 000000000000..d5ada8e32cf9 --- /dev/null +++ b/lib/galaxy/model/database_object_names.py @@ -0,0 +1,31 @@ +""" +Naming convention and helper functions for generating names of database +constraints and indexes. +""" + +# Naming convention applied to database constraints and indexes. +# All except "ix" are conventions used by PostgreSQL by default. +# We keep the "ix" template consistent with historical Galaxy usage. +NAMING_CONVENTION = { + "pk": "%(table_name)s_pkey", + "fk": "%(table_name)s_%(column_0_name)s_fkey", + "uq": "%(table_name)s_%(column_0_name)s_key", + "ck": "%(table_name)s_%(column_0_name)s_check", + "ix": "ix_%(table_name)s_%(column_0_name)s", +} + + +def foreign_key(table_name, column_name): + return f"{table_name}_{column_name}_fkey" + + +def unique_constraint(table_name, column_name): + return f"{table_name}_{column_name}_key" + + +def check_constraint(table_name, column_name): + return f"{table_name}_{column_name}_check" + + +def index(table_name, column_name): + return f"ix_{table_name}_{column_name}" diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py index cdc873a55b12..6bde8fb0b89c 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py @@ -5,9 +5,9 @@ Create Date: 2023-03-07 15:06:55.682273 """ +from galaxy.model.database_object_names import index from galaxy.model.migrations.util import ( create_index, - DbObjectNames, drop_index, ) @@ -19,7 +19,7 @@ table_name = "workflow_request_step_states" column_name = "workflow_invocation_id" -index_name = DbObjectNames.index(table_name, column_name) +index_name = index(table_name, column_name) def upgrade(): diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py index ff12065c2bb4..e2d0570d56c0 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py @@ -5,9 +5,9 @@ Create Date: 2023-03-07 15:10:44.943542 """ +from galaxy.model.database_object_names import index from galaxy.model.migrations.util import ( create_index, - DbObjectNames, drop_index, ) @@ -20,7 +20,7 @@ table_name = "workflow_request_input_parameters" column_name = "workflow_invocation_id" -index_name = DbObjectNames.index(table_name, column_name) +index_name = index(table_name, column_name) def upgrade(): 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 900137db088a..f708f3813c03 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 @@ -13,12 +13,12 @@ String, ) +from galaxy.model.database_object_names import index from galaxy.model.migrations.util import ( add_column, create_index, create_table, create_unique_constraint, - DbObjectNames, drop_column, drop_constraint, drop_index, @@ -32,8 +32,8 @@ branch_labels = None depends_on = None -old_index_name = DbObjectNames.index("default_quota_association", "type") -new_index_name = DbObjectNames.index("quota", "quota_source_label") +old_index_name = index("default_quota_association", "type") +new_index_name = index("quota", "quota_source_label") unique_constraint_name = "uqsu_unique_label_per_user" # leave unchanged 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 3463993fd089..44e2157fd87a 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 @@ -10,9 +10,9 @@ Column, ) +from galaxy.model.database_object_names import index from galaxy.model.migrations.util import ( add_column, - DbObjectNames, drop_column, drop_index, transaction, @@ -28,7 +28,7 @@ # database object names used in this revision table_name = "api_keys" column_name = "deleted" -index_name = DbObjectNames.index(table_name, column_name) +index_name = index(table_name, column_name) def upgrade(): diff --git a/lib/galaxy/model/migrations/util.py b/lib/galaxy/model/migrations/util.py index 267f3c45ea81..da15b720ed52 100644 --- a/lib/galaxy/model/migrations/util.py +++ b/lib/galaxy/model/migrations/util.py @@ -450,26 +450,3 @@ def transaction(): except OperationalError: op.execute("ROLLBACK") raise - - -class DbObjectNames: - """ - Helper methods for generating names for database constraints and indexes. - This format is based on the naming convention specified in the galaxy.model module. - """ - - @staticmethod - def foreign_key(table_name, column_name): - return f"{table_name}_{column_name}_fkey" - - @staticmethod - def unique_constraint(table_name, column_name): - return f"{table_name}_{column_name}_key" - - @staticmethod - def check_constraint(table_name, column_name): - return f"{table_name}_{column_name}_check" - - @staticmethod - def index(table_name, column_name): - return f"ix_{table_name}_{column_name}" From 22218b580681d1f4d024d95ed8226c98cdb7b146 Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 15 May 2023 10:53:32 -0400 Subject: [PATCH 5/6] Allow for composite indexes and constraints; add tests --- lib/galaxy/model/database_object_names.py | 27 ++++++++++++---- .../data/model/test_database_object_names.py | 32 +++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 test/unit/data/model/test_database_object_names.py diff --git a/lib/galaxy/model/database_object_names.py b/lib/galaxy/model/database_object_names.py index d5ada8e32cf9..339976f6dfa0 100644 --- a/lib/galaxy/model/database_object_names.py +++ b/lib/galaxy/model/database_object_names.py @@ -2,6 +2,12 @@ Naming convention and helper functions for generating names of database constraints and indexes. """ +from typing import ( + List, + Union, +) + +from galaxy.util import listify # Naming convention applied to database constraints and indexes. # All except "ix" are conventions used by PostgreSQL by default. @@ -15,17 +21,24 @@ } -def foreign_key(table_name, column_name): - return f"{table_name}_{column_name}_fkey" +def foreign_key(table_name: str, column_names: Union[str, List]) -> str: + columns = _as_str(column_names) + return f"{table_name}_{columns}_fkey" -def unique_constraint(table_name, column_name): - return f"{table_name}_{column_name}_key" +def unique_constraint(table_name: str, column_names: Union[str, List]) -> str: + columns = _as_str(column_names) + return f"{table_name}_{columns}_key" -def check_constraint(table_name, column_name): +def check_constraint(table_name: str, column_name: str) -> str: return f"{table_name}_{column_name}_check" -def index(table_name, column_name): - return f"ix_{table_name}_{column_name}" +def index(table_name: str, column_names: Union[str, List]) -> str: + columns = _as_str(column_names) + return f"ix_{table_name}_{columns}" + + +def _as_str(column_names: Union[str, List]) -> str: + return "_".join(listify(column_names)) diff --git a/test/unit/data/model/test_database_object_names.py b/test/unit/data/model/test_database_object_names.py new file mode 100644 index 000000000000..e27893cb5cf8 --- /dev/null +++ b/test/unit/data/model/test_database_object_names.py @@ -0,0 +1,32 @@ +import galaxy.model.database_object_names as names + + +def test_foreign_key_single_column(): + assert names.foreign_key("foo", "bar_id") == "foo_bar_id_fkey" + + +def test_foreign_key_composite(): + assert names.foreign_key("foo", ["bar_id", "buz_id"]) == "foo_bar_id_buz_id_fkey" + assert names.foreign_key("foo", ["bar_id", "buz_id", "bam_id"]) == "foo_bar_id_buz_id_bam_id_fkey" + + +def test_unique_constraint_single_column(): + assert names.unique_constraint("foo", "bar") == "foo_bar_key" + + +def test_unique_constraint_composite(): + assert names.unique_constraint("foo", ["bar", "buz"]) == "foo_bar_buz_key" + assert names.unique_constraint("foo", ["bar", "buz", "bam"]) == "foo_bar_buz_bam_key" + + +def test_check_constraint(): + assert names.check_constraint("foo", "bar") == "foo_bar_check" + + +def test_index_single_column(): + assert names.index("foo", "bar") == "ix_foo_bar" + + +def test_index_composite(): + assert names.index("foo", ["bar", "buz"]) == "ix_foo_bar_buz" + assert names.index("foo", ["bar", "buz", "bam"]) == "ix_foo_bar_buz_bam" From f5320695175ebc9a0929b3c208407d9fec94d4ae Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 15 May 2023 13:33:06 -0400 Subject: [PATCH 6/6] Rename helper functions --- lib/galaxy/model/database_object_names.py | 8 +++--- ...dd_index_wf_r_s_s__workflow_invocation_.py | 4 +-- ...dd_index_wf_r_i_p__workflow_invocation_.py | 4 +-- .../d0583094c8cd_add_quota_source_labels.py | 6 ++--- ...bb173ee6_add_column_deleted_to_api_keys.py | 4 +-- .../data/model/test_database_object_names.py | 27 +++++++++++-------- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/lib/galaxy/model/database_object_names.py b/lib/galaxy/model/database_object_names.py index 339976f6dfa0..802f40c65e12 100644 --- a/lib/galaxy/model/database_object_names.py +++ b/lib/galaxy/model/database_object_names.py @@ -21,21 +21,21 @@ } -def foreign_key(table_name: str, column_names: Union[str, List]) -> str: +def build_foreign_key_name(table_name: str, column_names: Union[str, List]) -> str: columns = _as_str(column_names) return f"{table_name}_{columns}_fkey" -def unique_constraint(table_name: str, column_names: Union[str, List]) -> str: +def build_unique_constraint_name(table_name: str, column_names: Union[str, List]) -> str: columns = _as_str(column_names) return f"{table_name}_{columns}_key" -def check_constraint(table_name: str, column_name: str) -> str: +def build_check_constraint_name(table_name: str, column_name: str) -> str: return f"{table_name}_{column_name}_check" -def index(table_name: str, column_names: Union[str, List]) -> str: +def build_index_name(table_name: str, column_names: Union[str, List]) -> str: columns = _as_str(column_names) return f"ix_{table_name}_{columns}" diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py index 6bde8fb0b89c..60805a2b7b5e 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/3a2914d703ca_add_index_wf_r_s_s__workflow_invocation_.py @@ -5,7 +5,7 @@ Create Date: 2023-03-07 15:06:55.682273 """ -from galaxy.model.database_object_names import index +from galaxy.model.database_object_names import build_index_name from galaxy.model.migrations.util import ( create_index, drop_index, @@ -19,7 +19,7 @@ table_name = "workflow_request_step_states" column_name = "workflow_invocation_id" -index_name = index(table_name, column_name) +index_name = build_index_name(table_name, column_name) def upgrade(): diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py b/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py index e2d0570d56c0..2081ba2c183c 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/caa7742f7bca_add_index_wf_r_i_p__workflow_invocation_.py @@ -5,7 +5,7 @@ Create Date: 2023-03-07 15:10:44.943542 """ -from galaxy.model.database_object_names import index +from galaxy.model.database_object_names import build_index_name from galaxy.model.migrations.util import ( create_index, drop_index, @@ -20,7 +20,7 @@ table_name = "workflow_request_input_parameters" column_name = "workflow_invocation_id" -index_name = index(table_name, column_name) +index_name = build_index_name(table_name, column_name) def upgrade(): 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 f708f3813c03..d7099bd36cdd 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 @@ -13,7 +13,7 @@ String, ) -from galaxy.model.database_object_names import index +from galaxy.model.database_object_names import build_index_name from galaxy.model.migrations.util import ( add_column, create_index, @@ -32,8 +32,8 @@ branch_labels = None depends_on = None -old_index_name = index("default_quota_association", "type") -new_index_name = index("quota", "quota_source_label") +old_index_name = build_index_name("default_quota_association", "type") +new_index_name = build_index_name("quota", "quota_source_label") unique_constraint_name = "uqsu_unique_label_per_user" # leave unchanged 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 44e2157fd87a..4cba2792fe43 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 @@ -10,7 +10,7 @@ Column, ) -from galaxy.model.database_object_names import index +from galaxy.model.database_object_names import build_index_name from galaxy.model.migrations.util import ( add_column, drop_column, @@ -28,7 +28,7 @@ # database object names used in this revision table_name = "api_keys" column_name = "deleted" -index_name = index(table_name, column_name) +index_name = build_index_name(table_name, column_name) def upgrade(): diff --git a/test/unit/data/model/test_database_object_names.py b/test/unit/data/model/test_database_object_names.py index e27893cb5cf8..e0ff6788264e 100644 --- a/test/unit/data/model/test_database_object_names.py +++ b/test/unit/data/model/test_database_object_names.py @@ -1,32 +1,37 @@ -import galaxy.model.database_object_names as names +from galaxy.model.database_object_names import ( + build_check_constraint_name, + build_foreign_key_name, + build_index_name, + build_unique_constraint_name, +) def test_foreign_key_single_column(): - assert names.foreign_key("foo", "bar_id") == "foo_bar_id_fkey" + assert build_foreign_key_name("foo", "bar_id") == "foo_bar_id_fkey" def test_foreign_key_composite(): - assert names.foreign_key("foo", ["bar_id", "buz_id"]) == "foo_bar_id_buz_id_fkey" - assert names.foreign_key("foo", ["bar_id", "buz_id", "bam_id"]) == "foo_bar_id_buz_id_bam_id_fkey" + assert build_foreign_key_name("foo", ["bar_id", "buz_id"]) == "foo_bar_id_buz_id_fkey" + assert build_foreign_key_name("foo", ["bar_id", "buz_id", "bam_id"]) == "foo_bar_id_buz_id_bam_id_fkey" def test_unique_constraint_single_column(): - assert names.unique_constraint("foo", "bar") == "foo_bar_key" + assert build_unique_constraint_name("foo", "bar") == "foo_bar_key" def test_unique_constraint_composite(): - assert names.unique_constraint("foo", ["bar", "buz"]) == "foo_bar_buz_key" - assert names.unique_constraint("foo", ["bar", "buz", "bam"]) == "foo_bar_buz_bam_key" + assert build_unique_constraint_name("foo", ["bar", "buz"]) == "foo_bar_buz_key" + assert build_unique_constraint_name("foo", ["bar", "buz", "bam"]) == "foo_bar_buz_bam_key" def test_check_constraint(): - assert names.check_constraint("foo", "bar") == "foo_bar_check" + assert build_check_constraint_name("foo", "bar") == "foo_bar_check" def test_index_single_column(): - assert names.index("foo", "bar") == "ix_foo_bar" + assert build_index_name("foo", "bar") == "ix_foo_bar" def test_index_composite(): - assert names.index("foo", ["bar", "buz"]) == "ix_foo_bar_buz" - assert names.index("foo", ["bar", "buz", "bam"]) == "ix_foo_bar_buz_bam" + assert build_index_name("foo", ["bar", "buz"]) == "ix_foo_bar_buz" + assert build_index_name("foo", ["bar", "buz", "bam"]) == "ix_foo_bar_buz_bam"