"""add_cmf_email_template

Revision ID: 331ecbd7b446
Revises: b6d50da379c6
Create Date: 2024-08-22 14:38:28.945234

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '331ecbd7b446'
down_revision = 'b6d50da379c6'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('cmf_email_template',
    sa.Column('id', sa.String(length=64), nullable=False),
    sa.Column('cmf_locked_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('cmf_created_at', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('cmf_modified_at', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('cmf_viewed_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('cmf_deleted', sa.Boolean(), nullable=False),
    sa.Column('cmf_version', sa.BIGINT(), nullable=True),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('code', sa.String(length=64), nullable=True),
    sa.Column('system', sa.Boolean(), nullable=False),
    sa.Column('text', sa.TEXT(), nullable=True),
    sa.Column('import_original', sa.Boolean(), nullable=False),
    sa.Column('import_raw_json', sa.TEXT(), nullable=True),
    sa.Column('ext_id', sa.String(), nullable=True),
    sa.Column('cmf_archived', sa.Boolean(), nullable=False),
    sa.Column('is_favorite', sa.Boolean(), nullable=False),
    sa.Column('has_tree_nodes', sa.Boolean(), nullable=False),
    sa.Column('tree_node_is_branch', sa.Boolean(), nullable=False),
    sa.Column('tree_hidden', sa.Boolean(), nullable=False),
    sa.Column('orderno', sa.Integer(), nullable=True),
    sa.Column('perm_public', sa.Boolean(), nullable=False),
    sa.Column('perm_has_acl', sa.Boolean(), nullable=False),
    sa.Column('perm_inherit', sa.Boolean(), nullable=False),
    sa.Column('perm_parent_owner_id', sa.String(length=64), nullable=True),
    sa.Column('perm_inherit_acl_id', sa.String(length=64), nullable=True),
    sa.Column('perm_effective_acl_id', sa.String(length=64), nullable=True),
    sa.Column('perm_security_level_allowed_ids_cache', sa.TEXT(), nullable=True),
    sa.Column('perm_encrypt', sa.Boolean(), nullable=False),
    sa.Column('tmplt_subject', sa.String(), nullable=True),
    sa.Column('tmplt_body_html', sa.TEXT(), nullable=True),
    sa.Column('body_сss', sa.TEXT(), nullable=True),
    sa.Column('cmf_author_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_owner_id', sa.String(length=64), nullable=True),
    sa.Column('parent_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_modified_by_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_locked_by_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_import_id', sa.String(length=64), nullable=True),
    sa.Column('tree_parent_id', sa.String(length=64), nullable=True),
    sa.Column('root_parent_id', sa.String(length=64), nullable=True),
    sa.Column('project_id', sa.String(length=64), nullable=True),
    sa.Column('perm_acl_id', sa.String(length=64), nullable=True),
    sa.Column('perm_parent_id', sa.String(length=64), nullable=True),
    sa.ForeignKeyConstraint(['cmf_import_id'], ['cmf_import.id'], ),
    sa.ForeignKeyConstraint(['perm_acl_id'], ['cmf_access_list.id'], ),
    sa.ForeignKeyConstraint(['project_id'], ['cmf_project.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cmf_email_template_cmf_author_id'), 'cmf_email_template', ['cmf_author_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_created_at'), 'cmf_email_template', ['cmf_created_at'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_deleted'), 'cmf_email_template', ['cmf_deleted'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_import_id'), 'cmf_email_template', ['cmf_import_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_locked_at'), 'cmf_email_template', ['cmf_locked_at'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_locked_by_id'), 'cmf_email_template', ['cmf_locked_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_modified_at'), 'cmf_email_template', ['cmf_modified_at'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_modified_by_id'), 'cmf_email_template', ['cmf_modified_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_owner_id'), 'cmf_email_template', ['cmf_owner_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_version'), 'cmf_email_template', ['cmf_version'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_cmf_viewed_at'), 'cmf_email_template', ['cmf_viewed_at'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_code'), 'cmf_email_template', ['code'], unique=True)
    op.create_index(op.f('ix_cmf_email_template_name'), 'cmf_email_template', ['name'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_orderno'), 'cmf_email_template', ['orderno'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_parent_id'), 'cmf_email_template', ['parent_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_perm_acl_id'), 'cmf_email_template', ['perm_acl_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_perm_parent_id'), 'cmf_email_template', ['perm_parent_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_project_id'), 'cmf_email_template', ['project_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_root_parent_id'), 'cmf_email_template', ['root_parent_id'], unique=False)
    op.create_index(op.f('ix_cmf_email_template_tree_parent_id'), 'cmf_email_template', ['tree_parent_id'], unique=False)
    op.add_column('cmf_notify', sa.Column('email_template_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_project_notify_scheme_rule', sa.Column('email_template_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_project_notify_scheme_rule_email_template_id'), 'cmf_project_notify_scheme_rule', ['email_template_id'], unique=False)
    op.create_foreign_key(None, 'cmf_project_notify_scheme_rule', 'cmf_email_template', ['email_template_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'cmf_project_notify_scheme_rule', type_='foreignkey')
    op.drop_index(op.f('ix_cmf_project_notify_scheme_rule_email_template_id'), table_name='cmf_project_notify_scheme_rule')
    op.drop_column('cmf_project_notify_scheme_rule', 'email_template_id')
    op.drop_column('cmf_notify', 'email_template_id')
    op.drop_index(op.f('ix_cmf_email_template_tree_parent_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_root_parent_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_project_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_perm_parent_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_perm_acl_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_parent_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_orderno'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_name'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_code'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_viewed_at'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_version'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_owner_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_modified_by_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_modified_at'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_locked_by_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_locked_at'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_import_id'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_deleted'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_created_at'), table_name='cmf_email_template')
    op.drop_index(op.f('ix_cmf_email_template_cmf_author_id'), table_name='cmf_email_template')
    op.drop_table('cmf_email_template')
    # ### end Alembic commands ###
