<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-billing-item-table" author="sasko.tanaskoski" dbms="mysql,mssql">
        <createTable tableName="acm_billing_item">
            <column name="cm_billing_item_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_billing_item"/>
            </column>

            <column name="cm_billing_item_number" type="INTEGER">
                <constraints nullable="false"/>
            </column>

            <column name="cm_billing_item_description" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
            
            <column name="cm_billing_item_amount" type="DOUBLE">
                <constraints nullable="false"/>
            </column>

            <column name="cm_parent_object_id" type="${fkIdType}">
                <constraints nullable="false"/>
            </column>

            <column name="cm_parent_object_type" type="VARCHAR(128)">
                <constraints nullable="false"/>
            </column>
            
            <column name="cm_billing_item_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>

            <column name="cm_billing_item_created" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            
            <column name="cm_class_name" type="VARCHAR(400)" defaultValue="com.armedia.acm.services.billing.model.BillingItem">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <createIndex tableName="acm_billing_item" indexName="idx_parent_object_id">
            <column name="cm_parent_object_id"/>
        </createIndex>
    </changeSet>

    <changeSet id="01-create-billing-item-table" author="sasko.tanaskoski" dbms="oracle,postgres">
        <createTable tableName="acm_billing_item">
            <column name="cm_billing_item_id" type="${idType}">
                <constraints primaryKey="true" primaryKeyName="pk_billing_item"/>
            </column>

            <column name="cm_billing_item_number" type="INTEGER">
                <constraints nullable="false"/>
            </column>

            <column name="cm_billing_item_description" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>

            <column name="cm_billing_item_amount" type="DOUBLE">
                <constraints nullable="false"/>
            </column>

            <column name="cm_parent_object_id" type="${fkIdType}">
                <constraints nullable="false"/>
            </column>

            <column name="cm_parent_object_type" type="VARCHAR(128)">
                <constraints nullable="false"/>
            </column>

            <column name="cm_billing_item_creator" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>

            <column name="cm_billing_item_created" type="${timestampType}">
                <constraints nullable="false"/>
            </column>

            <column name="cm_class_name" type="VARCHAR(400)" defaultValue="com.armedia.acm.services.billing.model.BillingItem">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <createIndex tableName="acm_billing_item" indexName="idx_billing_item_parent_object_id">
            <column name="cm_parent_object_id"/>
        </createIndex>
    </changeSet>

    <changeSet id="02-create-billing-item-id-table" author="sasko.tanaskoski">
        <createTable tableName="acm_billing_item_id">
            <column name="cm_seq_num" type="${idType}"/>
            <column name="cm_seq_name" type="VARCHAR(255)"/>
        </createTable>
        <insert tableName="acm_billing_item_id">
            <column name="cm_seq_num" value="100"></column>
            <column name="cm_seq_name" value="acm_billing_item"></column>
        </insert>
    </changeSet>

    <changeSet id="03-add-billing-item-modified-and-modifier" author="sasko.tanaskoski">
        <addColumn tableName="acm_billing_item">
            <column name="cm_billing_item_modified" type="${timestampType}">
                <constraints nullable="false"/>
            </column>
            <column name="cm_billing_item_modifier" type="VARCHAR(1024)">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>

    <changeSet id="04-add-billing-item-type" author="martin.jovanovski">
        <addColumn tableName="acm_billing_item">
            <column name="cm_billing_item_type" type="VARCHAR(64)">
            </column>
        </addColumn>
    </changeSet>

    <changeSet id="05-add-billing-reference-object-id" author="ana.serafimoska">
        <addColumn tableName="acm_billing_item">
            <column name="cm_billing_reference_object_id" type="${idType}"></column>
        </addColumn>
    </changeSet>

    <changeSet id="06-add-billing-note-column" author="stefan.sanevski">
        <addColumn tableName="acm_billing_item">
            <column name="cm_billing_note" type="VARCHAR(1024)"></column>
        </addColumn>
    </changeSet>

    <changeSet id="07-change_cm_billing_item_datetime" author="mario.gjurcheski" dbms="mysql">
        <modifyDataType tableName="acm_billing_item" columnName="cm_billing_item_created" newDataType="DATETIME"/>
        <modifyDataType tableName="acm_billing_item" columnName="cm_billing_item_modified" newDataType="DATETIME"/>
    </changeSet>

    <changeSet id="08-create-index-on-creator" author="bojan.milenkoski">
        <createIndex tableName="acm_billing_item" indexName="idx_acm_billing_item_billing_item_creator">
            <column name="cm_billing_item_creator"/>
        </createIndex>
    </changeSet>
    
</databaseChangeLog>
