<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~~~~~~licensing~~~~~~
  storage-esb_entaxy
  ==========
  Copyright (C) 2020 - 2021 EmDev LLC
  ==========
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
       http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  ~~~~~~/licensing~~~~~~
  -->


<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        		http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

    <changeSet id="007001" author="mmoiseev" context="main">
        <createTable tableName="system_subscription_registry">
            <column name="id" type="bigint" autoIncrement="true">
                <constraints primaryKey="true"/>
            </column>
            <column name="event_topic_id" type="bigint">
                <constraints nullable="false"/>
            </column>
            <column name="type" type="varchar(75)"/>
            <column name="id_system" type="bigint"/>
        </createTable>
    </changeSet>

    <changeSet id="007002" author="mmoiseev" context="main">
        <addForeignKeyConstraint baseColumnNames="id_system"
                                 baseTableName="system_subscription_registry"
                                 constraintName="fk_system_subscription_registry_id_system"
                                 referencedColumnNames="id"
                                 referencedTableName="system"/>
    </changeSet>

    <changeSet id="007003" author="mmoiseev" context="main">
        <createIndex indexName="ix_system_subscription_registry_id_system"
                     tableName="system_subscription_registry"
                     unique="false">
            <column name="id_system" type="bigint"/>
        </createIndex>
    </changeSet>

    <changeSet id="007004" author="mmoiseev" context="main">
        <addForeignKeyConstraint baseColumnNames="event_topic_id"
                                 baseTableName="system_subscription_registry"
                                 constraintName="fk_system_subscription_registry_event_topic_id"
                                 referencedColumnNames="id"
                                 referencedTableName="event_topic"/>
    </changeSet>

    <changeSet id="007005" author="mmoiseev" context="main">
        <createIndex indexName="ix_system_subscription_registry_id_system_event_topic_id"
                     tableName="system_subscription_registry"
                     unique="true">
            <column name="id_system" type="bigint"/>
            <column name="event_topic_id" type="bigint"/>
        </createIndex>
    </changeSet>

    <changeSet id="007006" author="mmoiseev" context="main">
        <createIndex indexName="ix_system_subscription_registry_event_topic_id"
                     tableName="system_subscription_registry"
                     unique="false">
            <column name="event_topic_id" type="bigint"/>
        </createIndex>
    </changeSet>

    <changeSet id="007007" author="mmoiseev" context="main">
        <createIndex indexName="ix_system_subscription_registry_event_topic_id_type"
                     tableName="system_subscription_registry"
                     unique="false">
            <column name="event_topic_id" type="bigint"/>
            <column name="type" type="varchar(75)"/>
        </createIndex>
    </changeSet>

</databaseChangeLog>
