<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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-latest.xsd">

  <changeSet id="0001" author="Artyom Hackimullin">
    <preConditions onFail="MARK_RAN">
      <sqlCheck expectedResult="0">
        SELECT COUNT(*) FROM pg_roles WHERE rolname = 'ervu-dashboard';
      </sqlCheck>
    </preConditions>
    <sql dbms="postgresql">
      CREATE ROLE "ervu-dashboard" WITH
        LOGIN
        NOSUPERUSER
        INHERIT
        NOCREATEDB
        NOCREATEROLE
        NOREPLICATION
        PASSWORD 'ervu-dashboard';
    </sql>
  </changeSet>

  <changeSet id="0002" author="Artyom Hackimullin">
    <preConditions onFail="MARK_RAN">
      <sqlCheck expectedResult="1">
        SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name LIKE 'ervu_dashboard';
      </sqlCheck>
      <sqlCheck expectedResult="0">
        SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name IN ('appeals', 'main_dashboard',
        'ratings', 'recruitment_campaign', 'space', 'total_registered');
      </sqlCheck>
    </preConditions>
    <sqlFile path="../sql_files/ervu-dashboard-copy.sql" relativeToChangelogFile="true"/>
  </changeSet>

  <changeSet id="0003" author="Artyom Hackimullin">
    <preConditions onFail="MARK_RAN">
      <sqlCheck expectedResult="0">
        SELECT COUNT(*) FROM ervu_dashboard.pub_recruitment;
      </sqlCheck>
    </preConditions>
    <sql dbms="postgresql">
      INSERT INTO ervu_dashboard.pub_recruitment (idm_id, parent_id, military_code, shortname,
                                                  fullname, code, id, sort)
      VALUES ('0340dea4-bf2d-4591-be09-987f7e79d0b4', '76e40191-adc7-4f03-84a4-0c29c44961a7',
              '00012345', 'Сахалинская область',
              'Военный комиссариат Сахалинской области', '65',
              '6b56f46a-16e7-4c0f-83a8-05fbddf2e6cb', '4'),
             ('3f1d6fb7-c9a8-4692-b292-e7a3732c1aff', '76e40191-adc7-4f03-84a4-0c29c44961a7',
              '08400325', 'Рязанская область',
              'Военный комиссариат Рязанской области, г. Рязань', '62',
              'd2e839ef-933c-48df-9a3a-ac1c00663154', '3'),
             ('08ce08c9-3595-4c36-bd14-8deda575d822', null, '000000010', 'Российская Федерация',
              'Российская Федерация', '00',
              '76e40191-adc7-4f03-84a4-0c29c44961a7', '1'),
             ('b16c8334-07a5-43e0-8c6f-bc07830fb096', '76e40191-adc7-4f03-84a4-0c29c44961a7',
              '07706878', 'Республика Марий Эл',
              'Военный комиссариат Республики Марий Эл', '12',
              '794ed0fa-a25b-4858-b89e-815bb391f2b5', '2');
    </sql>
  </changeSet>
</databaseChangeLog>