"""project now active entity

Revision ID: 0b2108b7e06f
Revises: a2e6fb267caf
Create Date: 2021-04-05 15:34:32.177777

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0b2108b7e06f'
down_revision = 'a2e6fb267caf'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('cmf_project', sa.Column('alarm_date', sa.TIMESTAMP(timezone=True), nullable=True))
    op.add_column('cmf_project', sa.Column('cache_status_opt_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_project', sa.Column('cache_status_type', sa.String(length=32), nullable=True))
    op.add_column('cmf_project', sa.Column('company_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_project', sa.Column('deadline', sa.TIMESTAMP(timezone=True), nullable=True))
    op.add_column('cmf_project', sa.Column('is_penalty', sa.Boolean(), nullable=True))
    op.add_column('cmf_project', sa.Column('mark', sa.String(length=32), nullable=True))
    op.add_column('cmf_project', sa.Column('no_control', sa.Boolean(), nullable=True))
    op.add_column('cmf_project', sa.Column('period_clone_from_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_project', sa.Column('period_interval', sa.String(length=32), nullable=True))
    op.add_column('cmf_project', sa.Column('period_next_date', sa.TIMESTAMP(timezone=True), nullable=True))
    op.add_column('cmf_project', sa.Column('plan_end_date', sa.TIMESTAMP(timezone=True), nullable=True))
    op.add_column('cmf_project', sa.Column('plan_start_date', sa.TIMESTAMP(timezone=True), nullable=True))

    op.add_column('cmf_project', sa.Column('priority', sa.String(length=32), nullable=True))
    op.execute('update cmf_project set priority = 0 where priority is null')
    op.alter_column('cmf_project', 'priority', nullable=False)

    op.add_column('cmf_project', sa.Column('responsible_id', sa.String(length=64), nullable=True))

    op.add_column('cmf_project', sa.Column('status_id', sa.String(length=64), nullable=True))
    op.execute("update cmf_project set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_project', 'status_id', nullable=False)


    op.add_column('cmf_project', sa.Column('status_modified_at', sa.TIMESTAMP(timezone=True), nullable=True))
    op.add_column('cmf_project', sa.Column('time_estimate', sa.Integer(), nullable=True))
    op.add_column('cmf_project', sa.Column('tree_parent_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_project', sa.Column('waiting_for_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_project_alarm_date'), 'cmf_project', ['alarm_date'], unique=False)
    op.create_index(op.f('ix_cmf_project_cache_status_opt_id'), 'cmf_project', ['cache_status_opt_id'], unique=False)
    op.create_index(op.f('ix_cmf_project_cache_status_type'), 'cmf_project', ['cache_status_type'], unique=False)
    op.create_index(op.f('ix_cmf_project_company_id'), 'cmf_project', ['company_id'], unique=False)
    op.create_index(op.f('ix_cmf_project_period_clone_from_id'), 'cmf_project', ['period_clone_from_id'], unique=False)
    op.create_index(op.f('ix_cmf_project_responsible_id'), 'cmf_project', ['responsible_id'], unique=False)
    op.create_index(op.f('ix_cmf_project_status_id'), 'cmf_project', ['status_id'], unique=False)
    op.create_index(op.f('ix_cmf_project_tree_parent_id'), 'cmf_project', ['tree_parent_id'], unique=False)
    op.create_index(op.f('ix_cmf_project_waiting_for_id'), 'cmf_project', ['waiting_for_id'], unique=False)
    op.create_foreign_key(None, 'cmf_project', 'cmf_status_opt', ['cache_status_opt_id'], ['id'])
    op.create_foreign_key(None, 'cmf_project', 'cmf_company', ['company_id'], ['id'])
    op.create_foreign_key(None, 'cmf_project', 'cmf_status', ['status_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'cmf_project', type_='foreignkey')
    op.drop_constraint(None, 'cmf_project', type_='foreignkey')
    op.drop_constraint(None, 'cmf_project', type_='foreignkey')
    op.drop_index(op.f('ix_cmf_project_waiting_for_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_tree_parent_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_status_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_responsible_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_period_clone_from_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_company_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_cache_status_type'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_cache_status_opt_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_alarm_date'), table_name='cmf_project')
    op.drop_column('cmf_project', 'waiting_for_id')
    op.drop_column('cmf_project', 'tree_parent_id')
    op.drop_column('cmf_project', 'time_estimate')
    op.drop_column('cmf_project', 'status_modified_at')
    op.drop_column('cmf_project', 'status_id')
    op.drop_column('cmf_project', 'responsible_id')
    op.drop_column('cmf_project', 'priority')
    op.drop_column('cmf_project', 'plan_start_date')
    op.drop_column('cmf_project', 'plan_end_date')
    op.drop_column('cmf_project', 'period_next_date')
    op.drop_column('cmf_project', 'period_interval')
    op.drop_column('cmf_project', 'period_clone_from_id')
    op.drop_column('cmf_project', 'no_control')
    op.drop_column('cmf_project', 'mark')
    op.drop_column('cmf_project', 'is_penalty')
    op.drop_column('cmf_project', 'deadline')
    op.drop_column('cmf_project', 'company_id')
    op.drop_column('cmf_project', 'cache_status_type')
    op.drop_column('cmf_project', 'cache_status_opt_id')
    op.drop_column('cmf_project', 'alarm_date')
    # ### end Alembic commands ###
