Files
yunke/yunke-server/migrations/versions/e5f6a7b8c9d0_message_media_hash.py
T

36 lines
1.1 KiB
Python
Raw Normal View History

"""message media_hash
Revision ID: e5f6a7b8c9d0
Revises: c4d5e6f7a8b9
Create Date: 2026-08-11 00:00:00.000000
"""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = 'e5f6a7b8c9d0'
down_revision: str | Sequence[str] | None = 'c4d5e6f7a8b9'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
"""Upgrade schema."""
# sha256 media_hash of the localized media blob (FK -> Media.media_hash).
# NULL until sync_message_images downloads it. batch_alter_table keeps
# this portable across SQLite (dev/test, table-recreate) and MySQL (prod,
# direct ALTER). Mirrors the voice_clip.media_hash + phone_call.record_media_hash
# migrations.
with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.add_column(sa.Column('media_hash', sa.String(length=64), nullable=True))
def downgrade() -> None:
"""Downgrade schema."""
with op.batch_alter_table('message', schema=None) as batch_op:
batch_op.drop_column('media_hash')