"""add cache_last_comments

Revision ID: e9bcbd54d793
Revises: 5bbe3e18fa49
Create Date: 2021-04-28 10:23:55.324929

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e9bcbd54d793'
down_revision = '5bbe3e18fa49'
branch_labels = None
depends_on = None


def op_add_column(table):
    op.add_column(table, sa.Column('cache_last_comments', sa.TEXT(), nullable=True))
    op.execute(f"update {table} set cache_last_comments='[]'")
    op.alter_column(table, 'cache_last_comments', nullable=False)


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op_add_column('cmf_active_entity_filter')
    op_add_column('cmf_activity')
    op_add_column('cmf_attachment')
    op_add_column('cmf_balance')
    op_add_column('cmf_balance_operation')
    op_add_column('cmf_card')
    op_add_column('cmf_channel_message')
    op_add_column('cmf_chat_group')
    op_add_column('cmf_chat_topic')
    op_add_column('cmf_comment')
    op_add_column('cmf_company')
    op_add_column('cmf_currency')
    op_add_column('cmf_deal')
    op_add_column('cmf_document')
    op_add_column('cmf_feed')
    op_add_column('cmf_folder')
    op_add_column('cmf_form')
    op_add_column('cmf_form_field')
    op_add_column('cmf_integration')
    op_add_column('cmf_invoice')
    op_add_column('cmf_invoice_items')
    op_add_column('cmf_job')
    op_add_column('cmf_lead')
    op_add_column('cmf_list')
    op_add_column('cmf_mail')
    op_add_column('cmf_mail_signature')
    op_add_column('cmf_mail_template')
    op_add_column('cmf_mailbox')
    op_add_column('cmf_notify')
    op_add_column('cmf_org_unit')
    op_add_column('cmf_payment')
    op_add_column('cmf_person')
    op_add_column('cmf_person_group')
    op_add_column('cmf_pipeline')
    op_add_column('cmf_plan')
    op_add_column('cmf_price')
    op_add_column('cmf_print_tmpl')
    op_add_column('cmf_product')
    op_add_column('cmf_project')
    op_add_column('cmf_purchase_order')
    op_add_column('cmf_purchase_order_items')
    op_add_column('cmf_role')
    op_add_column('cmf_sales_order')
    op_add_column('cmf_sales_order_items')
    op_add_column('cmf_staff_control')
    op_add_column('cmf_staff_control_settings')
    op_add_column('cmf_status')
    op_add_column('cmf_status_opt')
    op_add_column('cmf_stock')
    op_add_column('cmf_stock_items')
    op_add_column('cmf_stock_move')
    op_add_column('cmf_stock_move_items')
    op_add_column('cmf_stock_operations')
    op_add_column('cmf_subscription')
    op_add_column('cmf_tag')
    op_add_column('cmf_task')
    op_add_column('cmf_trigger')
    op_add_column('cmf_u_work_post')
    op_add_column('cmf_unit')
    op_add_column('cmf_whatsapp')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('cmf_whatsapp', 'cache_last_comments')
    op.drop_column('cmf_unit', 'cache_last_comments')
    op.drop_column('cmf_u_work_post', 'cache_last_comments')
    op.drop_column('cmf_trigger', 'cache_last_comments')
    op.drop_column('cmf_task', 'cache_last_comments')
    op.drop_column('cmf_tag', 'cache_last_comments')
    op.drop_column('cmf_subscription', 'cache_last_comments')
    op.drop_column('cmf_stock_operations', 'cache_last_comments')
    op.drop_column('cmf_stock_move_items', 'cache_last_comments')
    op.drop_column('cmf_stock_move', 'cache_last_comments')
    op.drop_column('cmf_stock_items', 'cache_last_comments')
    op.drop_column('cmf_stock', 'cache_last_comments')
    op.drop_column('cmf_status_opt', 'cache_last_comments')
    op.drop_column('cmf_status', 'cache_last_comments')
    op.drop_column('cmf_staff_control_settings', 'cache_last_comments')
    op.drop_column('cmf_staff_control', 'cache_last_comments')
    op.drop_column('cmf_sales_order_items', 'cache_last_comments')
    op.drop_column('cmf_sales_order', 'cache_last_comments')
    op.drop_column('cmf_role', 'cache_last_comments')
    op.drop_column('cmf_purchase_order_items', 'cache_last_comments')
    op.drop_column('cmf_purchase_order', 'cache_last_comments')
    op.drop_column('cmf_project', 'cache_last_comments')
    op.drop_column('cmf_product', 'cache_last_comments')
    op.drop_column('cmf_print_tmpl', 'cache_last_comments')
    op.drop_column('cmf_price', 'cache_last_comments')
    op.drop_column('cmf_plan', 'cache_last_comments')
    op.drop_column('cmf_pipeline', 'cache_last_comments')
    op.drop_column('cmf_person_group', 'cache_last_comments')
    op.drop_column('cmf_person', 'cache_last_comments')
    op.drop_column('cmf_payment', 'cache_last_comments')
    op.drop_column('cmf_org_unit', 'cache_last_comments')
    op.drop_column('cmf_notify', 'cache_last_comments')
    op.drop_column('cmf_mailbox', 'cache_last_comments')
    op.drop_column('cmf_mail_template', 'cache_last_comments')
    op.drop_column('cmf_mail_signature', 'cache_last_comments')
    op.drop_column('cmf_mail', 'cache_last_comments')
    op.drop_column('cmf_list', 'cache_last_comments')
    op.drop_column('cmf_lead', 'cache_last_comments')
    op.drop_column('cmf_job', 'cache_last_comments')
    op.drop_column('cmf_invoice_items', 'cache_last_comments')
    op.drop_column('cmf_invoice', 'cache_last_comments')
    op.drop_column('cmf_integration', 'cache_last_comments')
    op.drop_column('cmf_form_field', 'cache_last_comments')
    op.drop_column('cmf_form', 'cache_last_comments')
    op.drop_column('cmf_folder', 'cache_last_comments')
    op.drop_column('cmf_feed', 'cache_last_comments')
    op.drop_column('cmf_document', 'cache_last_comments')
    op.drop_column('cmf_deal', 'cache_last_comments')
    op.drop_column('cmf_currency', 'cache_last_comments')
    op.drop_column('cmf_company', 'cache_last_comments')
    op.drop_column('cmf_comment', 'cache_last_comments')
    op.drop_column('cmf_chat_topic', 'cache_last_comments')
    op.drop_column('cmf_chat_group', 'cache_last_comments')
    op.drop_column('cmf_channel_message', 'cache_last_comments')
    op.drop_column('cmf_card', 'cache_last_comments')
    op.drop_column('cmf_balance_operation', 'cache_last_comments')
    op.drop_column('cmf_balance', 'cache_last_comments')
    op.drop_column('cmf_attachment', 'cache_last_comments')
    op.drop_column('cmf_activity', 'cache_last_comments')
    op.drop_column('cmf_active_entity_filter', 'cache_last_comments')
    # ### end Alembic commands ###
