Выполнение 4 лабораторной на оценку 3
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Add attachment metadata and message references.
|
||||
|
||||
Revision ID: 004_attachments
|
||||
Revises: 003_message_idempotency
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "004_attachments"
|
||||
down_revision = "003_message_idempotency"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column("messages", sa.Column("attachment_ids", sa.JSON(), nullable=False,
|
||||
server_default=sa.text("'[]'")))
|
||||
op.create_table(
|
||||
"attachments",
|
||||
sa.Column("id", sa.String(), primary_key=True),
|
||||
sa.Column("chat_id", sa.String(), sa.ForeignKey("chats.id"), nullable=False),
|
||||
sa.Column("owner_id", sa.String(), sa.ForeignKey("users.id"), nullable=False),
|
||||
sa.Column("filename", sa.String(255), nullable=False),
|
||||
sa.Column("content_type", sa.String(32), nullable=False),
|
||||
sa.Column("size_bytes", sa.Integer(), nullable=False),
|
||||
sa.Column("sha256", sa.String(64), nullable=False),
|
||||
sa.Column("object_key", sa.String(128), nullable=False, unique=True),
|
||||
sa.Column("status", sa.String(16), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_attachments_chat_id", "attachments", ["chat_id"])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index("ix_attachments_chat_id", table_name="attachments")
|
||||
op.drop_table("attachments")
|
||||
op.drop_column("messages", "attachment_ids")
|
||||
Reference in New Issue
Block a user