Upload 6d730b286fc4_add_poll_id_to_vote_and_unique_.py
Browse files
app/alembic/versions/6d730b286fc4_add_poll_id_to_vote_and_unique_.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Add poll_id to Vote and unique constraint on voter_email_hash, poll_id
|
| 2 |
+
|
| 3 |
+
Revision ID: 6d730b286fc4
|
| 4 |
+
Revises: 4c9cd9554f1c
|
| 5 |
+
Create Date: 2024-11-08 13:02:45.311091
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from typing import Sequence, Union
|
| 9 |
+
|
| 10 |
+
from alembic import op
|
| 11 |
+
import sqlalchemy as sa
|
| 12 |
+
import sqlmodel
|
| 13 |
+
from sqlalchemy.dialects import postgresql
|
| 14 |
+
|
| 15 |
+
# revision identifiers, used by Alembic.
|
| 16 |
+
revision: str = '6d730b286fc4'
|
| 17 |
+
down_revision: Union[str, None] = '4c9cd9554f1c'
|
| 18 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 19 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def upgrade() -> None:
|
| 23 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 24 |
+
op.alter_column('poll', 'created_at',
|
| 25 |
+
existing_type=postgresql.TIMESTAMP(timezone=True),
|
| 26 |
+
type_=sa.DateTime(),
|
| 27 |
+
existing_nullable=False)
|
| 28 |
+
op.alter_column('poll', 'start_time',
|
| 29 |
+
existing_type=postgresql.TIMESTAMP(timezone=True),
|
| 30 |
+
type_=sa.DateTime(),
|
| 31 |
+
existing_nullable=False)
|
| 32 |
+
op.alter_column('poll', 'end_time',
|
| 33 |
+
existing_type=postgresql.TIMESTAMP(timezone=True),
|
| 34 |
+
type_=sa.DateTime(),
|
| 35 |
+
existing_nullable=False)
|
| 36 |
+
op.add_column('vote', sa.Column('poll_id', sa.Uuid(), nullable=True))
|
| 37 |
+
op.alter_column('vote', 'timestamp',
|
| 38 |
+
existing_type=postgresql.TIMESTAMP(timezone=True),
|
| 39 |
+
type_=sa.DateTime(),
|
| 40 |
+
existing_nullable=False)
|
| 41 |
+
op.create_index(op.f('ix_vote_poll_id'), 'vote', ['poll_id'], unique=False)
|
| 42 |
+
op.create_unique_constraint(None, 'vote', ['voter_email_hash', 'poll_id'])
|
| 43 |
+
op.create_foreign_key(None, 'vote', 'poll', ['poll_id'], ['id'])
|
| 44 |
+
# ### end Alembic commands ###
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def downgrade() -> None:
|
| 48 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 49 |
+
op.drop_constraint(None, 'vote', type_='foreignkey')
|
| 50 |
+
op.drop_constraint(None, 'vote', type_='unique')
|
| 51 |
+
op.drop_index(op.f('ix_vote_poll_id'), table_name='vote')
|
| 52 |
+
op.alter_column('vote', 'timestamp',
|
| 53 |
+
existing_type=sa.DateTime(),
|
| 54 |
+
type_=postgresql.TIMESTAMP(timezone=True),
|
| 55 |
+
existing_nullable=False)
|
| 56 |
+
op.drop_column('vote', 'poll_id')
|
| 57 |
+
op.alter_column('poll', 'end_time',
|
| 58 |
+
existing_type=sa.DateTime(),
|
| 59 |
+
type_=postgresql.TIMESTAMP(timezone=True),
|
| 60 |
+
existing_nullable=False)
|
| 61 |
+
op.alter_column('poll', 'start_time',
|
| 62 |
+
existing_type=sa.DateTime(),
|
| 63 |
+
type_=postgresql.TIMESTAMP(timezone=True),
|
| 64 |
+
existing_nullable=False)
|
| 65 |
+
op.alter_column('poll', 'created_at',
|
| 66 |
+
existing_type=sa.DateTime(),
|
| 67 |
+
type_=postgresql.TIMESTAMP(timezone=True),
|
| 68 |
+
existing_nullable=False)
|
| 69 |
+
# ### end Alembic commands ###
|