"""refactor tasks documents comments

Revision ID: 4716c577aaf2
Revises: 3c7376963215
Create Date: 2021-03-25 09:28:21.917152

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '4716c577aaf2'
down_revision = '3c7376963215'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('cmf_chat_group', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_chat_group_project_id', table_name='cmf_chat_group')
    op.create_index(op.f('ix_cmf_chat_group_parent_id'), 'cmf_chat_group', ['parent_id'], unique=False)
    op.drop_constraint('cmf_u_work_chat_group_project_id_fkey', 'cmf_chat_group', type_='foreignkey')

    op.alter_column('cmf_chat_topic', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_chat_topic_project_id', table_name='cmf_chat_topic')
    op.create_index(op.f('ix_cmf_chat_topic_parent_id'), 'cmf_chat_topic', ['parent_id'], unique=False)
    op.drop_constraint('cmf_u_work_chat_topic_project_id_fkey', 'cmf_chat_topic', type_='foreignkey')

    op.alter_column('cmf_company', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_company_project_id', table_name='cmf_company')
    op.create_index(op.f('ix_cmf_company_parent_id'), 'cmf_company', ['parent_id'], unique=False)
    op.drop_constraint('cmf_company_project_id_fkey', 'cmf_company', type_='foreignkey')

    op.alter_column('cmf_deal', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_deal_project_id', table_name='cmf_deal')
    op.create_index(op.f('ix_cmf_deal_parent_id'), 'cmf_deal', ['parent_id'], unique=False)
    op.drop_constraint('cmf_deal_project_id_fkey', 'cmf_deal', type_='foreignkey')

    op.alter_column('cmf_document', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_document_project_id', table_name='cmf_document')
    op.create_index(op.f('ix_cmf_document_parent_id'), 'cmf_document', ['parent_id'], unique=False)
    op.drop_constraint('cmf_document_project_id_fkey', 'cmf_document', type_='foreignkey')

    op.alter_column('cmf_invoice', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_invoice_project_id', table_name='cmf_invoice')
    op.create_index(op.f('ix_cmf_invoice_parent_id'), 'cmf_invoice', ['parent_id'], unique=False)
    op.drop_constraint('cmf_invoice_project_id_fkey', 'cmf_invoice', type_='foreignkey')

    op.alter_column('cmf_lead', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_lead_project_id', table_name='cmf_lead')
    op.create_index(op.f('ix_cmf_lead_parent_id'), 'cmf_lead', ['parent_id'], unique=False)
    op.drop_constraint('cmf_lead_project_id_fkey', 'cmf_lead', type_='foreignkey')

    op.alter_column('cmf_list', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_list_project_id', table_name='cmf_list')
    op.create_index(op.f('ix_cmf_list_parent_id'), 'cmf_list', ['parent_id'], unique=False)
    op.drop_constraint('cmf_u_work_list_project_id_fkey', 'cmf_list', type_='foreignkey')

    op.alter_column('cmf_mail', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_mail_project_id', table_name='cmf_mail')
    op.create_index(op.f('ix_cmf_mail_parent_id'), 'cmf_mail', ['parent_id'], unique=False)
    op.drop_constraint('cmf_mail_project_id_fkey', 'cmf_mail', type_='foreignkey')

    op.alter_column('cmf_payment', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_payment_project_id', table_name='cmf_payment')
    op.create_index(op.f('ix_cmf_payment_parent_id'), 'cmf_payment', ['parent_id'], unique=False)
    op.drop_constraint('cmf_payment_project_id_fkey', 'cmf_payment', type_='foreignkey')

    op.alter_column('cmf_pipeline', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_pipeline_project_id', table_name='cmf_pipeline')
    op.create_index(op.f('ix_cmf_pipeline_parent_id'), 'cmf_pipeline', ['parent_id'], unique=False)
    op.drop_constraint('cmf_pipeline_project_id_fkey', 'cmf_pipeline', type_='foreignkey')

    op.alter_column('cmf_purchase_order', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_purchase_order_project_id', table_name='cmf_purchase_order')
    op.create_index(op.f('ix_cmf_purchase_order_parent_id'), 'cmf_purchase_order', ['parent_id'], unique=False)
    op.drop_constraint('cmf_purchase_order_project_id_fkey', 'cmf_purchase_order', type_='foreignkey')

    op.alter_column('cmf_purchase_order_items', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_purchase_order_items_project_id', table_name='cmf_purchase_order_items')
    op.create_index(op.f('ix_cmf_purchase_order_items_parent_id'), 'cmf_purchase_order_items', ['parent_id'], unique=False)
    op.drop_constraint('cmf_purchase_order_items_project_id_fkey', 'cmf_purchase_order_items', type_='foreignkey')

    op.alter_column('cmf_sales_order', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_sales_order_project_id', table_name='cmf_sales_order')
    op.create_index(op.f('ix_cmf_sales_order_parent_id'), 'cmf_sales_order', ['parent_id'], unique=False)
    op.drop_constraint('cmf_sales_order_project_id_fkey', 'cmf_sales_order', type_='foreignkey')

    op.alter_column('cmf_stock_move', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_stock_move_project_id', table_name='cmf_stock_move')
    op.create_index(op.f('ix_cmf_stock_move_parent_id'), 'cmf_stock_move', ['parent_id'], unique=False)
    op.drop_constraint('cmf_stock_move_project_id_fkey', 'cmf_stock_move', type_='foreignkey')

    op.alter_column('cmf_stock_move_items', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_stock_move_items_project_id', table_name='cmf_stock_move_items')
    op.create_index(op.f('ix_cmf_stock_move_items_parent_id'), 'cmf_stock_move_items', ['parent_id'], unique=False)
    op.drop_constraint('cmf_stock_move_items_project_id_fkey', 'cmf_stock_move_items', type_='foreignkey')

    op.alter_column('cmf_task', 'project_id', new_column_name="parent_id")
    op.drop_index('ix_cmf_task_project_id', table_name='cmf_task')
    op.create_index(op.f('ix_cmf_task_parent_id'), 'cmf_task', ['parent_id'], unique=False)
    op.drop_constraint('cmf_u_work_task_project_id_fkey', 'cmf_task', type_='foreignkey')

    op.add_column('cmf_u_work_post', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_u_work_post_parent_id'), 'cmf_u_work_post', ['parent_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_cmf_u_work_post_parent_id'), table_name='cmf_u_work_post')
    op.drop_column('cmf_u_work_post', 'parent_id')
    op.add_column('cmf_task', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_u_work_task_project_id_fkey', 'cmf_task', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_task_parent_id'), table_name='cmf_task')
    op.create_index('ix_cmf_task_project_id', 'cmf_task', ['project_id'], unique=False)
    op.drop_column('cmf_task', 'parent_id')
    op.add_column('cmf_stock_move_items', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_stock_move_items_project_id_fkey', 'cmf_stock_move_items', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_stock_move_items_parent_id'), table_name='cmf_stock_move_items')
    op.create_index('ix_cmf_stock_move_items_project_id', 'cmf_stock_move_items', ['project_id'], unique=False)
    op.drop_column('cmf_stock_move_items', 'parent_id')
    op.add_column('cmf_stock_move', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_stock_move_project_id_fkey', 'cmf_stock_move', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_stock_move_parent_id'), table_name='cmf_stock_move')
    op.create_index('ix_cmf_stock_move_project_id', 'cmf_stock_move', ['project_id'], unique=False)
    op.drop_column('cmf_stock_move', 'parent_id')
    op.add_column('cmf_sales_order', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_sales_order_project_id_fkey', 'cmf_sales_order', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_sales_order_parent_id'), table_name='cmf_sales_order')
    op.create_index('ix_cmf_sales_order_project_id', 'cmf_sales_order', ['project_id'], unique=False)
    op.drop_column('cmf_sales_order', 'parent_id')
    op.add_column('cmf_purchase_order_items', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_purchase_order_items_project_id_fkey', 'cmf_purchase_order_items', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_purchase_order_items_parent_id'), table_name='cmf_purchase_order_items')
    op.create_index('ix_cmf_purchase_order_items_project_id', 'cmf_purchase_order_items', ['project_id'], unique=False)
    op.drop_column('cmf_purchase_order_items', 'parent_id')
    op.add_column('cmf_purchase_order', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_purchase_order_project_id_fkey', 'cmf_purchase_order', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_purchase_order_parent_id'), table_name='cmf_purchase_order')
    op.create_index('ix_cmf_purchase_order_project_id', 'cmf_purchase_order', ['project_id'], unique=False)
    op.drop_column('cmf_purchase_order', 'parent_id')
    op.add_column('cmf_pipeline', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_pipeline_project_id_fkey', 'cmf_pipeline', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_pipeline_parent_id'), table_name='cmf_pipeline')
    op.create_index('ix_cmf_pipeline_project_id', 'cmf_pipeline', ['project_id'], unique=False)
    op.drop_column('cmf_pipeline', 'parent_id')
    op.add_column('cmf_payment', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_payment_project_id_fkey', 'cmf_payment', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_payment_parent_id'), table_name='cmf_payment')
    op.create_index('ix_cmf_payment_project_id', 'cmf_payment', ['project_id'], unique=False)
    op.drop_column('cmf_payment', 'parent_id')
    op.add_column('cmf_mail', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_mail_project_id_fkey', 'cmf_mail', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_mail_parent_id'), table_name='cmf_mail')
    op.create_index('ix_cmf_mail_project_id', 'cmf_mail', ['project_id'], unique=False)
    op.drop_column('cmf_mail', 'parent_id')
    op.add_column('cmf_list', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_u_work_list_project_id_fkey', 'cmf_list', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_list_parent_id'), table_name='cmf_list')
    op.create_index('ix_cmf_list_project_id', 'cmf_list', ['project_id'], unique=False)
    op.drop_column('cmf_list', 'parent_id')
    op.add_column('cmf_lead', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_lead_project_id_fkey', 'cmf_lead', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_lead_parent_id'), table_name='cmf_lead')
    op.create_index('ix_cmf_lead_project_id', 'cmf_lead', ['project_id'], unique=False)
    op.drop_column('cmf_lead', 'parent_id')
    op.add_column('cmf_invoice', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_invoice_project_id_fkey', 'cmf_invoice', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_invoice_parent_id'), table_name='cmf_invoice')
    op.create_index('ix_cmf_invoice_project_id', 'cmf_invoice', ['project_id'], unique=False)
    op.drop_column('cmf_invoice', 'parent_id')
    op.add_column('cmf_document', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_document_project_id_fkey', 'cmf_document', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_document_parent_id'), table_name='cmf_document')
    op.create_index('ix_cmf_document_project_id', 'cmf_document', ['project_id'], unique=False)
    op.drop_column('cmf_document', 'parent_id')
    op.add_column('cmf_deal', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_deal_project_id_fkey', 'cmf_deal', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_deal_parent_id'), table_name='cmf_deal')
    op.create_index('ix_cmf_deal_project_id', 'cmf_deal', ['project_id'], unique=False)
    op.drop_column('cmf_deal', 'parent_id')
    op.add_column('cmf_company', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_company_project_id_fkey', 'cmf_company', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_company_parent_id'), table_name='cmf_company')
    op.create_index('ix_cmf_company_project_id', 'cmf_company', ['project_id'], unique=False)
    op.drop_column('cmf_company', 'parent_id')
    op.add_column('cmf_chat_topic', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_u_work_chat_topic_project_id_fkey', 'cmf_chat_topic', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_chat_topic_parent_id'), table_name='cmf_chat_topic')
    op.create_index('ix_cmf_chat_topic_project_id', 'cmf_chat_topic', ['project_id'], unique=False)
    op.drop_column('cmf_chat_topic', 'parent_id')
    op.add_column('cmf_chat_group', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.create_foreign_key('cmf_u_work_chat_group_project_id_fkey', 'cmf_chat_group', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_chat_group_parent_id'), table_name='cmf_chat_group')
    op.create_index('ix_cmf_chat_group_project_id', 'cmf_chat_group', ['project_id'], unique=False)
    op.drop_column('cmf_chat_group', 'parent_id')
    # ### end Alembic commands ###
