<?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"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

    <changeSet id="012-create-stocks-table" author="effigenix">
        <createTable tableName="stocks">
            <column name="id" type="VARCHAR(36)">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="article_id" type="VARCHAR(36)">
                <constraints nullable="false"
                             foreignKeyName="fk_stocks_article"
                             references="articles(id)"/>
            </column>
            <column name="storage_location_id" type="VARCHAR(36)">
                <constraints nullable="false"
                             foreignKeyName="fk_stocks_storage_location"
                             references="storage_locations(id)"/>
            </column>
            <column name="minimum_level_amount" type="DECIMAL(12,3)"/>
            <column name="minimum_level_unit" type="VARCHAR(20)"/>
            <column name="minimum_shelf_life_days" type="INTEGER"/>
        </createTable>
        <addUniqueConstraint tableName="stocks"
                             columnNames="article_id, storage_location_id"
                             constraintName="uq_stocks_article_location"/>
        <createIndex tableName="stocks" indexName="idx_stocks_article_id">
            <column name="article_id"/>
        </createIndex>
        <createIndex tableName="stocks" indexName="idx_stocks_storage_location_id">
            <column name="storage_location_id"/>
        </createIndex>
    </changeSet>

</databaseChangeLog>
