"""Update

Revision ID: 89a2912d10e3
Revises: 841eba11c02b
Create Date: 2019-06-10 13:30:35.640873

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "89a2912d10e3"
down_revision = "5b172edeaf8d"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "update",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("count", sa.Integer(), nullable=False),
        sa.Column("updated", sa.Boolean(), nullable=False),
        sa.Column("time_window", sa.DateTime(), nullable=False),
        sa.Column("poll_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["poll_id"], ["poll.id"], ondelete="cascade"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint(
            "poll_id", "time_window", name="one_update_per_time_window"
        ),
    )
    op.create_index(op.f("ix_update_poll_id"), "update", ["poll_id"], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_update_poll_id"), table_name="update")
    op.drop_table("update")
    # ### end Alembic commands ###
