Skip to content

Commit

Permalink
Add migration file for asynctasks table.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Mar 14, 2024
1 parent 36462fe commit 734cb8f
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions alembic/versions/20240313_b2353c25a95e_add_asynctasks_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Add asynctasks table
Revision ID: b2353c25a95e
Revises: 9d2dccb0d6ff
Create Date: 2024-03-13 21:48:45.911507+00:00
"""
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision = "b2353c25a95e"
down_revision = "9d2dccb0d6ff"
branch_labels = None
depends_on = None


def upgrade() -> None:
op.create_table(
"asynctasks",
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column("created", sa.DateTime(timezone=True), nullable=False),
sa.Column(
"status",
sa.Enum(
"READY",
"PROCESSING",
"SUCCESS",
"FAILURE",
name="asynctaskstatus",
),
nullable=False,
),
sa.Column(
"task_type",
sa.Enum(
"INVENTORY_REPORT",
name="asynctasktype",
),
nullable=False,
),
sa.Column("processing_start_time", sa.DateTime(timezone=True), nullable=True),
sa.Column("processing_end_time", sa.DateTime(timezone=True), nullable=True),
sa.Column("status_details", sa.Unicode(), nullable=True),
sa.Column("data", postgresql.JSONB(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
op.f("ix_asynctasks_tasktype_status_created"),
"asynctasks",
["task_type", "status", "created"],
unique=False,
)


def downgrade() -> None:
op.drop_index(
op.f("ix_asynctasks_tasktype_status_created"), table_name="asynctasks"
)
op.drop_table("asynctasks")
sa.Enum(name="asynctasktype").drop(op.get_bind(), checkfirst=False)
sa.Enum(name="asynctaskstatus").drop(op.get_bind(), checkfirst=False)

0 comments on commit 734cb8f

Please sign in to comment.