<?xml version="1.0" encoding="UTF-8"?>
<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>
        <columnExists tableName="citizen" columnName="has_disease" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="has_vich" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="registered_in_pnd" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="has_disability" schemaName="ervu_dashboard"/>
      </not>
      <not>
        <columnExists tableName="citizen" columnName="is_incompetent" schemaName="ervu_dashboard"/>
      </not>
      <tableExists tableName="citizen" schemaName="ervu_dashboard"/>
    </preConditions>

    <comment>add citizen external med flags</comment>
    <addColumn tableName="citizen" schemaName="ervu_dashboard">
      <column name="has_disease" type="boolean" defaultValueBoolean="false" remarks="Признак наличия сведений о заболеваниях">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <addColumn tableName="citizen" schemaName="ervu_dashboard">
      <column name="has_vich" type="boolean" defaultValueBoolean="false" remarks="Признак состояния на учете по ВИЧ">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <addColumn tableName="citizen" schemaName="ervu_dashboard">
      <column name="registered_in_pnd" type="boolean" defaultValueBoolean="false" remarks="Признак состояния на учете в ПНД">
        <constraints nullable="false"/>
      </column>
    </addColumn>

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

    <addColumn tableName="citizen" schemaName="ervu_dashboard">
      <column name="is_incompetent" type="boolean" defaultValueBoolean="false" remarks="Признак наличия сведений о признании недееспособным/ограниченно дееспособным">
        <constraints nullable="false"/>
      </column>
    </addColumn>

    <rollback>
      <dropColumn tableName="citizen" columnName="has_disease" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="has_vich" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="registered_in_pnd" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="has_disability" schemaName="ervu_dashboard"/>
      <dropColumn tableName="citizen" columnName="is_incompetent" schemaName="ervu_dashboard"/>
    </rollback>
  </changeSet>

</databaseChangeLog>