add msg_id

This commit is contained in:
Nathan Rashleigh committed 2024-04-08 23:20:11 +10:00
1 parent 796e9d2bd8
commit 321e82a71c
2 files changed
+35 -1

No files matched your search

@@ -0,0 +1,34 @@
"""add msg_id column to attachments
Revision ID: 5dfa093e7b2b
Revises: 1dc4564189c1
Create Date: 2024-04-08 23:08:51.542184
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '5dfa093e7b2b'
down_revision: Union[str, None] = '1dc4564189c1'
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.add_column('attachments', sa.Column('msg_id', sa.BigInteger(), nullable=True))
op.execute("UPDATE attachments SET msg_id = (message->>'id')::bigint")
op.alter_column('attachments', 'msg_id', nullable=False)
op.create_index(op.f('ix_attachments_msg_id'), 'attachments', ['msg_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_attachments_msg_id'), table_name='attachments')
op.drop_column('attachments', 'msg_id')
# ### end Alembic commands ###