forked from mtusi2026/mtusi2026lab4
feat: add migration for attachments tables
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
"""add attachments tables
|
||||||
|
|
||||||
|
Revision ID: 67c68635da78
|
||||||
|
Revises: b7965b0447f4
|
||||||
|
Create Date: 2026-11-11 20:18:53.130479
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '67c68635da78'
|
||||||
|
down_revision: Union[str, None] = 'b7965b0447f4'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('attachments',
|
||||||
|
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=100), nullable=False),
|
||||||
|
sa.Column('size_bytes', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('sha256', sa.String(length=64), nullable=False),
|
||||||
|
sa.Column('status', sa.String(length=20), nullable=False),
|
||||||
|
sa.Column('error_code', sa.String(length=50), nullable=True),
|
||||||
|
sa.Column('s3_key', sa.String(length=500), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['chat_id'], ['chats.id'], ondelete='CASCADE'),
|
||||||
|
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('message_attachments',
|
||||||
|
sa.Column('message_id', sa.UUID(), nullable=False),
|
||||||
|
sa.Column('attachment_id', sa.UUID(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['attachment_id'], ['attachments.id'], ondelete='CASCADE'),
|
||||||
|
sa.ForeignKeyConstraint(['message_id'], ['messages.id'], ondelete='CASCADE'),
|
||||||
|
sa.PrimaryKeyConstraint('message_id', 'attachment_id')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('message_attachments')
|
||||||
|
op.drop_table('attachments')
|
||||||
|
# ### end Alembic commands ###
|
||||||
Reference in New Issue
Block a user