<?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="1" author="rpelletier">
        <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">
            USE art_relations;;

            ALTER TABLE `track_artist_producer` DROP FOREIGN KEY `FK_track_artist_producer_track_artist`;;
            ALTER TABLE `track_artist_producer` DROP FOREIGN KEY `FK_track_artist_producer_country`;;
            DROP TABLE `art_relations`.`track_artist_producer`;;

            CREATE TABLE `track_producer_nationality`(
              `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
              `track_id` int(11) unsigned NOT NULL COMMENT 'Foreign key to the track table',
              `nationality_country_id` smallint(5) unsigned NOT NULL COMMENT 'Foreign key to the country table',
              `last_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date of last update',
            PRIMARY KEY (`id`),
            UNIQUE KEY `FK_track_id` (`track_id`),
            CONSTRAINT `FK_track_producer_nationality_track` FOREIGN KEY (`track_id`) REFERENCES `track` (`id`),
            CONSTRAINT `FK_track_producer_nationality_country` FOREIGN KEY (`nationality_country_id`) REFERENCES `country` (`id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;;

        </sql>
        <rollback>
            <sql dbms="mysql" endDelimiter=";;" splitStatements="true" stripComments="true">

                USE art_relations;;

                ALTER TABLE `track_producer_nationality` DROP FOREIGN KEY `FK_track_producer_nationality_track`;;
                ALTER TABLE `track_producer_nationality` DROP FOREIGN KEY `FK_track_producer_nationality_country`;;
                DROP TABLE `art_relations`.`track_producer_nationality`;;

                CREATE TABLE `track_artist_producer` (
                `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary key',
                `track_artist_id` int(11) unsigned NOT NULL COMMENT 'Foreign key to the track_artist table',
                `country_id` smallint(5) unsigned NOT NULL COMMENT 'Foreign key to the country table',
                `last_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date of last update',
                PRIMARY KEY (`id`),
                UNIQUE KEY `FK_track_artist` (`track_artist_id`),
                CONSTRAINT `FK_track_artist_producer_track_artist` FOREIGN KEY (`track_artist_id`) REFERENCES `track_artist` (`id`),
                CONSTRAINT `FK_track_artist_producer_country` FOREIGN KEY (`country_id`) REFERENCES `country` (`id`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8;;

            </sql>
        </rollback>
    </changeSet>
</databaseChangeLog>