forked from mtusi2026/mtusi2026lab4
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
"""add attachment uploads
|
|
|
|
Revision ID: a7c2e91d5f40
|
|
Revises: 4d9a1f2c7b10
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = "a7c2e91d5f40"
|
|
down_revision: Union[str, None] = "4d9a1f2c7b10"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"attachment_uploads",
|
|
sa.Column("id", sa.UUID(), nullable=False),
|
|
sa.Column("chat_id", sa.UUID(), nullable=False),
|
|
sa.Column("owner_id", sa.UUID(), nullable=False),
|
|
sa.Column("filename", sa.String(length=255), nullable=False),
|
|
sa.Column("content_type", sa.String(length=32), nullable=False),
|
|
sa.Column("expected_size_bytes", sa.Integer(), nullable=False),
|
|
sa.Column("expected_sha256", sa.String(length=64), nullable=False),
|
|
sa.Column("object_key", sa.String(length=512), nullable=False),
|
|
sa.Column("status", sa.String(length=16), nullable=False),
|
|
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
|
sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.ForeignKeyConstraint(
|
|
["chat_id"],
|
|
["chats.id"],
|
|
ondelete="CASCADE",
|
|
),
|
|
sa.ForeignKeyConstraint(
|
|
["owner_id"],
|
|
["users.id"],
|
|
ondelete="CASCADE",
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("object_key"),
|
|
)
|
|
|
|
op.create_index(
|
|
"ix_attachment_uploads_chat_id",
|
|
"attachment_uploads",
|
|
["chat_id"],
|
|
)
|
|
op.create_index(
|
|
"ix_attachment_uploads_owner_id",
|
|
"attachment_uploads",
|
|
["owner_id"],
|
|
)
|
|
op.create_index(
|
|
"ix_attachment_uploads_expires_at",
|
|
"attachment_uploads",
|
|
["expires_at"],
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(
|
|
"ix_attachment_uploads_expires_at",
|
|
table_name="attachment_uploads",
|
|
)
|
|
op.drop_index(
|
|
"ix_attachment_uploads_owner_id",
|
|
table_name="attachment_uploads",
|
|
)
|
|
op.drop_index(
|
|
"ix_attachment_uploads_chat_id",
|
|
table_name="attachment_uploads",
|
|
)
|
|
op.drop_table("attachment_uploads") |