"""add staff control settings

Revision ID: a38c9f6ae8ab
Revises: 1b1a300531e2
Create Date: 2021-03-02 13:45:22.905301

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'a38c9f6ae8ab'
down_revision = '1b1a300531e2'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('cmf_staff_control_settings',
    sa.Column('check_browser_open_at', sa.TEXT(), nullable=False),
    sa.Column('check_deadline_owner_at', sa.Time(), nullable=False),
    sa.Column('check_deadline_responsible_at', sa.Time(), nullable=False),
    sa.Column('check_deadline_supervisor_at', sa.Time(), nullable=False),
    sa.Column('cmf_author_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_created_at', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('cmf_deleted', sa.Boolean(), nullable=False),
    sa.Column('cmf_locked_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('cmf_locked_by_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_modified_at', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('cmf_modified_by_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_owner_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_version', sa.Integer(), nullable=True),
    sa.Column('cmf_viewed_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('code', sa.String(length=64), nullable=True),
    sa.Column('enabled', sa.Boolean(), nullable=False),
    sa.Column('id', sa.String(length=64), nullable=False),
    sa.Column('name', sa.String(length=256), nullable=True),
    sa.Column('text', sa.TEXT(), nullable=True),
    sa.Column('work_end_at', sa.Time(), nullable=False),
    sa.Column('work_start_at', sa.Time(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_author_id'), 'cmf_staff_control_settings', ['cmf_author_id'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_created_at'), 'cmf_staff_control_settings', ['cmf_created_at'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_deleted'), 'cmf_staff_control_settings', ['cmf_deleted'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_locked_at'), 'cmf_staff_control_settings', ['cmf_locked_at'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_locked_by_id'), 'cmf_staff_control_settings', ['cmf_locked_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_modified_at'), 'cmf_staff_control_settings', ['cmf_modified_at'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_modified_by_id'), 'cmf_staff_control_settings', ['cmf_modified_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_owner_id'), 'cmf_staff_control_settings', ['cmf_owner_id'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_version'), 'cmf_staff_control_settings', ['cmf_version'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_viewed_at'), 'cmf_staff_control_settings', ['cmf_viewed_at'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_code'), 'cmf_staff_control_settings', ['code'], unique=True)
    op.create_index(op.f('ix_cmf_staff_control_settings_name'), 'cmf_staff_control_settings', ['name'], unique=False)
    op.execute('update cmf_person set no_staff_control = false where no_staff_control is null')
    op.alter_column('cmf_person', 'no_staff_control',
               existing_type=sa.BOOLEAN(),
               nullable=False)
    op.drop_column('cmf_staff_control', 'work_start_at')
    op.drop_column('cmf_staff_control', 'work_end_at')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('cmf_staff_control', sa.Column('work_end_at', postgresql.TIME(), autoincrement=False, nullable=True))
    op.add_column('cmf_staff_control', sa.Column('work_start_at', postgresql.TIME(), autoincrement=False, nullable=True))
    op.alter_column('cmf_person', 'no_staff_control',
               existing_type=sa.BOOLEAN(),
               nullable=True)
    op.drop_index(op.f('ix_cmf_staff_control_settings_name'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_code'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_viewed_at'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_version'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_owner_id'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_modified_by_id'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_modified_at'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_locked_by_id'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_locked_at'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_deleted'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_created_at'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_author_id'), table_name='cmf_staff_control_settings')
    op.drop_table('cmf_staff_control_settings')
    # ### end Alembic commands ###
