Skip to content

Commit

Permalink
feat(db): Separate alembic versions into multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
eigerx committed Dec 16, 2024
1 parent 0b37bd4 commit 055eef5
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 68 deletions.
98 changes: 98 additions & 0 deletions alembic/versions/20428abf9581_error_tables_for_v0_4_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""Error tables for v0.4.0
Revision ID: 20428abf9581
Revises: f5e50e000a35
Create Date: 2024-12-13 22:07:55.828266+00:00
"""

from collections.abc import Sequence

import sqlalchemy as sa
from sqlalchemy import MetaData

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "20428abf9581"
down_revision: str | None = "f5e50e000a35"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
# Create table for Pipetask Error Types
op.create_table(
"pipetask_error_type",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"error_source",
sa.Enum(
"cmservice",
"local_script",
"manifest",
name="errorsourceenum",
create_type=False,
metadata=MetaData(),
),
nullable=False,
),
sa.Column(
"error_flavor",
sa.Enum(
"infrastructure",
"configuration",
"pipelines",
name="errorflavorenum",
create_type=False,
metadata=MetaData(),
),
nullable=False,
),
sa.Column(
"error_action",
sa.Enum(
"fail",
"requeue_and_pause",
"rescue",
"auto_retry",
"review",
"accept",
name="erroractionenum",
create_type=False,
metadata=MetaData(),
),
nullable=False,
),
sa.Column("task_name", sa.String(), nullable=False),
sa.Column("diagnostic_message", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("task_name", "diagnostic_message"),
)
# Create table for Pipetask Errors
op.create_table(
"pipetask_error",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("error_type_id", sa.Integer(), nullable=True),
sa.Column("task_id", sa.Integer(), nullable=False),
sa.Column("quanta", sa.String(), nullable=False),
sa.Column("diagnostic_message", sa.String(), nullable=False),
sa.Column("data_id", sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(["error_type_id"], ["pipetask_error_type.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["task_id"], ["task_set.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("quanta"),
)
# Create indices for Pipetask Error Types
op.create_index(
op.f("ix_pipetask_error_error_type_id"), "pipetask_error", ["error_type_id"], unique=False
)
# Create indices for Pipetask Error Tasks
op.create_index(op.f("ix_pipetask_error_task_id"), "pipetask_error", ["task_id"], unique=False)


def downgrade() -> None:
op.drop_index(op.f("ix_pipetask_error_task_id"), table_name="pipetask_error")
op.drop_index(op.f("ix_pipetask_error_error_type_id"), table_name="pipetask_error")
op.drop_table("pipetask_error")
op.drop_table("pipetask_error_type")
68 changes: 0 additions & 68 deletions alembic/versions/f5e50e000a35_autogenerated_from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,6 @@

def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"pipetask_error_type",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"error_source",
sa.Enum(
"cmservice",
"local_script",
"manifest",
name="errorsourceenum",
create_type=False,
metadata=MetaData(),
),
nullable=False,
),
sa.Column(
"error_flavor",
sa.Enum(
"infrastructure",
"configuration",
"pipelines",
name="errorflavorenum",
create_type=False,
metadata=MetaData(),
),
nullable=False,
),
sa.Column(
"error_action",
sa.Enum(
"fail",
"requeue_and_pause",
"rescue",
"auto_retry",
"review",
"accept",
name="erroractionenum",
create_type=False,
metadata=MetaData(),
),
nullable=False,
),
sa.Column("task_name", sa.String(), nullable=False),
sa.Column("diagnostic_message", sa.String(), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("task_name", "diagnostic_message"),
)
op.create_table(
"production",
sa.Column("id", sa.Integer(), nullable=False),
Expand Down Expand Up @@ -421,23 +374,6 @@ def upgrade() -> None:
sa.UniqueConstraint("fullname"),
)
op.create_index(op.f("ix_wms_task_report_job_id"), "wms_task_report", ["job_id"], unique=False)
op.create_table(
"pipetask_error",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("error_type_id", sa.Integer(), nullable=True),
sa.Column("task_id", sa.Integer(), nullable=False),
sa.Column("quanta", sa.String(), nullable=False),
sa.Column("diagnostic_message", sa.String(), nullable=False),
sa.Column("data_id", sa.JSON(), nullable=True),
sa.ForeignKeyConstraint(["error_type_id"], ["pipetask_error_type.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["task_id"], ["task_set.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("quanta"),
)
op.create_index(
op.f("ix_pipetask_error_error_type_id"), "pipetask_error", ["error_type_id"], unique=False
)
op.create_index(op.f("ix_pipetask_error_task_id"), "pipetask_error", ["task_id"], unique=False)
op.create_table(
"product_set",
sa.Column("id", sa.Integer(), nullable=False),
Expand Down Expand Up @@ -551,9 +487,6 @@ def downgrade() -> None:
op.drop_index(op.f("ix_product_set_task_id"), table_name="product_set")
op.drop_index(op.f("ix_product_set_job_id"), table_name="product_set")
op.drop_table("product_set")
op.drop_index(op.f("ix_pipetask_error_task_id"), table_name="pipetask_error")
op.drop_index(op.f("ix_pipetask_error_error_type_id"), table_name="pipetask_error")
op.drop_table("pipetask_error")
op.drop_index(op.f("ix_wms_task_report_job_id"), table_name="wms_task_report")
op.drop_table("wms_task_report")
op.drop_index(op.f("ix_task_set_job_id"), table_name="task_set")
Expand Down Expand Up @@ -593,5 +526,4 @@ def downgrade() -> None:
op.drop_table("script_template")
op.drop_index(op.f("ix_production_name"), table_name="production")
op.drop_table("production")
op.drop_table("pipetask_error_type")
# ### end Alembic commands ###

0 comments on commit 055eef5

Please sign in to comment.