"""document history

Revision ID: 2e79de612153
Revises: 170e05a4f2b6
Create Date: 2022-03-28 06:05:51.545444

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2e79de612153'
down_revision = '170e05a4f2b6'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('cmf_document_history',
    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.Integer(), 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('cache_last_comments', sa.TEXT(), nullable=False),
    sa.Column('is_favorite', sa.Boolean(), 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('cmf_owner_assistant_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.ForeignKeyConstraint(['cmf_import_id'], ['cmf_import.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cmf_document_history_cmf_author_id'), 'cmf_document_history', ['cmf_author_id'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_created_at'), 'cmf_document_history', ['cmf_created_at'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_deleted'), 'cmf_document_history', ['cmf_deleted'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_import_id'), 'cmf_document_history', ['cmf_import_id'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_locked_at'), 'cmf_document_history', ['cmf_locked_at'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_locked_by_id'), 'cmf_document_history', ['cmf_locked_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_modified_at'), 'cmf_document_history', ['cmf_modified_at'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_modified_by_id'), 'cmf_document_history', ['cmf_modified_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_owner_assistant_id'), 'cmf_document_history', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_owner_id'), 'cmf_document_history', ['cmf_owner_id'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_version'), 'cmf_document_history', ['cmf_version'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_cmf_viewed_at'), 'cmf_document_history', ['cmf_viewed_at'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_code'), 'cmf_document_history', ['code'], unique=True)
    op.create_index(op.f('ix_cmf_document_history_name'), 'cmf_document_history', ['name'], unique=False)
    op.create_index(op.f('ix_cmf_document_history_parent_id'), 'cmf_document_history', ['parent_id'], unique=False)
    op.add_column('cmf_document', sa.Column('need_approve', sa.Boolean(), nullable=False, server_default='false'))
    op.drop_index('ix_cmf_document_approved', table_name='cmf_document')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index('ix_cmf_document_approved', 'cmf_document', ['approved'], unique=False)
    op.drop_column('cmf_document', 'need_approve')
    op.drop_index(op.f('ix_cmf_document_history_parent_id'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_name'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_code'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_viewed_at'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_version'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_owner_id'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_owner_assistant_id'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_modified_by_id'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_modified_at'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_locked_by_id'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_locked_at'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_import_id'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_deleted'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_created_at'), table_name='cmf_document_history')
    op.drop_index(op.f('ix_cmf_document_history_cmf_author_id'), table_name='cmf_document_history')
    op.drop_table('cmf_document_history')
    # ### end Alembic commands ###
