Skeleton contracts / contracts (pull_request) Blocked by required conditions
30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
"""Add durable staging and asynchronous attachment job state."""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "005_async_attachments"
|
|
down_revision = "004_attachments"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
op.add_column("attachments", sa.Column("staging_key", sa.String(128), nullable=True))
|
|
op.add_column("attachments", sa.Column("job_id", sa.String(36), nullable=True))
|
|
op.add_column("attachments", sa.Column("error_code", sa.String(64), nullable=True))
|
|
op.add_column("attachments", sa.Column("variants", sa.JSON(), nullable=False, server_default="[]"))
|
|
op.execute("UPDATE attachments SET staging_key = object_key, job_id = id")
|
|
op.alter_column("attachments", "staging_key", nullable=False)
|
|
op.alter_column("attachments", "job_id", nullable=False)
|
|
op.create_unique_constraint("uq_attachments_staging_key", "attachments", ["staging_key"])
|
|
op.create_unique_constraint("uq_attachments_job_id", "attachments", ["job_id"])
|
|
|
|
|
|
def downgrade():
|
|
op.drop_constraint("uq_attachments_job_id", "attachments", type_="unique")
|
|
op.drop_constraint("uq_attachments_staging_key", "attachments", type_="unique")
|
|
op.drop_column("attachments", "variants")
|
|
op.drop_column("attachments", "error_code")
|
|
op.drop_column("attachments", "job_id")
|
|
op.drop_column("attachments", "staging_key")
|