"""add smart proxies

Revision ID: 133961a48525
Revises: 31aec2f86c40
Create Date: 2022-05-24 14:56:43.071054

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '133961a48525'
down_revision = '31aec2f86c40'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('smart_proxy',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('added', sa.DateTime(), nullable=False),
    sa.Column('updated', sa.DateTime(), nullable=False),
    sa.Column('deprecated', sa.DateTime(), nullable=True),
    sa.Column('deprecation_reason', sa.String(), nullable=True),
    sa.Column('destroyed', sa.DateTime(), nullable=True),
    sa.Column('group_id', sa.Integer(), nullable=False),
    sa.Column('instance_id', sa.String(length=100), nullable=True),
    sa.Column('provider', sa.String(length=20), nullable=False),
    sa.Column('region', sa.String(length=20), nullable=False),
    sa.ForeignKeyConstraint(['group_id'], ['group.id'], name=op.f('fk_smart_proxy_group_id_group')),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_smart_proxy'))
    )
    with op.batch_alter_table('origin', schema=None) as batch_op:
        batch_op.add_column(sa.Column('smart', sa.Boolean(), nullable=True))
    with op.batch_alter_table('origin', schema=None) as batch_op:
        batch_op.execute("UPDATE origin SET smart=FALSE")
        batch_op.alter_column(sa.Column('smart', sa.Boolean(), nullable=False))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('origin', schema=None) as batch_op:
        batch_op.drop_column('smart')

    op.drop_table('smart_proxy')
    # ### end Alembic commands ###
