microblog/alembic/versions/edea0406b7d0_poll_questions...

50 lines
1.9 KiB
Python

"""Poll/Questions answers handling
Revision ID: edea0406b7d0
Revises: c8cbfccf885d
Create Date: 2022-07-24 09:49:53.669481
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = 'edea0406b7d0'
down_revision = 'c8cbfccf885d'
branch_labels = None
depends_on = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('poll_answer',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('outbox_object_id', sa.Integer(), nullable=False),
sa.Column('poll_type', sa.String(), nullable=False),
sa.Column('inbox_object_id', sa.Integer(), nullable=False),
sa.Column('actor_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.ForeignKeyConstraint(['actor_id'], ['actor.id'], ),
sa.ForeignKeyConstraint(['inbox_object_id'], ['inbox.id'], ),
sa.ForeignKeyConstraint(['outbox_object_id'], ['outbox.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('outbox_object_id', 'name', 'actor_id', name='uix_outbox_object_id_name_actor_id')
)
with op.batch_alter_table('poll_answer', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_poll_answer_id'), ['id'], unique=False)
batch_op.create_index('uix_one_of_outbox_object_id_actor_id', ['outbox_object_id', 'actor_id'], unique=True, sqlite_where=sa.text('poll_type = "oneOf"'))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('poll_answer', schema=None) as batch_op:
batch_op.drop_index('uix_one_of_outbox_object_id_actor_id', sqlite_where=sa.text('poll_type = "oneOf"'))
batch_op.drop_index(batch_op.f('ix_poll_answer_id'))
op.drop_table('poll_answer')
# ### end Alembic commands ###