<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-4.9.xsd">

  <changeSet id="0001" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_form" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_form" schemaName="ervu_dashboard" remarks="Справочник форм обучения">
      <column name="education_form_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_form"
                         columnNames="code"
                         constraintName="education_form_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_form" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0002" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_leave_reason" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_leave_reason" schemaName="ervu_dashboard" remarks="Справочник причин отпуска">
      <column name="education_leave_reason_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_leave_reason"
                         columnNames="code"
                         constraintName="education_leave_reason_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_leave_reason" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0003" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_status" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_status" schemaName="ervu_dashboard" remarks="Справочник статуса обучения">
      <column name="education_status_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_status"
                         columnNames="code"
                         constraintName="education_status_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_status" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0004" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_level" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_level" schemaName="ervu_dashboard" remarks="Справочник уровня образования">
      <column name="education_level_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_level"
                         columnNames="code"
                         constraintName="education_level_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_level" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0005" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_minobr_doc_type" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_minobr_doc_type" schemaName="ervu_dashboard" remarks="Справочник типа документа минобразования">
      <column name="education_minobr_doc_type_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_minobr_doc_type"
                         columnNames="code"
                         constraintName="education_minobr_doc_type_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_minobr_doc_type" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0006" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_minprosv_doc_type" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_minprosv_doc_type" schemaName="ervu_dashboard" remarks="Справочник типа документа минпросвещения">
      <column name="education_minprosv_doc_type_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_minprosv_doc_type"
                         columnNames="code"
                         constraintName="education_minprosv_doc_type_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_minprosv_doc_type" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0007" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_minprosv_speciality" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_minprosv_speciality" schemaName="ervu_dashboard" remarks="Справочник специальности минпросвещения">
      <column name="education_minprosv_speciality_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_minprosv_speciality"
                         columnNames="code"
                         constraintName="education_minprosv_speciality_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_minprosv_speciality" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0008" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_minobr_speciality" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_minobr_speciality" schemaName="ervu_dashboard" remarks="Справочник специальности минобразования">
      <column name="education_minobr_speciality_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_minobr_speciality"
                         columnNames="code"
                         constraintName="education_minobr_speciality_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_minobr_speciality" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>


  <changeSet id="0009" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="education_institution_type" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="education_institution_type" schemaName="ervu_dashboard" remarks="Справочник типа образовательного учреждения">
      <column name="education_institution_type_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="education_institution_type"
                         columnNames="code"
                         constraintName="education_institution_type_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="education_institution_type" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0010" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="country_oksm" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="country_oksm" schemaName="ervu_dashboard" remarks="Справочник кода страны">
      <column name="country_oksm_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="code" type="varchar(15)" remarks="Cправочный код">
        <constraints nullable="false"/>
      </column>
      <column name="value" type="varchar(255)" remarks="Значение">
        <constraints nullable="false"/>
      </column>
      <column name="description" type="text" remarks="Описание"/>
      <column name="actual" type="boolean" defaultValueBoolean="true" remarks="Признак актуальности справочного значения">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addUniqueConstraint tableName="country_oksm"
                         columnNames="code"
                         constraintName="country_oksm_code_unique_key"
                         schemaName="ervu_dashboard"/>
    <rollback>
      <dropTable tableName="country_oksm" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0011" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="citizen_education" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="citizen_education" schemaName="ervu_dashboard" remarks="Сведения об образовании гражданина">
      <column name="citizen_education_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="recruit_id" type="uuid">
        <constraints nullable="false"/>
      </column>
      <column name="inn" type="varchar" remarks="ИНН"/>
      <column name="kpp" type="varchar" remarks="КПП"/>
      <column name="ogrn" type="varchar" remarks="ОГРН"/>
      <column name="educational_institution_name" type="text" remarks="Наименование образовательного учреждения"/>
      <column name="educational_institution_address" type="text" remarks="Адрес образовательного учреждения"/>
      <column name="educational_institution_type_code" type="varchar" remarks="Код типа образовательного учреждения">
        <constraints referencedTableName="education_institution_type"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_institution_type_code_fk"/>
      </column>
      <column name="education_status_code" type="varchar" remarks="Код статуса обучения">
        <constraints referencedTableName="education_status"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_status_type_code_fk"/>
      </column>
      <column name="recovery_date" type="date" remarks="Дата восстановления"/>
      <column name="recovery_order_date" type="date" remarks="Дата приказа на восстановление"/>
      <column name="recovery_order_number" type="varchar" remarks="Номер приказа на восстановление"/>
      <column name="education_level_code" type="varchar" remarks="Код уровня образования">
        <constraints referencedTableName="education_level"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_level_code_fk"/>
      </column>
      <column name="grade_number" type="varchar" remarks="Номер класса/курса"/>
      <column name="leave_start_date" type="date" remarks="Дата начала отпуска"/>
      <column name="leave_end_date" type="date" remarks="Дата окончания отпуска"/>
      <column name="leave_reason_code" type="varchar" remarks="Код причины отпуска">
        <constraints referencedTableName="education_leave_reason"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_leave_reason_code_fk"/>
      </column>
      <column name="admission_date" type="date" remarks="Дата зачисления"/>
      <column name="first_education" type="boolean" defaultValueBoolean="false" remarks="Признак получения образования впервые"/>
      <column name="vus_spec" type="boolean" defaultValueBoolean="false"
              remarks="Признак наличия специальности/направления подготовки/профессии относящейся
                       к перечню, при наличии которых граждане женского пола получают военно-учетные
                       специальности и подлежат постановке на воинский учет"/>
      <column name="education_start_date" type="date" remarks="Дата начала обучения"/>
      <column name="planned_education_end_date" type="date" remarks="Планируемая дата окончания обучения"/>
      <column name="education_form_code" type="varchar" remarks="Код формы обучения">
        <constraints referencedTableName="education_form"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_form_code_fk"/>
      </column>
      <column name="minobr_spec_code" type="varchar" remarks="Код специальности минобразования">
        <constraints referencedTableName="education_minobr_speciality"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_minobr_speciality_code_fk"/>
      </column>
      <column name="minprosv_spec_code" type="varchar" remarks="Код специальности минпросвещения">
        <constraints referencedTableName="education_minprosv_speciality"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_education_minprosv_speciality_code_fk"/>
      </column>
      <column name="expulsion_date" type="date" remarks="Дата отчисления"/>
      <column name="expulsion_order_date" type="date" remarks="Дата приказа на отчисление"/>
      <column name="expulsion_order_number" type="varchar" remarks="Номер приказа на отчисление"/>
      <column name="military_education_start_date" type="date" remarks="Дата начала обучения в военно-учебном центре"/>
      <column name="military_education_end_date" type="date" remarks="Дата окончания обучения в военно-учебном центре"/>
      <column name="admission_order_date" type="date" remarks="Дата приказа о зачислении"/>
      <column name="admission_order_number" type="varchar" remarks="Номер приказа о зачислении"/>
    </createTable>
    <rollback>
      <dropTable tableName="citizen_education" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0012" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="citizen_education_diploma" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="citizen_education_diploma" schemaName="ervu_dashboard" remarks="Диплом/аттестат гражданина">
      <column name="citizen_education_diploma_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="education_speciality_code" type="varchar" remarks="Код специальности"/>
      <column name="issue_date" type="date" remarks="Дата выдачи"/>
      <column name="education_institution_name" type="text" remarks="Наименование образовательного учреждения"/>
      <column name="education_level_code" type="varchar" remarks="Код уровня образования">
        <constraints referencedTableName="education_level"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_education_level_code_fk"/>
      </column>
      <column name="reg_number" type="varchar" remarks="Регистрационный номер документа об образовании"/>
      <column name="vus_spec" type="boolean" defaultValueBoolean="false"
              remarks="Признак наличия специальности/направления подготовки/профессии относящейся
                       к перечню, при наличии которых граждане женского пола получают
                       военно-учетные специальности и подлежат постановке на воинский учет"/>
      <column name="blank_number" type="varchar" remarks="Номер бланка документа об образовании"/>
      <column name="blank_series" type="varchar" remarks="Серия бланка документа об образовании"/>
      <column name="doc_type_code_minobr" type="varchar" remarks="Код вида документа минобразования">
        <constraints referencedTableName="education_minobr_doc_type"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_minobr_doc_type_code_fk"/>
      </column>
      <column name="doc_type_code_minprosv" type="varchar" remarks="Код вида документа минобразования">
        <constraints referencedTableName="education_minprosv_doc_type"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_doc_type_code_minprosv_code_fk"/>
      </column>
      <column name="education_speciality_minpobr_code" type="varchar" remarks="Код вида документа минобразования">
        <constraints referencedTableName="education_minobr_speciality"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_education_minobr_speciality_code_fk"/>
      </column>
      <column name="education_speciality_minprosv_code" type="varchar" remarks="Код вида документа минобразования">
        <constraints referencedTableName="education_minprosv_speciality"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_education_minprosv_speciality_code_fk"/>
      </column>
    </createTable>
    <rollback>
      <dropTable tableName="citizen_education_diploma" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0013" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <tableExists tableName="citizen_foreign_education_diploma" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>
    <createTable tableName="citizen_foreign_education_diploma" schemaName="ervu_dashboard" remarks="Иностранный диплом/аттестат гражданина">
      <column name="citizen_foreign_education_diploma_id" type="BIGSERIAL">
        <constraints primaryKey="true" nullable="false"/>
      </column>
      <column name="education_speciality_code" type="varchar" remarks="Код специальности"/>
      <column name="qualification" type="varchar" remarks="Признанная в соответствие с законодательством РФ квалификация (степень)"/>
      <column name="oksm_code" type="varchar" remarks="Код страны, выдавшей документ об иностранном образовании">
        <constraints referencedTableName="country_oksm"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_foreign_education_diploma_country_oksm_code_fk"/>
      </column>
      <column name="study_field" type="varchar"
                                 remarks="Признанное в соответствие с законодательством РФ
                                 направление подготовки по дополнительному профессиональному образованию"/>
      <column name="education_certificate_number" type="varchar"
              remarks="Уникальный номер свидетельства о признании
              иностранного документа об образовании"/>
      <column name="recognition_date" type="date" remarks="Дата признания документа об образовании"/>
      <column name="education_level_code" type="varchar" remarks="Код уровня образования">
        <constraints referencedTableName="education_level"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_education_level_code_fk"/>
      </column>
      <column name="vus_spec" type="boolean" defaultValueBoolean="false"
              remarks="Признак наличия специальности/направления подготовки/профессии относящейся
                       к перечню, при наличии которых граждане женского пола получают
                       военно-учетные специальности и подлежат постановке на воинский учет"/>
      <column name="doc_reg_num" type="varchar" remarks="Регистрационный номер документа об образовании"/>
      <column name="doc_reg_series" type="varchar" remarks="Серия документа об образовании"/>
      <column name="foreign_doc_name" type="varchar" remarks="Наименование иностранного документа"/>
      <column name="education_institution_name" type="text" remarks="Наименование образовательного учреждения"/>
      <column name="education_speciality_minpobr_code" type="varchar" remarks="Код вида документа минобразования">
        <constraints referencedTableName="education_minobr_speciality"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_foreign_education_diploma_education_minobr_speciality_code_fk"/>
      </column>
      <column name="education_speciality_minprosv_code" type="varchar" remarks="Код вида документа минобразования">
        <constraints referencedTableName="education_minprosv_speciality"
                     referencedColumnNames="code"
                     foreignKeyName="citizen_education_diploma_education_minprosv_speciality_code_fk"/>
      </column>
    </createTable>
    <rollback>
      <dropTable tableName="citizen_education_diploma" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

  <changeSet id="0014" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <columnExists tableName="citizen_education_diploma" columnName="recruit_id"/>
      </not>
    </preConditions>

    <addColumn tableName="citizen_education_diploma">
      <column name="recruit_id" type="uuid" remarks="Идентификатор рекрута">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <rollback>
      <dropColumn tableName="citizen_education_diploma" columnName="recruit_id"/>
    </rollback>
  </changeSet>

  <changeSet id="0015" author="AlexSave">
    <preConditions onFail="MARK_RAN">
      <not>
        <columnExists tableName="citizen_foreign_education_diploma" columnName="recruit_id"/>
      </not>
    </preConditions>

    <addColumn tableName="citizen_foreign_education_diploma">
      <column name="recruit_id" type="uuid" remarks="Идентификатор рекрута">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <rollback>
      <dropColumn tableName="citizen_foreign_education_diploma" columnName="recruit_id"/>
    </rollback>
  </changeSet>
</databaseChangeLog>