"""chat_messages

Revision ID: c1fb20145a41
Revises: 5c86366d5292
Create Date: 2021-11-09 15:43:22.985835

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

# revision identifiers, used by Alembic.
revision = 'c1fb20145a41'
down_revision = '5c86366d5292'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('cmf_chat_message',
    sa.Column('id', sa.String(length=64), nullable=False),
    sa.Column('cmf_locked_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('cmf_created_at', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('cmf_modified_at', sa.TIMESTAMP(timezone=True), nullable=False),
    sa.Column('cmf_viewed_at', sa.TIMESTAMP(timezone=True), nullable=True),
    sa.Column('cmf_deleted', sa.Boolean(), nullable=False),
    sa.Column('cmf_version', sa.Integer(), nullable=True),
    sa.Column('text', sa.String(), nullable=True),
    sa.Column('likes', sa.TEXT(), nullable=True),
    sa.Column('views', sa.TEXT(), nullable=True),
    sa.Column('important', sa.Boolean(), nullable=True),
    sa.Column('priority', sa.Integer(), nullable=False),
    sa.Column('pinned', sa.Boolean(), nullable=False),
    sa.Column('cache_cmf_author_login', sa.String(length=64), nullable=True),
    sa.Column('cache_cmf_author_name', sa.String(length=256), nullable=True),
    sa.Column('cache_cmf_author_code', sa.String(length=64), nullable=True),
    sa.Column('cmf_author_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_owner_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_owner_assistant_id', sa.String(length=64), nullable=True),
    sa.Column('parent_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_modified_by_id', sa.String(length=64), nullable=True),
    sa.Column('cmf_locked_by_id', sa.String(length=64), nullable=True),
    sa.Column('deal_id', sa.String(length=64), nullable=True),
    sa.Column('lead_id', sa.String(length=64), nullable=True),
    sa.ForeignKeyConstraint(['deal_id'], ['cmf_deal.id'], ),
    sa.ForeignKeyConstraint(['lead_id'], ['cmf_lead.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cmf_chat_message_cache_cmf_author_code'), 'cmf_chat_message', ['cache_cmf_author_code'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cache_cmf_author_name'), 'cmf_chat_message', ['cache_cmf_author_name'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_author_id'), 'cmf_chat_message', ['cmf_author_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_created_at'), 'cmf_chat_message', ['cmf_created_at'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_deleted'), 'cmf_chat_message', ['cmf_deleted'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_locked_at'), 'cmf_chat_message', ['cmf_locked_at'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_locked_by_id'), 'cmf_chat_message', ['cmf_locked_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_modified_at'), 'cmf_chat_message', ['cmf_modified_at'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_modified_by_id'), 'cmf_chat_message', ['cmf_modified_by_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_owner_assistant_id'), 'cmf_chat_message', ['cmf_owner_assistant_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_owner_id'), 'cmf_chat_message', ['cmf_owner_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_version'), 'cmf_chat_message', ['cmf_version'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_cmf_viewed_at'), 'cmf_chat_message', ['cmf_viewed_at'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_deal_id'), 'cmf_chat_message', ['deal_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_lead_id'), 'cmf_chat_message', ['lead_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_parent_id'), 'cmf_chat_message', ['parent_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_message_pinned'), 'cmf_chat_message', ['pinned'], unique=False)
    op.create_table('cmf_chat_topic_unread_message',
    sa.Column('id', sa.String(length=64), nullable=False),
    sa.Column('chat_topic_id', sa.String(length=64), nullable=False),
    sa.Column('person_id', sa.String(length=64), nullable=False),
    sa.Column('message_id', sa.String(length=64), nullable=False),
    sa.ForeignKeyConstraint(['chat_topic_id'], ['cmf_chat_topic.id'], ),
    sa.ForeignKeyConstraint(['message_id'], ['cmf_chat_message.id'], ),
    sa.ForeignKeyConstraint(['person_id'], ['cmf_person.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_cmf_chat_topic_unread_message_chat_topic_id'), 'cmf_chat_topic_unread_message', ['chat_topic_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_topic_unread_message_message_id'), 'cmf_chat_topic_unread_message', ['message_id'], unique=False)
    op.create_index(op.f('ix_cmf_chat_topic_unread_message_person_id'), 'cmf_chat_topic_unread_message', ['person_id'], unique=False)
    op.drop_index('ix_cmf_chat_topic_unread_comment_chat_topic_id', table_name='cmf_chat_topic_unread_comment')
    op.drop_index('ix_cmf_chat_topic_unread_comment_comment_id', table_name='cmf_chat_topic_unread_comment')
    op.drop_index('ix_cmf_chat_topic_unread_comment_person_id', table_name='cmf_chat_topic_unread_comment')
    op.drop_table('cmf_chat_topic_unread_comment')
    op.add_column('cmf_channel_message', sa.Column('chat_message_id', sa.String(length=64), nullable=True))
    op.create_index(op.f('ix_cmf_channel_message_chat_message_id'), 'cmf_channel_message', ['chat_message_id'], unique=False)
    op.create_foreign_key(None, 'cmf_channel_message', 'cmf_chat_message', ['chat_message_id'], ['id'])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'cmf_channel_message', type_='foreignkey')
    op.drop_index(op.f('ix_cmf_channel_message_chat_message_id'), table_name='cmf_channel_message')
    op.drop_column('cmf_channel_message', 'chat_message_id')
    op.create_table('cmf_chat_topic_unread_comment',
    sa.Column('id', sa.VARCHAR(length=64), autoincrement=False, nullable=False),
    sa.Column('chat_topic_id', sa.VARCHAR(length=64), autoincrement=False, nullable=False),
    sa.Column('person_id', sa.VARCHAR(length=64), autoincrement=False, nullable=False),
    sa.Column('comment_id', sa.VARCHAR(length=64), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['chat_topic_id'], ['cmf_chat_topic.id'], name='cmf_chat_topic_unread_comment_chat_topic_id_fkey'),
    sa.ForeignKeyConstraint(['comment_id'], ['cmf_comment.id'], name='cmf_chat_topic_unread_comment_comment_id_fkey'),
    sa.ForeignKeyConstraint(['person_id'], ['cmf_person.id'], name='cmf_chat_topic_unread_comment_person_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='cmf_chat_topic_unread_comment_pkey')
    )
    op.create_index('ix_cmf_chat_topic_unread_comment_person_id', 'cmf_chat_topic_unread_comment', ['person_id'], unique=False)
    op.create_index('ix_cmf_chat_topic_unread_comment_comment_id', 'cmf_chat_topic_unread_comment', ['comment_id'], unique=False)
    op.create_index('ix_cmf_chat_topic_unread_comment_chat_topic_id', 'cmf_chat_topic_unread_comment', ['chat_topic_id'], unique=False)
    op.drop_index(op.f('ix_cmf_chat_topic_unread_message_person_id'), table_name='cmf_chat_topic_unread_message')
    op.drop_index(op.f('ix_cmf_chat_topic_unread_message_message_id'), table_name='cmf_chat_topic_unread_message')
    op.drop_index(op.f('ix_cmf_chat_topic_unread_message_chat_topic_id'), table_name='cmf_chat_topic_unread_message')
    op.drop_table('cmf_chat_topic_unread_message')
    op.drop_index(op.f('ix_cmf_chat_message_pinned'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_parent_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_lead_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_deal_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_viewed_at'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_version'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_owner_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_owner_assistant_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_modified_by_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_modified_at'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_locked_by_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_locked_at'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_deleted'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_created_at'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cmf_author_id'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cache_cmf_author_name'), table_name='cmf_chat_message')
    op.drop_index(op.f('ix_cmf_chat_message_cache_cmf_author_code'), table_name='cmf_chat_message')
    op.drop_table('cmf_chat_message')
    # ### end Alembic commands ###
