<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet id="2" author="klayman1">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            USE art_relations;;
            DROP TABLE IF EXISTS `project`;;

            CREATE TABLE project(
            project_id BIGINT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
            project_code varchar(255) NOT NULL COMMENT 'example: DAP-012',
            vendor_id INT(15) UNSIGNED NOT NULL COMMENT 'Foreign key to vendor table',
            subaccount_id INT(15) UNSIGNED NOT NULL COMMENT 'Non-null subaccount_id where NULL is represented by 0',
            project_name varchar(255) NOT NULL,
            created_date_utc datetime(6) NOT NULL COMMENT 'microsecond precision',
            updated_date_utc datetime(6) NOT NULL COMMENT 'microsecond precision',
            correlation_id varchar(100) NULL COMMENT 'example: e4eaaaf2-d142-11e1-b3e4-080027620cdd',
            PRIMARY KEY (project_id),
            UNIQUE KEY `project_idx1` (`project_code`,`vendor_id`,`subaccount_id`),
            KEY `project_idx2` (`vendor_id`,`subaccount_id`,`created_date_utc`),
            CONSTRAINT FK_vendor_id FOREIGN KEY (vendor_id) REFERENCES vendor (vendor_id) ON DELETE CASCADE ON UPDATE NO ACTION
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;;
        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
                USE art_relations;;

                ALTER TABLE project DROP FOREIGN KEY FK_vendor_id;;
                DROP TABLE project;;
            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>
