<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.19.xsd">

  <changeSet id="1" author="AlexSave">
    <preConditions>
      <tableExists tableName="citizen" schemaName="ervu_dashboard"/>
      <not>
        <columnExists tableName="citizen" columnName="employed" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="active_reg_ip" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="active_parental_leave" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="self_employed" schemaName="ervu_dashboard"/>
      </not>
    </preConditions>

    <comment>add external trud flags to citizen table</comment>
    <addColumn schemaName="ervu_dashboard" tableName="citizen">
      <column name="employed" type="boolean" defaultValueBoolean="false"
              remarks="Признак трудоустройства в организацию или ИП">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <addColumn schemaName="ervu_dashboard" tableName="citizen">
      <column name="active_reg_ip" type="boolean" defaultValueBoolean="false"
              remarks="Признак наличия активного ИП">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <addColumn schemaName="ervu_dashboard" tableName="citizen">
      <column name="active_parental_leave" type="boolean" defaultValueBoolean="false"
              remarks="Признак активного отпуска по уходу за ребенком">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <addColumn schemaName="ervu_dashboard" tableName="citizen">
      <column name="self_employed" type="boolean" defaultValueBoolean="false"
              remarks="Признак наличия активной самозанятости.">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <rollback>
      <dropColumn tableName="citizen" columnName="employed" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="active_reg_ip" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="active_parental_leave" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="self_employed" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>
</databaseChangeLog>