Skip to content

Commit

Permalink
Add order type application table (#3844) (minor)
Browse files Browse the repository at this point in the history
### Added

- OrderTypeApplication table
  • Loading branch information
islean authored Oct 16, 2024
1 parent f7be20e commit e2e2008
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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")
14 changes: 14 additions & 0 deletions cg/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import Enum
from typing import Annotated

import sqlalchemy
from sqlalchemy import (
BLOB,
DECIMAL,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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")

0 comments on commit e2e2008

Please sign in to comment.