"""initialize basic snomed components and refsets

Revision ID: 89efb2ad498e
Revises: None
Create Date: 2016-08-17 10:44:17.479387

"""

# revision identifiers, used by Alembic.
revision = '89efb2ad498e'
down_revision = None

from alembic import op
import sqlalchemy as sa
import sil_snomed_server



def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('curr_annotationrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('annotation', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id')
    )
    op.create_index('sct_curr_annotationrefset_f_index_effective_time', 'curr_annotationrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_associationrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('target_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'target_component_id')
    )
    op.create_index('sct_curr_associationrefset_f_index_effective_time', 'curr_associationrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_attributevaluerefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('value_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'value_id')
    )
    op.create_index('sct_curr_attributevaluerefset_f_index_effective_time', 'curr_attributevaluerefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_complexmaprefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('map_group', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('map_priority', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('map_rule', sa.Unicode(), nullable=True),
    sa.Column('map_target', sa.Unicode(), nullable=True),
    sa.Column('correlation_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('map_advice', sa.Unicode(), nullable=True),
    sa.Column('map_block', sa.Integer(), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'map_group', 'map_priority', 'correlation_id')
    )
    op.create_index('sct_curr_complexmaprefset_f_index_effective_time', 'curr_complexmaprefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_concept_f',
    sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('definition_status_id', sa.BigInteger(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id')
    )
    op.create_index(op.f('ix_curr_concept_f_id'), 'curr_concept_f', ['id'], unique=False)
    op.create_index('sct_curr_concept_f_index_effective_time', 'curr_concept_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_description_f',
    sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('concept_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('language_code', sa.Unicode(), nullable=True),
    sa.Column('type_id', sa.BigInteger(), nullable=True),
    sa.Column('term', sa.Text(), nullable=True),
    sa.Column('case_significance_id', sa.BigInteger(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'concept_id')
    )
    op.create_index(op.f('ix_curr_description_f_id'), 'curr_description_f', ['id'], unique=False)
    op.create_index('sct_curr_description_f_index_effective_time', 'curr_description_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_descriptionformatrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('description_format_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('description_length', sa.Integer(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'description_format_id', 'description_length')
    )
    op.create_index('sct_curr_descriptionformatrefset_f_index_effective_time', 'curr_descriptionformatrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_extendedmaprefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('map_group', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('map_priority', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('map_rule', sa.Unicode(), nullable=True),
    sa.Column('map_target', sa.Unicode(), nullable=True),
    sa.Column('correlation_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('map_category_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('map_advice', sa.Unicode(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'map_group', 'map_priority', 'correlation_id', 'map_category_id')
    )
    op.create_index('sct_curr_extendedmaprefset_f_index_effective_time', 'curr_extendedmaprefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_langrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('acceptability_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'acceptability_id')
    )
    op.create_index('sct_curr_langrefset_f_index_effective_time', 'curr_langrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_moduledependencyrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('source_effective_time', sa.Date(), nullable=False),
    sa.Column('target_effective_time', sa.Date(), nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'source_effective_time', 'target_effective_time')
    )
    op.create_index('sct_curr_moduledependencyrefset_f_index_effective_time', 'curr_moduledependencyrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_orderedrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('order', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('linked_to_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'order', 'linked_to_id')
    )
    op.create_index('sct_curr_orderedrefset_f_index_effective_time', 'curr_orderedrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_queryspecificationrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('query', sa.Unicode(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id')
    )
    op.create_index('sct_curr_queryspecificationrefset_f_index_effective_time', 'curr_queryspecificationrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_referencesetdescriptorrefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('attribute_description_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('attribute_type_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('attribute_order', sa.Integer(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id', 'attribute_description_id', 'attribute_type_id', 'attribute_order')
    )
    op.create_index('sct_curr_referencesetdescriptorrefset_f_index_effective_time', 'curr_referencesetdescriptorrefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_relationship_f',
    sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('source_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('destination_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('relationship_group', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('type_id', sa.BigInteger(), nullable=True),
    sa.Column('characteristic_type_id', sa.BigInteger(), nullable=True),
    sa.Column('modifier_id', sa.BigInteger(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'source_id', 'destination_id', 'relationship_group')
    )
    op.create_index(op.f('ix_curr_relationship_f_id'), 'curr_relationship_f', ['id'], unique=False)
    op.create_index('sct_curr_relationship_f_index_effective_time', 'curr_relationship_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_simplemaprefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('map_target', sa.Unicode(), nullable=True),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id')
    )
    op.create_index('sct_curr_simplemaprefset_f_index_effective_time', 'curr_simplemaprefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    op.create_table('curr_simplerefset_f',
    sa.Column('id', sil_snomed_server.data_types.custom_types.sa.dialects.postgresql.UUID(), nullable=False),
    sa.Column('effective_time', sa.Date(), nullable=False),
    sa.Column('active', sa.Boolean(), nullable=False),
    sa.Column('module_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('refset_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('referenced_component_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id', 'effective_time', 'active', 'module_id', 'refset_id', 'referenced_component_id')
    )
    op.create_index('sct_curr_simplerefset_f_index_effective_time', 'curr_simplerefset_f', ['effective_time'], unique=False, postgresql_using='brin')
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_index('sct_curr_simplerefset_f_index_effective_time', table_name='curr_simplerefset_f')
    op.drop_table('curr_simplerefset_f')
    op.drop_index('sct_curr_simplemaprefset_f_index_effective_time', table_name='curr_simplemaprefset_f')
    op.drop_table('curr_simplemaprefset_f')
    op.drop_index('sct_curr_relationship_f_index_effective_time', table_name='curr_relationship_f')
    op.drop_index(op.f('ix_curr_relationship_f_id'), table_name='curr_relationship_f')
    op.drop_table('curr_relationship_f')
    op.drop_index('sct_curr_referencesetdescriptorrefset_f_index_effective_time', table_name='curr_referencesetdescriptorrefset_f')
    op.drop_table('curr_referencesetdescriptorrefset_f')
    op.drop_index('sct_curr_queryspecificationrefset_f_index_effective_time', table_name='curr_queryspecificationrefset_f')
    op.drop_table('curr_queryspecificationrefset_f')
    op.drop_index('sct_curr_orderedrefset_f_index_effective_time', table_name='curr_orderedrefset_f')
    op.drop_table('curr_orderedrefset_f')
    op.drop_index('sct_curr_moduledependencyrefset_f_index_effective_time', table_name='curr_moduledependencyrefset_f')
    op.drop_table('curr_moduledependencyrefset_f')
    op.drop_index('sct_curr_langrefset_f_index_effective_time', table_name='curr_langrefset_f')
    op.drop_table('curr_langrefset_f')
    op.drop_index('sct_curr_extendedmaprefset_f_index_effective_time', table_name='curr_extendedmaprefset_f')
    op.drop_table('curr_extendedmaprefset_f')
    op.drop_index('sct_curr_descriptionformatrefset_f_index_effective_time', table_name='curr_descriptionformatrefset_f')
    op.drop_table('curr_descriptionformatrefset_f')
    op.drop_index('sct_curr_description_f_index_effective_time', table_name='curr_description_f')
    op.drop_index(op.f('ix_curr_description_f_id'), table_name='curr_description_f')
    op.drop_table('curr_description_f')
    op.drop_index('sct_curr_concept_f_index_effective_time', table_name='curr_concept_f')
    op.drop_index(op.f('ix_curr_concept_f_id'), table_name='curr_concept_f')
    op.drop_table('curr_concept_f')
    op.drop_index('sct_curr_complexmaprefset_f_index_effective_time', table_name='curr_complexmaprefset_f')
    op.drop_table('curr_complexmaprefset_f')
    op.drop_index('sct_curr_attributevaluerefset_f_index_effective_time', table_name='curr_attributevaluerefset_f')
    op.drop_table('curr_attributevaluerefset_f')
    op.drop_index('sct_curr_associationrefset_f_index_effective_time', table_name='curr_associationrefset_f')
    op.drop_table('curr_associationrefset_f')
    op.drop_index('sct_curr_annotationrefset_f_index_effective_time', table_name='curr_annotationrefset_f')
    op.drop_table('curr_annotationrefset_f')
    ### end Alembic commands ###
