"""cmf text search

Revision ID: 69b79419d661
Revises: ded098605cb8
Create Date: 2023-09-22 17:17:57.208534

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

# revision identifiers, used by Alembic.
revision = '69b79419d661'
down_revision = 'ded098605cb8'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.execute(sa.text("CREATE EXTENSION IF NOT EXISTS pg_trgm;"))
    op.create_index(op.f('ix_cmf_synonym_dict_name'), 'cmf_synonym', ['dict_name'], unique=False)
    op.create_index('ix_cmf_synonym_name_gin_trgm', 'cmf_synonym', ['name'], unique=False, postgresql_using='gin', postgresql_ops={'name': 'gin_trgm_ops'})
    op.create_index(op.f('ix_cmf_synonym_stat_lang_usage'), 'cmf_synonym', ['stat_lang_usage'], unique=False)
    op.create_index(op.f('ix_cmf_synonym_stat_search'), 'cmf_synonym', ['stat_search'], unique=False)
    op.create_index(op.f('ix_cmf_synonym_stat_usage'), 'cmf_synonym', ['stat_usage'], unique=False)
    op.add_column('cmf_text_search', sa.Column('obj_logic_type_code', sa.TEXT(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('obj_activity_code', sa.TEXT(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('obj_result', sa.TEXT(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('obj_comments', sa.TEXT(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('obj_owner_name', sa.TEXT(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('obj_responsible_names', sa.TEXT(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('result_tsvector', postgresql.TSVECTOR(), nullable=True))
    op.add_column('cmf_text_search', sa.Column('comments_tsvector', postgresql.TSVECTOR(), nullable=True))
    op.drop_index('ix_cmf_text_search_name_tsvector', table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_tags_tsvector', table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_text_tsvector', table_name='cmf_text_search')
    op.create_index('ix_cmf_text_search_comments_tsvector_gin', 'cmf_text_search', ['comments_tsvector'], unique=False, postgresql_using='gin')
    op.create_index('ix_cmf_text_search_name_tsvector_gin', 'cmf_text_search', ['name_tsvector'], unique=False, postgresql_using='gin')
    op.create_index(op.f('ix_cmf_text_search_obj_activity_code'), 'cmf_text_search', ['obj_activity_code'], unique=False)
    op.create_index('ix_cmf_text_search_obj_comments_gin_trgm', 'cmf_text_search', ['obj_comments'], unique=False, postgresql_using='gin', postgresql_ops={'obj_comments': 'gin_trgm_ops'})
    op.create_index(op.f('ix_cmf_text_search_obj_created_at'), 'cmf_text_search', ['obj_created_at'], unique=False)
    op.create_index(op.f('ix_cmf_text_search_obj_logic_type_code'), 'cmf_text_search', ['obj_logic_type_code'], unique=False)
    op.create_index(op.f('ix_cmf_text_search_obj_modified_at'), 'cmf_text_search', ['obj_modified_at'], unique=False)
    op.create_index(op.f('ix_cmf_text_search_obj_name'), 'cmf_text_search', ['obj_name'], unique=False)
    op.create_index('ix_cmf_text_search_obj_name_gin_trgm', 'cmf_text_search', ['obj_name'], unique=False, postgresql_using='gin', postgresql_ops={'obj_name': 'gin_trgm_ops'})
    op.create_index(op.f('ix_cmf_text_search_obj_owner_name'), 'cmf_text_search', ['obj_owner_name'], unique=False)
    op.create_index('ix_cmf_text_search_obj_owner_name_gin_trgm', 'cmf_text_search', ['obj_owner_name'], unique=False, postgresql_using='gin', postgresql_ops={'obj_owner_name': 'gin_trgm_ops'})
    op.create_index(op.f('ix_cmf_text_search_obj_responsible_names'), 'cmf_text_search', ['obj_responsible_names'], unique=False)
    op.create_index('ix_cmf_text_search_obj_responsible_names_gin_trgm', 'cmf_text_search', ['obj_responsible_names'], unique=False, postgresql_using='gin', postgresql_ops={'obj_responsible_names': 'gin_trgm_ops'})
    op.create_index('ix_cmf_text_search_obj_result_gin_trgm', 'cmf_text_search', ['obj_result'], unique=False, postgresql_using='gin', postgresql_ops={'obj_result': 'gin_trgm_ops'})
    op.create_index('ix_cmf_text_search_obj_tags_gin_trgm', 'cmf_text_search', ['obj_tags'], unique=False, postgresql_using='gin', postgresql_ops={'obj_tags': 'gin_trgm_ops'})
    op.create_index(op.f('ix_cmf_text_search_obj_tree_parent_id'), 'cmf_text_search', ['obj_tree_parent_id'], unique=False)
    op.create_index('ix_cmf_text_search_result_tsvector_gin', 'cmf_text_search', ['result_tsvector'], unique=False, postgresql_using='gin')
    op.create_index('ix_cmf_text_search_tags_tsvector_gin', 'cmf_text_search', ['tags_tsvector'], unique=False, postgresql_using='gin')
    op.create_index('ix_cmf_text_search_text_tsvector_gin', 'cmf_text_search', ['text_tsvector'], unique=False, postgresql_using='gin')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('ix_cmf_text_search_text_tsvector_gin', table_name='cmf_text_search', postgresql_using='gin')
    op.drop_index('ix_cmf_text_search_tags_tsvector_gin', table_name='cmf_text_search', postgresql_using='gin')
    op.drop_index('ix_cmf_text_search_result_tsvector_gin', table_name='cmf_text_search', postgresql_using='gin')
    op.drop_index(op.f('ix_cmf_text_search_obj_tree_parent_id'), table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_obj_tags_gin_trgm', table_name='cmf_text_search', postgresql_using='gin', postgresql_ops={'obj_tags': 'gin_trgm_ops'})
    op.drop_index('ix_cmf_text_search_obj_result_gin_trgm', table_name='cmf_text_search', postgresql_using='gin', postgresql_ops={'obj_result': 'gin_trgm_ops'})
    op.drop_index('ix_cmf_text_search_obj_responsible_names_gin_trgm', table_name='cmf_text_search', postgresql_using='gin', postgresql_ops={'obj_responsible_names': 'gin_trgm_ops'})
    op.drop_index(op.f('ix_cmf_text_search_obj_responsible_names'), table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_obj_owner_name_gin_trgm', table_name='cmf_text_search', postgresql_using='gin', postgresql_ops={'obj_owner_name': 'gin_trgm_ops'})
    op.drop_index(op.f('ix_cmf_text_search_obj_owner_name'), table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_obj_name_gin_trgm', table_name='cmf_text_search', postgresql_using='gin', postgresql_ops={'obj_name': 'gin_trgm_ops'})
    op.drop_index(op.f('ix_cmf_text_search_obj_name'), table_name='cmf_text_search')
    op.drop_index(op.f('ix_cmf_text_search_obj_modified_at'), table_name='cmf_text_search')
    op.drop_index(op.f('ix_cmf_text_search_obj_logic_type_code'), table_name='cmf_text_search')
    op.drop_index(op.f('ix_cmf_text_search_obj_created_at'), table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_obj_comments_gin_trgm', table_name='cmf_text_search', postgresql_using='gin', postgresql_ops={'obj_comments': 'gin_trgm_ops'})
    op.drop_index(op.f('ix_cmf_text_search_obj_activity_code'), table_name='cmf_text_search')
    op.drop_index('ix_cmf_text_search_name_tsvector_gin', table_name='cmf_text_search', postgresql_using='gin')
    op.drop_index('ix_cmf_text_search_comments_tsvector_gin', table_name='cmf_text_search', postgresql_using='gin')
    op.create_index('ix_cmf_text_search_text_tsvector', 'cmf_text_search', ['text_tsvector'], unique=False)
    op.create_index('ix_cmf_text_search_tags_tsvector', 'cmf_text_search', ['tags_tsvector'], unique=False)
    op.create_index('ix_cmf_text_search_name_tsvector', 'cmf_text_search', ['name_tsvector'], unique=False)
    op.drop_column('cmf_text_search', 'comments_tsvector')
    op.drop_column('cmf_text_search', 'result_tsvector')
    op.drop_column('cmf_text_search', 'obj_responsible_names')
    op.drop_column('cmf_text_search', 'obj_owner_name')
    op.drop_column('cmf_text_search', 'obj_comments')
    op.drop_column('cmf_text_search', 'obj_result')
    op.drop_column('cmf_text_search', 'obj_activity_code')
    op.drop_column('cmf_text_search', 'obj_logic_type_code')
    op.drop_index(op.f('ix_cmf_synonym_stat_usage'), table_name='cmf_synonym')
    op.drop_index(op.f('ix_cmf_synonym_stat_search'), table_name='cmf_synonym')
    op.drop_index(op.f('ix_cmf_synonym_stat_lang_usage'), table_name='cmf_synonym')
    op.drop_index('ix_cmf_synonym_name_gin_trgm', table_name='cmf_synonym', postgresql_using='gin', postgresql_ops={'name': 'gin_trgm_ops'})
    op.drop_index(op.f('ix_cmf_synonym_dict_name'), table_name='cmf_synonym')
    # ### end Alembic commands ###
