From e2e20082ace17bcf3629d79448585b85e69dc699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20Ohlsson=20=C3=85ngnell?= <40887124+islean@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:10:00 +0200 Subject: [PATCH] Add order type application table (#3844) (minor) ### Added - OrderTypeApplication table --- ...d246255_add_ordertype_application_table.py | 61 +++++++++++++++++++ cg/store/models.py | 14 +++++ 2 files changed, 75 insertions(+) create mode 100644 alembic/versions/2024_10_14_fd7c9d246255_add_ordertype_application_table.py diff --git a/alembic/versions/2024_10_14_fd7c9d246255_add_ordertype_application_table.py b/alembic/versions/2024_10_14_fd7c9d246255_add_ordertype_application_table.py new file mode 100644 index 0000000000..a9f2fa2e2e --- /dev/null +++ b/alembic/versions/2024_10_14_fd7c9d246255_add_ordertype_application_table.py @@ -0,0 +1,61 @@ +"""Add ordertype application table + +Revision ID: fd7c9d246255 +Revises: 3b165ec34791 +Create Date: 2024-10-14 15:29:29.062523 + +""" + +from enum import Enum + +import sqlalchemy as sa + +from alembic import op +from cg.constants import Workflow + +# revision identifiers, used by Alembic. +revision = "fd7c9d246255" +down_revision = "3b165ec34791" +branch_labels = None +depends_on = None + + +class OrderTypes(Enum): + BALSAMIC: str = "balsamic" + BALSAMIC_QC: str = "balsamic-qc" + BALSAMIC_UMI: str = "balsamic-umi" + FASTQ: str = "fastq" + FLUFFY: str = "fluffy" + METAGENOME: str = "metagenome" + MICROBIAL_FASTQ: str = "microbial-fastq" + MICROSALT: str = "microsalt" + MIP_DNA: str = "mip-dna" + MIP_RNA: str = "mip-rna" + PACBIO_LONG_READ = "pacbio-long-read" + RML: str = "rml" + RNAFUSION: str = "rnafusion" + SARS_COV_2: str = "sars-cov-2" + TAXPROFILER: str = "taxprofiler" + TOMTE: str = "tomte" + + +order_type_column = sa.Column("order_type", sa.Enum(OrderTypes), index=True, nullable=False) +application_column = sa.Column( + "application_id", + sa.Integer(), + sa.ForeignKey("application.id", ondelete="CASCADE"), + nullable=False, +) + + +def upgrade(): + op.create_table( + "order_type_application", + order_type_column, + application_column, + sa.PrimaryKeyConstraint("order_type", "application_id"), + ) + + +def downgrade(): + op.drop_table(table_name="order_type_application") diff --git a/cg/store/models.py b/cg/store/models.py index f1aea748cd..0f462e7ab6 100644 --- a/cg/store/models.py +++ b/cg/store/models.py @@ -3,6 +3,7 @@ from enum import Enum from typing import Annotated +import sqlalchemy from sqlalchemy import ( BLOB, DECIMAL, @@ -32,6 +33,7 @@ from cg.constants.devices import DeviceType from cg.constants.priority import SlurmQos from cg.constants.symbols import EMPTY_STRING +from cg.models.orders.constants import OrderType BigInt = Annotated[int, None] Blob = Annotated[bytes, None] @@ -1189,3 +1191,15 @@ class PacbioSampleSequencingMetrics(SampleRunMetrics): polymerase_mean_read_length: Mapped[BigInt | None] __mapper_args__ = {"polymorphic_identity": DeviceType.PACBIO} + + +class OrderTypeApplication(Base): + """Maps an order type to its allowed applications""" + + __tablename__ = "order_type_application" + + order_type: Mapped[OrderType] = mapped_column(sqlalchemy.Enum(OrderType), primary_key=True) + application_id: Mapped[int] = mapped_column( + ForeignKey("application.id", ondelete="CASCADE"), primary_key=True + ) + application: Mapped[Application] = orm.relationship("Application")