"""Added rulesets

Revision ID: 709085f65102
Revises: 892f53ea8054
Create Date: 2021-04-04 23:50:25.845214

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '709085f65102'
down_revision = '892f53ea8054'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'ruleset',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_ruleset_id'), 'ruleset', ['id'], unique=False)
    op.create_index(op.f('ix_ruleset_name'), 'ruleset', ['name'], unique=False)

    with op.batch_alter_table('rule') as bo:
        bo.add_column(sa.Column('ruleset_id', sa.Integer(), nullable=True))
        bo.create_foreign_key('rule_ruleset_fk', 'ruleset', ['ruleset_id'], ['id'])
    #op.create_foreign_key(None, 'rule', 'ruleset', ['ruleset_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('rule') as bo:
        bo.drop_constraint('rule_ruleset_fk', type_='foreignkey')
        bo.drop_column('ruleset_id')
    #op.drop_constraint(None, 'rule', type_='foreignkey')
    #op.drop_column('rule', 'ruleset_id')
    op.drop_index(op.f('ix_ruleset_name'), table_name='ruleset')
    op.drop_index(op.f('ix_ruleset_id'), table_name='ruleset')
    op.drop_table('ruleset')
    # ### end Alembic commands ###
