"""media trash Revision ID: c9e2a7f4b1d8 Revises: b6d1f4a82e57 Create Date: 2026-10-14 03:00:00.000000 """ from collections.abc import Sequence from alembic import op revision: str = "c9e2a7f4b1d8" down_revision: str | None = "b6d1f4a82e57" branch_labels: str | Sequence[str] | None = None depends_on: str | Sequence[str] | None = None _TRASH = """ CREATE TABLE media_trash ( storage_key text PRIMARY KEY, account_id integer NOT NULL, chat_id bigint NOT NULL, message_id bigint NOT NULL, kind text NOT NULL, mime text, file_name text NOT NULL, file_size bigint, trashed_at timestamptz NOT NULL DEFAULT now() ) """ def upgrade() -> None: op.execute( "ALTER TABLE media ADD COLUMN evicted_at timestamptz, " "ADD COLUMN evicted_key text" ) op.execute( "CREATE INDEX ix_media_evicted_unique ON media (unique_id) " "WHERE evicted_at IS NOT NULL" ) op.execute( "CREATE INDEX ix_media_evicted_key ON media (evicted_key) " "WHERE evicted_key IS NOT NULL" ) op.execute(_TRASH) op.execute( "CREATE INDEX ix_media_trash_account ON media_trash " "(account_id, trashed_at DESC)" ) def downgrade() -> None: op.execute("DROP TABLE IF EXISTS media_trash") op.execute("DROP INDEX IF EXISTS ix_media_evicted_key") op.execute("DROP INDEX IF EXISTS ix_media_evicted_unique") op.execute("ALTER TABLE media DROP COLUMN evicted_key, DROP COLUMN evicted_at")