<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="01-create-addressable-tables" author="dmiller" dbms="oracle,postgresql,mssql">
        <createTable tableName="acm_postal_address">
            <column name="cm_address_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_postal_address"/>
            </column>
            <column name="cm_address_status" type="VARCHAR(128)" defaultValue="ACTIVE">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_created" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_modified" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_type" type="VARCHAR(128)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_street_address" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_street_address_extra" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_locality" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_region" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_postal_code" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_country" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
        </createTable>

        <createTable tableName="acm_contact_method">
            <column name="cm_contact_method_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_contact_method"/>
            </column>
            <column name="cm_contact_method_status" type="VARCHAR(128)" defaultValue="ACTIVE">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_created" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_modified" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_type" type="VARCHAR(128)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_location" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_contact_value" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
        </createTable>

    </changeSet>

    <changeSet id="01-create-addressable-tables" author="dmiller" dbms="mysql">
        <createTable tableName="acm_postal_address">
            <column name="cm_address_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_postal_address"/>
            </column>
            <column name="cm_address_status" type="VARCHAR(128)" defaultValue="ACTIVE">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_created" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_modified" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_address_type" type="VARCHAR(128)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_street_address" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_street_address_extra" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_locality" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_region" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_postal_code" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_country" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
        </createTable>

        <createTable tableName="acm_contact_method">
            <column name="cm_contact_method_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_contact_method"/>
            </column>
            <column name="cm_contact_method_status" type="VARCHAR(128)" defaultValue="ACTIVE">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_created" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_modified" type="${timestampType}" defaultValueComputed="${timestampFunction}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_method_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_type" type="VARCHAR(128)">
                <constraints nullable="false"/>
            </column>
            <column name="cm_contact_location" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_contact_value" type="VARCHAR(1024)">
                <constraints nullable="true"/>
            </column>
        </createTable>

    </changeSet>

    <changeSet id="02-create-acm_postal_address-id" author="nebojsha.davidovikj">
        <createTable tableName="acm_postal_address_id">
            <column name="cm_seq_num" type="${idType}"/>
            <column name="cm_seq_name" type="VARCHAR(255)"/>
        </createTable>
        <insert tableName="acm_postal_address_id">
            <column name="cm_seq_num" value="100"></column>
            <column name="cm_seq_name" value="acm_postal_address"></column>
        </insert>
    </changeSet>
    <changeSet id="03-create-acm_contact_method-id" author="nebojsha.davidovikj">
        <createTable tableName="acm_contact_method_id">
            <column name="cm_seq_num" type="${idType}"/>
            <column name="cm_seq_name" type="VARCHAR(255)"/>
        </createTable>
        <insert tableName="acm_contact_method_id">
            <column name="cm_seq_num" value="100"></column>
            <column name="cm_seq_name" value="acm_contact_method"></column>
        </insert>
    </changeSet>
    <changeSet id="04-add-address-contact-method-table" author="nebojsha.davidovikj">
        <createTable tableName="acm_address_contact_method">
            <column name="cm_address_id" type="${fkIdType}">
                <constraints nullable="false" foreignKeyName="fk_address_cntct_address_id" references="acm_postal_address(cm_address_id)"/>
            </column>
            <column name="cm_contact_method_id" type="${fkIdType}">
                <constraints nullable="false" foreignKeyName="fk_address_cntct_cntct_id"
                    references="acm_contact_method(cm_contact_method_id)"/>
            </column>
        </createTable>
        <createIndex tableName="acm_address_contact_method" indexName="idx_address_cntct_person_id">
            <column name="cm_address_id"/>
        </createIndex>
        <createIndex tableName="acm_address_contact_method" indexName="idx_address_cntct_cntct_id">
            <column name="cm_contact_method_id"/>
        </createIndex>
    </changeSet>

    <changeSet id="05-add-sub-type-to-contact_method" author="dragan.simonovski" dbms="oracle,postgresql,mssql">
        <addColumn tableName="acm_contact_method">
            <column name="cm_contact_sub_type" type="VARCHAR(128)">
                <constraints nullable="true"/>
            </column>
            <column name="cm_description" type="VARCHAR(1024)"/>
        </addColumn>
    </changeSet>
    <changeSet id="05-add-sub-type-to-contact_method" author="dragan.simonovski" dbms="mysql">
        <addColumn tableName="acm_contact_method">
            <column name="cm_contact_sub_type" type="TEXT">
                <constraints nullable="true"/>
            </column>
            <column name="cm_description" type="TEXT"/>
        </addColumn>
    </changeSet>

    <changeSet id="06-add-discriminator-column-extensibility" author="manoj.dhungana">
        <addColumn tableName="acm_postal_address">
            <column name="cm_class_name" type="VARCHAR(400)" defaultValue="com.armedia.acm.plugins.addressable.model.PostalAddress">
                <constraints nullable="false"/>
            </column>
        </addColumn>
        <addColumn tableName="acm_contact_method">
            <column name="cm_class_name" type="VARCHAR(400)" defaultValue="com.armedia.acm.plugins.addressable.model.ContactMethod">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>
    
    <changeSet id="07-update-cm_address_type-column" author="stefan.sanevski" >
        <dropNotNullConstraint tableName="acm_postal_address" columnName="cm_address_type" columnDataType="VARCHAR(128)"></dropNotNullConstraint>
    </changeSet>

    <changeSet id="16-change_cm_contact_method_created" author="mario.gjurcheski" dbms="mysql">
        <modifyDataType tableName="acm_contact_method" columnName="cm_contact_method_created" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_contact_method" columnName="cm_contact_method_modified" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_postal_address" columnName="cm_address_created" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_postal_address" columnName="cm_address_modified" newDataType="DATETIME"/>
    </changeSet>

</databaseChangeLog>

