"""refactor active entity

Revision ID: d361ac8d2e77
Revises: 90c4b572626a
Create Date: 2021-03-30 09:42:39.936549

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd361ac8d2e77'
down_revision = '90c4b572626a'
branch_labels = None
depends_on = None

def add_parent_and_owner():
    op.add_column('cmf_active_entity_filter', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_active_entity_filter', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_active_entity_filter_cmf_owner_assistant_id'), 'cmf_active_entity_filter', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_active_entity_filter_parent_id'), 'cmf_active_entity_filter', ['parent_id'], unique=False)
    op.add_column('cmf_activity', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_activity', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_activity_cmf_owner_assistant_id'), 'cmf_activity', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_activity_parent_id'), 'cmf_activity', ['parent_id'], unique=False)
    op.add_column('cmf_attachment', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_attachment_cmf_owner_assistant_id'), 'cmf_attachment', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_auth', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_auth', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_auth_cmf_owner_assistant_id'), 'cmf_auth', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_auth_parent_id'), 'cmf_auth', ['parent_id'], unique=False)
    op.add_column('cmf_balance', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_balance', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_balance_cmf_owner_assistant_id'), 'cmf_balance', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_balance_parent_id'), 'cmf_balance', ['parent_id'], unique=False)
    op.add_column('cmf_balance_operation', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_balance_operation', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_balance_operation_cmf_owner_assistant_id'), 'cmf_balance_operation', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_balance_operation_parent_id'), 'cmf_balance_operation', ['parent_id'], unique=False)
    op.add_column('cmf_card', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_card', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_card_cmf_owner_assistant_id'), 'cmf_card', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_card_parent_id'), 'cmf_card', ['parent_id'], unique=False)
    op.add_column('cmf_chat_group', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_chat_group_cmf_owner_assistant_id'), 'cmf_chat_group', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_chat_topic', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_chat_topic_cmf_owner_assistant_id'), 'cmf_chat_topic', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_comment', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_comment_cmf_owner_assistant_id'), 'cmf_comment', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_company', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_company_cmf_owner_assistant_id'), 'cmf_company', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_currency', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_currency', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_currency_cmf_owner_assistant_id'), 'cmf_currency', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_currency_parent_id'), 'cmf_currency', ['parent_id'], unique=False)
    op.add_column('cmf_deal', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_deal_cmf_owner_assistant_id'), 'cmf_deal', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_document', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_document_cmf_owner_assistant_id'), 'cmf_document', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_feed', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_feed', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_feed_cmf_owner_assistant_id'), 'cmf_feed', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_feed_parent_id'), 'cmf_feed', ['parent_id'], unique=False)
    op.add_column('cmf_folder', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_folder', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_folder_cmf_owner_assistant_id'), 'cmf_folder', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_folder_parent_id'), 'cmf_folder', ['parent_id'], unique=False)
    op.add_column('cmf_form', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_form', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_form_cmf_owner_assistant_id'), 'cmf_form', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_form_parent_id'), 'cmf_form', ['parent_id'], unique=False)
    op.add_column('cmf_form_field', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_form_field', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_form_field_cmf_owner_assistant_id'), 'cmf_form_field', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_form_field_parent_id'), 'cmf_form_field', ['parent_id'], unique=False)
    op.add_column('cmf_integration', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_integration', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_integration_cmf_owner_assistant_id'), 'cmf_integration', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_integration_parent_id'), 'cmf_integration', ['parent_id'], unique=False)
    op.add_column('cmf_invoice', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_invoice_cmf_owner_assistant_id'), 'cmf_invoice', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_invoice_items', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_invoice_items', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_invoice_items_cmf_owner_assistant_id'), 'cmf_invoice_items', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_invoice_items_parent_id'), 'cmf_invoice_items', ['parent_id'], unique=False)
    op.add_column('cmf_job', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_job', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_job_cmf_owner_assistant_id'), 'cmf_job', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_job_parent_id'), 'cmf_job', ['parent_id'], unique=False)
    op.add_column('cmf_lead', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_lead_cmf_owner_assistant_id'), 'cmf_lead', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_list', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_list_cmf_owner_assistant_id'), 'cmf_list', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_mail', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_mail_cmf_owner_assistant_id'), 'cmf_mail', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_mail_signature', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_mail_signature', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_mail_signature_cmf_owner_assistant_id'), 'cmf_mail_signature', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_mail_signature_parent_id'), 'cmf_mail_signature', ['parent_id'], unique=False)
    op.add_column('cmf_mail_template', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_mail_template', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_mail_template_cmf_owner_assistant_id'), 'cmf_mail_template', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_mail_template_parent_id'), 'cmf_mail_template', ['parent_id'], unique=False)
    op.add_column('cmf_mailbox', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_mailbox', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_mailbox_cmf_owner_assistant_id'), 'cmf_mailbox', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_mailbox_parent_id'), 'cmf_mailbox', ['parent_id'], unique=False)
    op.add_column('cmf_org_unit', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_org_unit', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_org_unit_cmf_owner_assistant_id'), 'cmf_org_unit', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_org_unit_parent_id'), 'cmf_org_unit', ['parent_id'], unique=False)
    op.add_column('cmf_payment', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_payment_cmf_owner_assistant_id'), 'cmf_payment', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_person', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_person', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_person_cmf_owner_assistant_id'), 'cmf_person', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_person_parent_id'), 'cmf_person', ['parent_id'], unique=False)
    op.add_column('cmf_person_group', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_person_group', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_person_group_cmf_owner_assistant_id'), 'cmf_person_group', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_person_group_parent_id'), 'cmf_person_group', ['parent_id'], unique=False)
    op.add_column('cmf_pipeline', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_pipeline_cmf_owner_assistant_id'), 'cmf_pipeline', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_plan', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_plan', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_plan_cmf_owner_assistant_id'), 'cmf_plan', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_plan_parent_id'), 'cmf_plan', ['parent_id'], unique=False)
    op.add_column('cmf_price', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_price', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_price_cmf_owner_assistant_id'), 'cmf_price', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_price_parent_id'), 'cmf_price', ['parent_id'], unique=False)
    op.add_column('cmf_print_tmpl', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_print_tmpl', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_print_tmpl_cmf_owner_assistant_id'), 'cmf_print_tmpl', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_print_tmpl_parent_id'), 'cmf_print_tmpl', ['parent_id'], unique=False)
    op.add_column('cmf_product', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_product', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_product_cmf_owner_assistant_id'), 'cmf_product', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_product_parent_id'), 'cmf_product', ['parent_id'], unique=False)
    op.add_column('cmf_project', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_project_parent_id'), 'cmf_project', ['parent_id'], unique=False)
    op.add_column('cmf_purchase_order', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_purchase_order_cmf_owner_assistant_id'), 'cmf_purchase_order', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_purchase_order_items', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_purchase_order_items_cmf_owner_assistant_id'), 'cmf_purchase_order_items', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_role', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_role', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_role_cmf_owner_assistant_id'), 'cmf_role', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_role_parent_id'), 'cmf_role', ['parent_id'], unique=False)
    op.add_column('cmf_sales_order', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_sales_order_cmf_owner_assistant_id'), 'cmf_sales_order', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_sales_order_items', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_sales_order_items', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_sales_order_items_cmf_owner_assistant_id'), 'cmf_sales_order_items', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_sales_order_items_parent_id'), 'cmf_sales_order_items', ['parent_id'], unique=False)
    op.add_column('cmf_staff_control', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_staff_control', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_staff_control_cmf_owner_assistant_id'), 'cmf_staff_control', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_parent_id'), 'cmf_staff_control', ['parent_id'], unique=False)
    op.add_column('cmf_staff_control_settings', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_staff_control_settings', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_staff_control_settings_cmf_owner_assistant_id'), 'cmf_staff_control_settings', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_staff_control_settings_parent_id'), 'cmf_staff_control_settings', ['parent_id'], unique=False)
    op.add_column('cmf_status', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_status', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_status_cmf_owner_assistant_id'), 'cmf_status', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_status_parent_id'), 'cmf_status', ['parent_id'], unique=False)
    op.add_column('cmf_status_opt', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_status_opt', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_status_opt_cmf_owner_assistant_id'), 'cmf_status_opt', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_status_opt_parent_id'), 'cmf_status_opt', ['parent_id'], unique=False)
    op.add_column('cmf_stock', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_stock', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_stock_cmf_owner_assistant_id'), 'cmf_stock', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_stock_parent_id'), 'cmf_stock', ['parent_id'], unique=False)
    op.add_column('cmf_stock_items', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_stock_items', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_stock_items_cmf_owner_assistant_id'), 'cmf_stock_items', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_stock_items_parent_id'), 'cmf_stock_items', ['parent_id'], unique=False)
    op.add_column('cmf_stock_move', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_stock_move_cmf_owner_assistant_id'), 'cmf_stock_move', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_stock_move_items', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_stock_move_items_cmf_owner_assistant_id'), 'cmf_stock_move_items', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_stock_operations', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_stock_operations', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_stock_operations_cmf_owner_assistant_id'), 'cmf_stock_operations', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_stock_operations_parent_id'), 'cmf_stock_operations', ['parent_id'], unique=False)
    op.add_column('cmf_subscription', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_subscription', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_subscription_cmf_owner_assistant_id'), 'cmf_subscription', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_subscription_parent_id'), 'cmf_subscription', ['parent_id'], unique=False)
    op.add_column('cmf_tag', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_tag', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_tag_cmf_owner_assistant_id'), 'cmf_tag', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_tag_parent_id'), 'cmf_tag', ['parent_id'], unique=False)
    op.add_column('cmf_task', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_task_cmf_owner_assistant_id'), 'cmf_task', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_trigger', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_trigger', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_trigger_cmf_owner_assistant_id'), 'cmf_trigger', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_trigger_parent_id'), 'cmf_trigger', ['parent_id'], unique=False)
    op.add_column('cmf_u_work_post', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_u_work_post_cmf_owner_assistant_id'), 'cmf_u_work_post', ['cmf_owner_assistant_id'], unique=False)
    op.add_column('cmf_unit', sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True))
    op.add_column('cmf_unit', sa.Column('parent_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_unit_cmf_owner_assistant_id'), 'cmf_unit', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_unit_parent_id'), 'cmf_unit', ['parent_id'], unique=False)

def not_null_status():
    op.execute("update cmf_chat_group set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_chat_group', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_chat_topic set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_chat_topic', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_company set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_company', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_deal set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_deal', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_document set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_document', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_invoice set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_invoice', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_lead set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_lead', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_list set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_list', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_mail set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_mail', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_payment set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_payment', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_pipeline set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_pipeline', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_purchase_order set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_purchase_order', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_purchase_order_items set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_purchase_order_items', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_sales_order set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_sales_order', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_stock_move set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_stock_move', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_stock_move_items set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_stock_move_items', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

    op.execute("update cmf_task set status_id = 'CmfStatus:00000000-0000-0000-0000-000000000002' where status_id is null")
    op.alter_column('cmf_task', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=False)

def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###

    add_parent_and_owner()
    not_null_status()

    op.alter_column('cmf_person', 'project_id', new_column_name='default_parent_id')

    op.drop_index('ix_cmf_person_project_id', table_name='cmf_person')
    op.create_index(op.f('ix_cmf_person_default_parent_id'), 'cmf_person', ['default_parent_id'], unique=False)

    op.drop_constraint('cmf_person_project_id_fkey', 'cmf_person', type_='foreignkey')
    op.create_foreign_key(None, 'cmf_person', 'cmf_project', ['default_parent_id'], ['id'])

    op.alter_column('cmf_project', 'cmf_owner_deputy_id', new_column_name='cmf_owner_assistant_id')

    op.drop_index('ix_cmf_project_cmf_owner_deputy_id', table_name='cmf_project')
    op.create_index(op.f('ix_cmf_project_cmf_owner_assistant_id'), 'cmf_project', ['cmf_owner_assistant_id'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_cmf_unit_parent_id'), table_name='cmf_unit')
    op.drop_index(op.f('ix_cmf_unit_cmf_owner_assistant_id'), table_name='cmf_unit')
    op.drop_column('cmf_unit', 'parent_id')
    op.drop_column('cmf_unit', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_u_work_post_cmf_owner_assistant_id'), table_name='cmf_u_work_post')
    op.drop_column('cmf_u_work_post', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_trigger_parent_id'), table_name='cmf_trigger')
    op.drop_index(op.f('ix_cmf_trigger_cmf_owner_assistant_id'), table_name='cmf_trigger')
    op.drop_column('cmf_trigger', 'parent_id')
    op.drop_column('cmf_trigger', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_task_cmf_owner_assistant_id'), table_name='cmf_task')
    op.alter_column('cmf_task', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_task', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_tag_parent_id'), table_name='cmf_tag')
    op.drop_index(op.f('ix_cmf_tag_cmf_owner_assistant_id'), table_name='cmf_tag')
    op.drop_column('cmf_tag', 'parent_id')
    op.drop_column('cmf_tag', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_subscription_parent_id'), table_name='cmf_subscription')
    op.drop_index(op.f('ix_cmf_subscription_cmf_owner_assistant_id'), table_name='cmf_subscription')
    op.drop_column('cmf_subscription', 'parent_id')
    op.drop_column('cmf_subscription', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_stock_operations_parent_id'), table_name='cmf_stock_operations')
    op.drop_index(op.f('ix_cmf_stock_operations_cmf_owner_assistant_id'), table_name='cmf_stock_operations')
    op.drop_column('cmf_stock_operations', 'parent_id')
    op.drop_column('cmf_stock_operations', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_stock_move_items_cmf_owner_assistant_id'), table_name='cmf_stock_move_items')
    op.alter_column('cmf_stock_move_items', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_stock_move_items', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_stock_move_cmf_owner_assistant_id'), table_name='cmf_stock_move')
    op.alter_column('cmf_stock_move', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_stock_move', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_stock_items_parent_id'), table_name='cmf_stock_items')
    op.drop_index(op.f('ix_cmf_stock_items_cmf_owner_assistant_id'), table_name='cmf_stock_items')
    op.drop_column('cmf_stock_items', 'parent_id')
    op.drop_column('cmf_stock_items', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_stock_parent_id'), table_name='cmf_stock')
    op.drop_index(op.f('ix_cmf_stock_cmf_owner_assistant_id'), table_name='cmf_stock')
    op.drop_column('cmf_stock', 'parent_id')
    op.drop_column('cmf_stock', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_status_opt_parent_id'), table_name='cmf_status_opt')
    op.drop_index(op.f('ix_cmf_status_opt_cmf_owner_assistant_id'), table_name='cmf_status_opt')
    op.drop_column('cmf_status_opt', 'parent_id')
    op.drop_column('cmf_status_opt', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_status_parent_id'), table_name='cmf_status')
    op.drop_index(op.f('ix_cmf_status_cmf_owner_assistant_id'), table_name='cmf_status')
    op.drop_column('cmf_status', 'parent_id')
    op.drop_column('cmf_status', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_staff_control_settings_parent_id'), table_name='cmf_staff_control_settings')
    op.drop_index(op.f('ix_cmf_staff_control_settings_cmf_owner_assistant_id'), table_name='cmf_staff_control_settings')
    op.drop_column('cmf_staff_control_settings', 'parent_id')
    op.drop_column('cmf_staff_control_settings', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_staff_control_parent_id'), table_name='cmf_staff_control')
    op.drop_index(op.f('ix_cmf_staff_control_cmf_owner_assistant_id'), table_name='cmf_staff_control')
    op.drop_column('cmf_staff_control', 'parent_id')
    op.drop_column('cmf_staff_control', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_sales_order_items_parent_id'), table_name='cmf_sales_order_items')
    op.drop_index(op.f('ix_cmf_sales_order_items_cmf_owner_assistant_id'), table_name='cmf_sales_order_items')
    op.drop_column('cmf_sales_order_items', 'parent_id')
    op.drop_column('cmf_sales_order_items', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_sales_order_cmf_owner_assistant_id'), table_name='cmf_sales_order')
    op.alter_column('cmf_sales_order', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_sales_order', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_role_parent_id'), table_name='cmf_role')
    op.drop_index(op.f('ix_cmf_role_cmf_owner_assistant_id'), table_name='cmf_role')
    op.drop_column('cmf_role', 'parent_id')
    op.drop_column('cmf_role', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_purchase_order_items_cmf_owner_assistant_id'), table_name='cmf_purchase_order_items')
    op.alter_column('cmf_purchase_order_items', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_purchase_order_items', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_purchase_order_cmf_owner_assistant_id'), table_name='cmf_purchase_order')
    op.alter_column('cmf_purchase_order', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_purchase_order', 'cmf_owner_assistant_id')
    op.add_column('cmf_project', sa.Column('cmf_owner_deputy_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.drop_index(op.f('ix_cmf_project_parent_id'), table_name='cmf_project')
    op.drop_index(op.f('ix_cmf_project_cmf_owner_assistant_id'), table_name='cmf_project')
    op.create_index('ix_cmf_project_cmf_owner_deputy_id', 'cmf_project', ['cmf_owner_deputy_id'], unique=False)
    op.drop_column('cmf_project', 'parent_id')
    op.drop_column('cmf_project', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_product_parent_id'), table_name='cmf_product')
    op.drop_index(op.f('ix_cmf_product_cmf_owner_assistant_id'), table_name='cmf_product')
    op.drop_column('cmf_product', 'parent_id')
    op.drop_column('cmf_product', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_print_tmpl_parent_id'), table_name='cmf_print_tmpl')
    op.drop_index(op.f('ix_cmf_print_tmpl_cmf_owner_assistant_id'), table_name='cmf_print_tmpl')
    op.drop_column('cmf_print_tmpl', 'parent_id')
    op.drop_column('cmf_print_tmpl', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_price_parent_id'), table_name='cmf_price')
    op.drop_index(op.f('ix_cmf_price_cmf_owner_assistant_id'), table_name='cmf_price')
    op.drop_column('cmf_price', 'parent_id')
    op.drop_column('cmf_price', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_plan_parent_id'), table_name='cmf_plan')
    op.drop_index(op.f('ix_cmf_plan_cmf_owner_assistant_id'), table_name='cmf_plan')
    op.drop_column('cmf_plan', 'parent_id')
    op.drop_column('cmf_plan', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_pipeline_cmf_owner_assistant_id'), table_name='cmf_pipeline')
    op.alter_column('cmf_pipeline', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_pipeline', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_person_group_parent_id'), table_name='cmf_person_group')
    op.drop_index(op.f('ix_cmf_person_group_cmf_owner_assistant_id'), table_name='cmf_person_group')
    op.drop_column('cmf_person_group', 'parent_id')
    op.drop_column('cmf_person_group', 'cmf_owner_assistant_id')
    op.add_column('cmf_person', sa.Column('project_id', sa.VARCHAR(length=64), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'cmf_person', type_='foreignkey')
    op.create_foreign_key('cmf_person_project_id_fkey', 'cmf_person', 'cmf_project', ['project_id'], ['id'])
    op.drop_index(op.f('ix_cmf_person_parent_id'), table_name='cmf_person')
    op.drop_index(op.f('ix_cmf_person_default_parent_id'), table_name='cmf_person')
    op.drop_index(op.f('ix_cmf_person_cmf_owner_assistant_id'), table_name='cmf_person')
    op.create_index('ix_cmf_person_project_id', 'cmf_person', ['project_id'], unique=False)
    op.drop_column('cmf_person', 'parent_id')
    op.drop_column('cmf_person', 'default_parent_id')
    op.drop_column('cmf_person', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_payment_cmf_owner_assistant_id'), table_name='cmf_payment')
    op.alter_column('cmf_payment', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_payment', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_org_unit_parent_id'), table_name='cmf_org_unit')
    op.drop_index(op.f('ix_cmf_org_unit_cmf_owner_assistant_id'), table_name='cmf_org_unit')
    op.drop_column('cmf_org_unit', 'parent_id')
    op.drop_column('cmf_org_unit', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_mailbox_parent_id'), table_name='cmf_mailbox')
    op.drop_index(op.f('ix_cmf_mailbox_cmf_owner_assistant_id'), table_name='cmf_mailbox')
    op.drop_column('cmf_mailbox', 'parent_id')
    op.drop_column('cmf_mailbox', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_mail_template_parent_id'), table_name='cmf_mail_template')
    op.drop_index(op.f('ix_cmf_mail_template_cmf_owner_assistant_id'), table_name='cmf_mail_template')
    op.drop_column('cmf_mail_template', 'parent_id')
    op.drop_column('cmf_mail_template', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_mail_signature_parent_id'), table_name='cmf_mail_signature')
    op.drop_index(op.f('ix_cmf_mail_signature_cmf_owner_assistant_id'), table_name='cmf_mail_signature')
    op.drop_column('cmf_mail_signature', 'parent_id')
    op.drop_column('cmf_mail_signature', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_mail_cmf_owner_assistant_id'), table_name='cmf_mail')
    op.alter_column('cmf_mail', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_mail', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_list_cmf_owner_assistant_id'), table_name='cmf_list')
    op.alter_column('cmf_list', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_list', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_lead_cmf_owner_assistant_id'), table_name='cmf_lead')
    op.alter_column('cmf_lead', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_lead', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_job_parent_id'), table_name='cmf_job')
    op.drop_index(op.f('ix_cmf_job_cmf_owner_assistant_id'), table_name='cmf_job')
    op.drop_column('cmf_job', 'parent_id')
    op.drop_column('cmf_job', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_invoice_items_parent_id'), table_name='cmf_invoice_items')
    op.drop_index(op.f('ix_cmf_invoice_items_cmf_owner_assistant_id'), table_name='cmf_invoice_items')
    op.drop_column('cmf_invoice_items', 'parent_id')
    op.drop_column('cmf_invoice_items', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_invoice_cmf_owner_assistant_id'), table_name='cmf_invoice')
    op.alter_column('cmf_invoice', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_invoice', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_integration_parent_id'), table_name='cmf_integration')
    op.drop_index(op.f('ix_cmf_integration_cmf_owner_assistant_id'), table_name='cmf_integration')
    op.drop_column('cmf_integration', 'parent_id')
    op.drop_column('cmf_integration', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_form_field_parent_id'), table_name='cmf_form_field')
    op.drop_index(op.f('ix_cmf_form_field_cmf_owner_assistant_id'), table_name='cmf_form_field')
    op.drop_column('cmf_form_field', 'parent_id')
    op.drop_column('cmf_form_field', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_form_parent_id'), table_name='cmf_form')
    op.drop_index(op.f('ix_cmf_form_cmf_owner_assistant_id'), table_name='cmf_form')
    op.drop_column('cmf_form', 'parent_id')
    op.drop_column('cmf_form', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_folder_parent_id'), table_name='cmf_folder')
    op.drop_index(op.f('ix_cmf_folder_cmf_owner_assistant_id'), table_name='cmf_folder')
    op.drop_column('cmf_folder', 'parent_id')
    op.drop_column('cmf_folder', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_feed_parent_id'), table_name='cmf_feed')
    op.drop_index(op.f('ix_cmf_feed_cmf_owner_assistant_id'), table_name='cmf_feed')
    op.drop_column('cmf_feed', 'parent_id')
    op.drop_column('cmf_feed', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_document_cmf_owner_assistant_id'), table_name='cmf_document')
    op.alter_column('cmf_document', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_document', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_deal_cmf_owner_assistant_id'), table_name='cmf_deal')
    op.alter_column('cmf_deal', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_deal', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_currency_parent_id'), table_name='cmf_currency')
    op.drop_index(op.f('ix_cmf_currency_cmf_owner_assistant_id'), table_name='cmf_currency')
    op.drop_column('cmf_currency', 'parent_id')
    op.drop_column('cmf_currency', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_company_cmf_owner_assistant_id'), table_name='cmf_company')
    op.alter_column('cmf_company', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_company', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_comment_cmf_owner_assistant_id'), table_name='cmf_comment')
    op.drop_column('cmf_comment', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_chat_topic_cmf_owner_assistant_id'), table_name='cmf_chat_topic')
    op.alter_column('cmf_chat_topic', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_chat_topic', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_chat_group_cmf_owner_assistant_id'), table_name='cmf_chat_group')
    op.alter_column('cmf_chat_group', 'status_id',
               existing_type=sa.VARCHAR(length=64),
               nullable=True)
    op.drop_column('cmf_chat_group', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_card_parent_id'), table_name='cmf_card')
    op.drop_index(op.f('ix_cmf_card_cmf_owner_assistant_id'), table_name='cmf_card')
    op.drop_column('cmf_card', 'parent_id')
    op.drop_column('cmf_card', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_balance_operation_parent_id'), table_name='cmf_balance_operation')
    op.drop_index(op.f('ix_cmf_balance_operation_cmf_owner_assistant_id'), table_name='cmf_balance_operation')
    op.drop_column('cmf_balance_operation', 'parent_id')
    op.drop_column('cmf_balance_operation', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_balance_parent_id'), table_name='cmf_balance')
    op.drop_index(op.f('ix_cmf_balance_cmf_owner_assistant_id'), table_name='cmf_balance')
    op.drop_column('cmf_balance', 'parent_id')
    op.drop_column('cmf_balance', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_auth_parent_id'), table_name='cmf_auth')
    op.drop_index(op.f('ix_cmf_auth_cmf_owner_assistant_id'), table_name='cmf_auth')
    op.drop_column('cmf_auth', 'parent_id')
    op.drop_column('cmf_auth', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_attachment_cmf_owner_assistant_id'), table_name='cmf_attachment')
    op.drop_column('cmf_attachment', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_activity_parent_id'), table_name='cmf_activity')
    op.drop_index(op.f('ix_cmf_activity_cmf_owner_assistant_id'), table_name='cmf_activity')
    op.drop_column('cmf_activity', 'parent_id')
    op.drop_column('cmf_activity', 'cmf_owner_assistant_id')
    op.drop_index(op.f('ix_cmf_active_entity_filter_parent_id'), table_name='cmf_active_entity_filter')
    op.drop_index(op.f('ix_cmf_active_entity_filter_cmf_owner_assistant_id'), table_name='cmf_active_entity_filter')
    op.drop_column('cmf_active_entity_filter', 'parent_id')
    op.drop_column('cmf_active_entity_filter', 'cmf_owner_assistant_id')
    # ### end Alembic commands ###
