35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""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') |