<?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 Unit.
    -->
    <changeSet id="20241015091807-1" author="jhipster">
        <createTable tableName="unit" remarks="Unit">
            <column name="id" type="bigint" autoIncrement="true" startWith="1500">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="code" type="varchar(255)" remarks="Required code to use in integrations">
                <constraints nullable="false" unique="true" uniqueConstraintName="ux_unit__code" />
            </column>
            <column name="symbol" type="varchar(255)" remarks="Math symbol that is usually used as sufix for this unit. Eg. &apos;m3&apos; for square metters.">
                <constraints nullable="false" />
            </column>
            <column name="name" type="varchar(255)" remarks="Math name for this unit. Eg. &apos;Square metters&apos;.">
                <constraints nullable="false" />
            </column>
            <column name="description" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="convertion_rate" type="decimal(21,2)" remarks="The convertion rate (CR), relative to the base unit.\nThis values awnsers the question: When the base unit is 1 (one), whats the value of this unit measure ?\nEx: How many Ml (miligrams) 1Kg has? 1000\nThe formula to convert between any value unit the scale is:\n&lt;Value&gt;*CR(target unit)/CR(source unit)">
                <constraints nullable="false" />
            </column>
            <column name="version" type="integer" defaultValueNumeric="-1" remarks="Record version for concurrency control.">
                <constraints nullable="false" />
            </column>
            <column name="unit_type_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="20241015091807-1-data" author="jhipster" context="faker">
        <loadData
                  file="config/liquibase/fake-data/unit.csv"
                  separator=";"
                  tableName="unit"
                  usePreparedStatements="true">
            <column name="id" type="numeric"/>
            <column name="code" type="string"/>
            <column name="symbol" type="string"/>
            <column name="name" type="string"/>
            <column name="description" type="string"/>
            <column name="convertion_rate" type="numeric"/>
            <column name="version" type="numeric"/>
            <!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
        </loadData>
    </changeSet>
</databaseChangeLog>
