diff --git a/lib/galaxy/model/migrations/alembic/versions_gxy/7ffd33d5d144_implement_structured_tool_state.py b/lib/galaxy/model/migrations/alembic/versions_gxy/7ffd33d5d144_implement_structured_tool_state.py index fe76f3c199a1..8440377b0f26 100644 --- a/lib/galaxy/model/migrations/alembic/versions_gxy/7ffd33d5d144_implement_structured_tool_state.py +++ b/lib/galaxy/model/migrations/alembic/versions_gxy/7ffd33d5d144_implement_structured_tool_state.py @@ -8,7 +8,6 @@ from sqlalchemy import ( Column, - ForeignKey, Integer, String, ) @@ -16,8 +15,9 @@ from galaxy.model.custom_types import JSONType from galaxy.model.database_object_names import build_index_name from galaxy.model.migrations.util import ( - _is_sqlite, add_column, + create_foreign_key, + create_index, create_table, drop_column, drop_index, @@ -32,6 +32,8 @@ depends_on = None job_table_name = "job" +tool_source_table_name = "tool_source" +tool_request_table_name = "tool_request" request_column_name = "tool_request_id" job_request_index_name = build_index_name(job_table_name, request_column_name) @@ -39,31 +41,56 @@ def upgrade(): with transaction(): create_table( - "tool_source", + tool_source_table_name, Column("id", Integer, primary_key=True), Column("hash", String(255), index=True), Column("source", JSONType), ) create_table( - "tool_request", + tool_request_table_name, Column("id", Integer, primary_key=True), Column("request", JSONType), Column("state", String(32)), Column("state_message", JSONType), - Column("tool_source_id", Integer, ForeignKey("tool_source.id"), index=True), - Column("history_id", Integer, ForeignKey("history.id"), index=True), + Column("tool_source_id", Integer, index=True), + Column("history_id", Integer, index=True), ) - index = not _is_sqlite() + + create_foreign_key( + "foreign_key_tool_source_id", + tool_request_table_name, + tool_source_table_name, + ["tool_source_id"], + ["id"], + ) + + create_foreign_key( + "foreign_key_history_id", + tool_request_table_name, + "history", + ["history_id"], + ["id"], + ) + add_column( job_table_name, - Column(request_column_name, Integer, ForeignKey("tool_request.id"), default=None, index=index), + Column(request_column_name, Integer, default=None), ) + create_foreign_key( + "foreign_key_tool_request_id", + job_table_name, + tool_request_table_name, + ["tool_request_id"], + ["id"], + ) + + create_index(job_request_index_name, job_table_name, [request_column_name]) + def downgrade(): with transaction(): - if not _is_sqlite(): - drop_index(job_request_index_name, job_table_name) + drop_index(job_request_index_name, job_table_name) drop_column(job_table_name, request_column_name) - drop_table("tool_request") - drop_table("tool_source") + drop_table(tool_request_table_name) + drop_table(tool_source_table_name)