<?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 Organization.
    -->
    <changeSet id="20241015091407-1" author="jhipster">
        <createTable tableName="organization" remarks="Organization\nHierarchical organigram of the organization.">
            <column name="id" type="bigint" autoIncrement="true" startWith="1500">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="code" type="varchar(255)" remarks="User defined code. Must be unique in the Organization">
                <constraints nullable="false" unique="true" uniqueConstraintName="ux_organization__code" />
            </column>
            <column name="name" type="varchar(255)" remarks="The name of the Organization entry. Allows duplicate name&apos;s, but NOT duplicate code&apos;s.">
                <constraints nullable="false" />
            </column>
            <column name="image" type="${blobType}">
                <constraints nullable="true" />
            </column>
            <column name="image_content_type" type="varchar(255)">
                <constraints nullable="true" />
            </column>
            <column name="input_inventory" type="boolean">
                <constraints nullable="true" />
            </column>
            <column name="output_inventory" type="boolean">
                <constraints nullable="true" />
            </column>
            <column name="version" type="integer" defaultValueNumeric="-1" remarks="Record version for concurrency control.">
                <constraints nullable="false" />
            </column>
            <column name="user_id" type="bigint">
                <constraints nullable="true" unique="true" uniqueConstraintName="ux_organization__user_id" />
            </column>
            <column name="parent_id" type="bigint">
                <constraints nullable="true" />
            </column>
            <column name="organization_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="20241015091407-1-data" author="jhipster" context="faker">
        <loadData
                  file="config/liquibase/fake-data/organization.csv"
                  separator=";"
                  tableName="organization"
                  usePreparedStatements="true">
            <column name="id" type="numeric"/>
            <column name="code" type="string"/>
            <column name="name" type="string"/>
            <column name="image" type="blob"/>
            <column name="image_content_type" type="string"/>
            <column name="input_inventory" type="boolean"/>
            <column name="output_inventory" type="boolean"/>
            <column name="version" type="numeric"/>
            <!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
        </loadData>
    </changeSet>
</databaseChangeLog>
