"""Notify Scheme Rule

Revision ID: 396f0f92b1f6
Revises: cc6dbbd5bfa7
Create Date: 2023-07-20 15:52:23.203701

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '396f0f92b1f6'
down_revision = 'cc6dbbd5bfa7'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_left_id', table_name='cmf_project_notify_scheme_rule_cmf_project_role')
    op.drop_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_parent_id', table_name='cmf_project_notify_scheme_rule_cmf_project_role')
    op.drop_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_right_id', table_name='cmf_project_notify_scheme_rule_cmf_project_role')
    op.drop_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_root_id', table_name='cmf_project_notify_scheme_rule_cmf_project_role')
    op.drop_table('cmf_project_notify_scheme_rule_cmf_project_role')
    op.add_column('cmf_event_type', sa.Column('perm_security_level_allowed_ids_cache', sa.TEXT(), nullable=True))
    op.add_column('cmf_person_notify_opt', sa.Column('perm_security_level_allowed_ids_cache', sa.TEXT(), nullable=True))
    op.add_column('cmf_project_notify_scheme', sa.Column('perm_security_level_allowed_ids_cache', sa.TEXT(), nullable=True))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('perm_security_level_allowed_ids_cache', sa.TEXT(), nullable=True))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_custom_field', sa.TEXT(), nullable=True))
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_current_user')
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_responsible')
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_project_owner')
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_spectators')
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_owner')
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_author')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_author', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_owner', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_spectators', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_project_owner', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_responsible', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('notify_current_user', sa.BOOLEAN(), autoincrement=False, nullable=False))
    op.drop_column('cmf_project_notify_scheme_rule', 'notify_custom_field')
    op.drop_column('cmf_project_notify_scheme_rule', 'perm_security_level_allowed_ids_cache')
    op.drop_column('cmf_project_notify_scheme', 'perm_security_level_allowed_ids_cache')
    op.drop_column('cmf_person_notify_opt', 'perm_security_level_allowed_ids_cache')
    op.drop_column('cmf_event_type', 'perm_security_level_allowed_ids_cache')
    op.create_table('cmf_project_notify_scheme_rule_cmf_project_role',
    sa.Column('id', sa.VARCHAR(length=128), autoincrement=False, nullable=False),
    sa.Column('parent_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True),
    sa.Column('root_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True),
    sa.Column('description', sa.VARCHAR(length=4096), autoincrement=False, nullable=True),
    sa.Column('left_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True),
    sa.Column('right_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True),
    sa.Column('left_name_cache', sa.VARCHAR(length=256), autoincrement=False, nullable=True),
    sa.Column('right_name_cache', sa.VARCHAR(length=256), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['left_id'], ['cmf_project_notify_scheme_rule.id'], name='cmf_project_notify_scheme_rule_cmf_project_role_left_id_fkey'),
    sa.ForeignKeyConstraint(['right_id'], ['cmf_project_role.id'], name='cmf_project_notify_scheme_rule_cmf_project_role_right_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='cmf_project_notify_scheme_rule_cmf_project_role_pkey')
    )
    op.create_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_root_id', 'cmf_project_notify_scheme_rule_cmf_project_role', ['root_id'], unique=False)
    op.create_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_right_id', 'cmf_project_notify_scheme_rule_cmf_project_role', ['right_id'], unique=False)
    op.create_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_parent_id', 'cmf_project_notify_scheme_rule_cmf_project_role', ['parent_id'], unique=False)
    op.create_index('ix_cmf_project_notify_scheme_rule_cmf_project_role_left_id', 'cmf_project_notify_scheme_rule_cmf_project_role', ['left_id'], unique=False)
    # ### end Alembic commands ###
