<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    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
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <!--
        Added the entity Variable.
    -->
    <changeSet id="20241015092207-1" author="jhipster">
        <createTable tableName="variable" remarks="Variable Definition (GEE variable classification)">
            <column name="id" type="bigint" autoIncrement="true" startWith="1500">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="code" type="varchar(255)" remarks="Unique key, composed by: &lt;br&gt;\nVariableScope.code + VariableCategory.code + &lt;index&gt;\nNOTA: User will provide the index property, and the software will create the code\nindex and code are NOT changeable">
                <constraints nullable="false" unique="true" uniqueConstraintName="ux_variable__code" />
            </column>
            <column name="variable_index" type="integer" remarks="Variable index">
                <constraints nullable="false" />
            </column>
            <column name="name" type="varchar(255)" remarks="The name or title for the variable">
                <constraints nullable="false" />
            </column>
            <column name="description" type="varchar(255)" remarks="The descriptions of the variable. Its meaning. Its usage.">
                <constraints nullable="false" />
            </column>
            <column name="input" type="boolean" remarks="Defines this variable as input. Values will be inserted for this variable">
                <constraints nullable="false" />
            </column>
            <column name="input_mode" type="varchar(255)" remarks="Defines the way of input. See the enum for instructions.">
                <constraints nullable="false" />
            </column>
            <column name="output" type="boolean" remarks="Defines this variable as output. This variable will be evaluated for output">
                <constraints nullable="false" />
            </column>
            <column name="output_formula" type="varchar(255)" remarks="The formula to calculate the output valut of the variable. Mandatory when output==TRUE">
                <constraints nullable="true" />
            </column>
            <column name="version" type="integer" defaultValueNumeric="-1" remarks="Record version for concurrency control.">
                <constraints nullable="false" />
            </column>
            <column name="base_unit_id" type="bigint">
                <constraints nullable="true" />
            </column>
            <column name="variable_scope_id" type="bigint">
                <constraints nullable="true" />
            </column>
            <column name="variable_category_id" type="bigint">
                <constraints nullable="true" />
            </column>
            <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here -->
        </createTable>
    </changeSet>

    <!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->

    <!--
        Load sample data generated with Faker.js
        - This data can be easily edited using a CSV editor (or even MS Excel) and
          is located in the 'src/main/resources/config/liquibase/fake-data' directory
        - By default this data is applied when running with the JHipster 'dev' profile.
          This can be customized by adding or removing 'faker' in the 'spring.liquibase.contexts'
          Spring Boot configuration key.
    -->
    <changeSet id="20241015092207-1-data" author="jhipster" context="faker">
        <loadData
                  file="config/liquibase/fake-data/variable.csv"
                  separator=";"
                  tableName="variable"
                  usePreparedStatements="true">
            <column name="id" type="numeric"/>
            <column name="code" type="string"/>
            <column name="variable_index" type="numeric"/>
            <column name="name" type="string"/>
            <column name="description" type="string"/>
            <column name="input" type="boolean"/>
            <column name="input_mode" type="string"/>
            <column name="output" type="boolean"/>
            <column name="output_formula" type="string"/>
            <column name="version" type="numeric"/>
            <!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
        </loadData>
    </changeSet>
</databaseChangeLog>
