Files
mtusi2026lab7/alembic/versions/b0f31212df2c_add_owner_and_sha256_to_attachments.py
T
kirill_dolda 280c5a3300
Skeleton contracts / contracts (pull_request) Blocked by required conditions
ЛР 7: безопасность, mTLS и OpenBao на оценку 3
2026-12-06 15:19:24 +03:00

35 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""add owner and sha256 to attachments
Revision ID: b0f31212df2c
Revises: d78a7aaedac6
Create Date: 2026-11-11 15:39:07.391800
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'b0f31212df2c'
down_revision: Union[str, None] = 'd78a7aaedac6'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# 1. Добавляем user_id с nullable=True, чтобы не упасть на старых данных
op.add_column('attachments', sa.Column('user_id', sa.UUID(), nullable=True))
# 2. Добавляем sha256
op.add_column('attachments', sa.Column('sha256', sa.String(), nullable=True))
# 3. Создаем внешний ключ
op.create_foreign_key(None, 'attachments', 'users', ['user_id'], ['id'], ondelete='CASCADE')
def downgrade() -> None:
op.drop_constraint(None, 'attachments', type_='foreignkey')
op.drop_column('attachments', 'sha256')
op.drop_column('attachments', 'user_id')