<?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="r.gaztdinov">
    <!--<comment>RENAME COLUMN testspring_autumn</comment>-->
	<preConditions onFail="MARK_RAN">
      <sqlCheck expectedResult="1">
        SELECT count(*)
		FROM information_schema.columns
		WHERE table_schema = 'recruitment_campaign'
		AND table_name = 'postponement_info'
		AND column_name = 'testspring_autumn';
      </sqlCheck>
    </preConditions>
    <sql dbms="postgresql">
	    ALTER TABLE recruitment_campaign.postponement_info
        RENAME COLUMN testspring_autumn TO spring_autumn;
    </sql>
  </changeSet>
  
  <changeSet id="0002" author="r.gaztdinov" dbms="postgresql">
    <comment>change for lvls table total_registered.age</comment>
    <sql>
      -- таблица ervu_dashboard.recruitment
    ALTER TABLE ratings.appear_subppoena
      DROP CONSTRAINT IF EXISTS appear_subppoena_fk1;
    ALTER TABLE ratings.conscription_info
      DROP CONSTRAINT IF EXISTS conscription_info_fk1;
      ALTER TABLE ervu_dashboard.recruitment
        DROP CONSTRAINT IF EXISTS recruitment_pkey;
      ALTER TABLE ervu_dashboard.recruitment
		ALTER COLUMN parent_id TYPE uuid
		USING parent_id::uuid;
      ALTER TABLE ervu_dashboard.recruitment
		ALTER COLUMN id TYPE uuid
		USING id::uuid;
      ALTER TABLE ervu_dashboard.recruitment
		ALTER COLUMN idm_id TYPE uuid
		USING idm_id::uuid;
      ALTER TABLE ervu_dashboard.recruitment
        ADD CONSTRAINT recruitment_pkey PRIMARY KEY (idm_id);
      ALTER TABLE ervu_dashboard.recruitment
		ADD COLUMN IF NOT EXISTS updated_at timestamp without time zone;
      ALTER TABLE ervu_dashboard.recruitment
		ADD COLUMN IF NOT EXISTS schema character varying(64);

      -- main_dashboard.appeals
      DELETE FROM main_dashboard.appeals;
      ALTER TABLE IF EXISTS main_dashboard.appeals
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN main_dashboard.appeals.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE main_dashboard.appeals
        DROP CONSTRAINT IF EXISTS appeals_pkey;
      ALTER TABLE main_dashboard.appeals
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE main_dashboard.appeals
        ADD CONSTRAINT appeals_pkey PRIMARY KEY (recruitment_id,recording_date,schema);

      -- main_dashboard.recruitment_campaign
      DELETE FROM main_dashboard.recruitment_campaign;
      ALTER TABLE IF EXISTS main_dashboard.recruitment_campaign
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN main_dashboard.recruitment_campaign.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE main_dashboard.recruitment_campaign
        DROP CONSTRAINT IF EXISTS recruitment_campaign_pkey;
      ALTER TABLE main_dashboard.recruitment_campaign
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE main_dashboard.recruitment_campaign
        ADD CONSTRAINT recruitment_campaign_pkey PRIMARY KEY (recruitment_id,recording_date,schema,spring_autumn);

      -- main_dashboard.total_registered
      DELETE FROM main_dashboard.total_registered;
      ALTER TABLE IF EXISTS main_dashboard.total_registered
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN main_dashboard.total_registered.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE main_dashboard.total_registered
        DROP CONSTRAINT IF EXISTS total_registered_pkey;
      ALTER TABLE main_dashboard.total_registered
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE main_dashboard.total_registered
        ADD CONSTRAINT total_registered_pkey PRIMARY KEY (recruitment_id,recording_date,schema);

      -- main_dashboard.waiting_registration
      DELETE FROM main_dashboard.waiting_registration;
      ALTER TABLE IF EXISTS main_dashboard.waiting_registration
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN main_dashboard.waiting_registration.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE main_dashboard.waiting_registration
        DROP CONSTRAINT IF EXISTS waiting_registration_pkey;
      ALTER TABLE main_dashboard.waiting_registration
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE main_dashboard.waiting_registration
        ADD CONSTRAINT waiting_registration_pkey PRIMARY KEY (recruitment_id,recording_date,schema);


      -- recruitment_campaign.appeals
      DELETE FROM recruitment_campaign.appeals;
      ALTER TABLE IF EXISTS recruitment_campaign.appeals
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN recruitment_campaign.appeals.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE recruitment_campaign.appeals
        DROP CONSTRAINT IF EXISTS appeals_pkey;
      ALTER TABLE recruitment_campaign.appeals
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE recruitment_campaign.appeals
        ADD CONSTRAINT appeals_pkey PRIMARY KEY (recording_date,spring_autumn,recruitment_id,schema);

      -- recruitment_campaign.subpoenas
      DELETE FROM recruitment_campaign.subpoenas;
      ALTER TABLE IF EXISTS recruitment_campaign.subpoenas
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN recruitment_campaign.subpoenas.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE recruitment_campaign.subpoenas
        DROP CONSTRAINT IF EXISTS subpoenas_pkey;
      ALTER TABLE recruitment_campaign.subpoenas
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE recruitment_campaign.subpoenas
        ADD CONSTRAINT subpoenas_pkey PRIMARY KEY (recording_date,spring_autumn,recruitment_id,schema);

      -- total_registered.age
      DELETE FROM total_registered.age;
      ALTER TABLE IF EXISTS total_registered.age
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      ALTER TABLE IF EXISTS total_registered.age
		ADD COLUMN IF NOT EXISTS total_count numeric;
      COMMENT ON COLUMN total_registered.age.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.age
        DROP CONSTRAINT IF EXISTS age_pkey;
      ALTER TABLE total_registered.age
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.age
        ADD CONSTRAINT age_pkey PRIMARY KEY (registered,recruitment_id,recording_date,"all_M_W",schema);

      -- total_registered.busyness
      DELETE FROM total_registered.busyness;
	  ALTER TABLE IF EXISTS total_registered.busyness
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN total_registered.busyness.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.busyness
        DROP CONSTRAINT IF EXISTS busyness_pkey;
      ALTER TABLE total_registered.busyness
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.busyness
        ADD CONSTRAINT busyness_pkey PRIMARY KEY (registered,recruitment_id,recording_date,"all_M_W",schema);

      -- total_registered.child_minor
      DELETE FROM total_registered.child_minor;
      ALTER TABLE IF EXISTS total_registered.child_minor
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      ALTER TABLE IF EXISTS total_registered.child_minor
		ADD COLUMN IF NOT EXISTS total_count numeric;
      COMMENT ON COLUMN total_registered.child_minor.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.child_minor
        DROP CONSTRAINT IF EXISTS child_minor_pkey;
      ALTER TABLE total_registered.child_minor
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.child_minor
        ADD CONSTRAINT child_minor_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema);

      -- total_registered.driver_license
      DELETE FROM total_registered.driver_license;
      ALTER TABLE IF EXISTS total_registered.driver_license
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      ALTER TABLE IF EXISTS total_registered.driver_license
		ADD COLUMN IF NOT EXISTS total_count numeric;
      COMMENT ON COLUMN total_registered.driver_license.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.driver_license
        DROP CONSTRAINT IF EXISTS driver_license_pkey;
      ALTER TABLE total_registered.driver_license
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.driver_license
        ADD CONSTRAINT driver_license_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema);

      -- total_registered.education_level
      DELETE FROM total_registered.education_level;
      ALTER TABLE IF EXISTS total_registered.education_level
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN total_registered.education_level.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.education_level
        DROP CONSTRAINT IF EXISTS education_level_pkey;
      ALTER TABLE total_registered.education_level
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.education_level
        ADD CONSTRAINT education_level_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema);

      -- total_registered.marital_status
      DELETE FROM total_registered.marital_status;
      ALTER TABLE IF EXISTS total_registered.marital_status
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN total_registered.marital_status.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.marital_status
        DROP CONSTRAINT IF EXISTS marital_status_pkey;
      ALTER TABLE total_registered.marital_status
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.marital_status
        ADD CONSTRAINT marital_status_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema);

      -- total_registered.reg_mil_cat
      DELETE FROM total_registered.reg_mil_cat;
      ALTER TABLE IF EXISTS total_registered.reg_mil_cat
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN total_registered.reg_mil_cat.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.reg_mil_cat
        DROP CONSTRAINT IF EXISTS reg_mil_cat_pkey;
      ALTER TABLE total_registered.reg_mil_cat
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.reg_mil_cat
        ADD CONSTRAINT reg_mil_cat_pkey PRIMARY KEY (mil_reg,recruitment_id,recording_date,schema);

      -- total_registered.removed_registry
      DELETE FROM total_registered.removed_registry;
      ALTER TABLE IF EXISTS total_registered.removed_registry
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN total_registered.removed_registry.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.removed_registry
        DROP CONSTRAINT IF EXISTS removed_registry_pkey;
      ALTER TABLE total_registered.removed_registry
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.removed_registry
        ADD CONSTRAINT removed_registry_pkey PRIMARY KEY (recruitment_id,recording_date,schema);

      -- total_registered.subpoenas
      DELETE FROM total_registered.subpoenas;
      ALTER TABLE IF EXISTS total_registered.subpoenas
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN total_registered.subpoenas.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE total_registered.subpoenas
        DROP CONSTRAINT IF EXISTS subpoenas_pkey;
      ALTER TABLE total_registered.subpoenas
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE total_registered.subpoenas
        ADD CONSTRAINT subpoenas_pkey PRIMARY KEY (mil_reg,recruitment_id,recording_date,schema);

      -- изменения в таблицы, в которых нет данных

      -- recruitment_campaign.postponement_info
      DELETE FROM recruitment_campaign.postponement_info;
      ALTER TABLE IF EXISTS recruitment_campaign.postponement_info
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN recruitment_campaign.postponement_info.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE recruitment_campaign.postponement_info
        DROP CONSTRAINT IF EXISTS pk_postponement_info;
      ALTER TABLE recruitment_campaign.postponement_info
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
	  ALTER TABLE recruitment_campaign.postponement_info
		ALTER COLUMN spring_autumn TYPE character varying;
      ALTER TABLE recruitment_campaign.postponement_info
		ADD CONSTRAINT pk_postponement_info PRIMARY KEY (recruitment_id,recording_date,spring_autumn,schema);

      -- appeals.main_profile
      DELETE FROM appeals.main_profile;
      ALTER TABLE IF EXISTS appeals.main_profile
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN appeals.main_profile.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE appeals.main_profile
        DROP CONSTRAINT IF EXISTS pk_main_profile;
      ALTER TABLE appeals.main_profile
        DROP CONSTRAINT IF EXISTS main_profile_fk1;
      ALTER TABLE appeals.main_profile
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE appeals.main_profile
        ADD CONSTRAINT pk_main_profile PRIMARY KEY (recruitment_id,recording_date,schema);

      -- appeals.reasons_appeal
      DELETE FROM appeals.reasons_appeal;
      ALTER TABLE IF EXISTS appeals.reasons_appeal
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN appeals.reasons_appeal.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE appeals.reasons_appeal
        DROP CONSTRAINT IF EXISTS pk_reasons_appeal;
      ALTER TABLE appeals.reasons_appeal
        DROP CONSTRAINT IF EXISTS reasons_appeal_fk1;      
      ALTER TABLE appeals.reasons_appeal
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE appeals.reasons_appeal
        ADD CONSTRAINT pk_reasons_appeal PRIMARY KEY (recruitment_id,recording_date,schema);

      -- appeals.review_rating
      DELETE FROM appeals.review_rating;
	  ALTER TABLE IF EXISTS appeals.review_rating
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN appeals.review_rating.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE appeals.review_rating
        DROP CONSTRAINT IF EXISTS pk_review_rating;
      ALTER TABLE appeals.review_rating
        DROP CONSTRAINT IF EXISTS review_rating_fk1;
      ALTER TABLE appeals.review_rating
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE appeals.review_rating
        ADD CONSTRAINT pk_review_rating PRIMARY KEY (recruitment_id,recording_date,schema);

      -- appeals.topic_appeal
      DELETE FROM appeals.topic_appeal;
      ALTER TABLE IF EXISTS appeals.topic_appeal
		ADD COLUMN IF NOT EXISTS schema character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'empty'::character varying;
      COMMENT ON COLUMN appeals.topic_appeal.schema
        IS '''Department'' - обычный ВК, ''Organization'' - главный ВК региона, ''Region'' - главный ВК военного округа,
        ''Ministry'' - уровень РФ, ''REG_LVL'' - сумма всех ВК региона, ''MD_LVL'' - сумма всех ВК ВО, ''Country'' - все ВК РФ';
      ALTER TABLE appeals.topic_appeal
        DROP CONSTRAINT IF EXISTS pk_topic_appeal;
      ALTER TABLE appeals.topic_appeal
        DROP CONSTRAINT IF EXISTS topic_appeal_fk1;
      ALTER TABLE appeals.topic_appeal
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE appeals.topic_appeal
        ADD CONSTRAINT pk_topic_appeal PRIMARY KEY (recruitment_id,recording_date,schema);

      -- ratings.appear_subppoena
      DELETE FROM ratings.appear_subppoena;
      ALTER TABLE ratings.appear_subppoena
        DROP CONSTRAINT IF EXISTS pk_appear_subppoena;
      ALTER TABLE ratings.appear_subppoena
        DROP CONSTRAINT IF EXISTS appear_subppoena_fk1;      
      ALTER TABLE ratings.appear_subppoena
        DROP COLUMN IF EXISTS id_region;
      ALTER TABLE IF EXISTS ratings.appear_subppoena
		ADD COLUMN id_region uuid;
      ALTER TABLE ratings.appear_subppoena
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE ratings.appear_subppoena
      ALTER COLUMN recording_date SET DEFAULT NOW()::DATE;
      ALTER TABLE ratings.appear_subppoena
        ADD CONSTRAINT pk_appear_subppoena PRIMARY KEY (id_region,recording_date);

      -- ratings.conscription_info
      DELETE FROM ratings.conscription_info;
      ALTER TABLE ratings.conscription_info
        DROP CONSTRAINT IF EXISTS pk_conscription_info;
      ALTER TABLE ratings.conscription_info
        DROP CONSTRAINT IF EXISTS r_recruitment_fk1;        
      ALTER TABLE ratings.conscription_info
        DROP COLUMN IF EXISTS id_region;
      ALTER TABLE IF EXISTS ratings.conscription_info
		ADD COLUMN id_region uuid;
      ALTER TABLE ratings.conscription_info
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE ratings.conscription_info
      ALTER COLUMN recording_date SET DEFAULT NOW()::DATE;
      ALTER TABLE ratings.conscription_info
        ADD CONSTRAINT pk_conscription_info PRIMARY KEY (id_region,recording_date,spring_autumn);

      -- ratings.consideration_complaint
      DELETE FROM ratings.consideration_complaint;
      ALTER TABLE ratings.consideration_complaint
        DROP CONSTRAINT IF EXISTS pk_consideration_complaint;
      ALTER TABLE ratings.consideration_complaint
        DROP CONSTRAINT IF EXISTS consideration_complaint_fk1;
      ALTER TABLE ratings.consideration_complaint
        DROP COLUMN IF EXISTS id_region;
      ALTER TABLE IF EXISTS ratings.consideration_complaint
		ADD COLUMN id_region uuid;
      ALTER TABLE ratings.consideration_complaint
		ALTER COLUMN recruitment_id TYPE uuid
		USING recruitment_id::uuid;
      ALTER TABLE ratings.consideration_complaint
      ALTER COLUMN recording_date SET DEFAULT NOW()::DATE;
      ALTER TABLE ratings.consideration_complaint
		ADD CONSTRAINT pk_consideration_complaint PRIMARY KEY (id_region,recording_date);
    </sql>
  </changeSet>
    
  <changeSet id="0003" author="r.gaztdinov" dbms="postgresql">
    <comment>add tables ervu_dashboard.array_mildis, ervu_dashboard.array_reg</comment>
    <sql>
      -- создание таблицы для массива военных округов
      CREATE TABLE IF NOT EXISTS ervu_dashboard.array_mildis
      (
        recruitment_dstr_id uuid NOT NULL,
        reg_array_id character varying,
        CONSTRAINT array_mildis_pkey PRIMARY KEY (recruitment_dstr_id)
      )
      TABLESPACE pg_default;
      ALTER TABLE IF EXISTS ervu_dashboard.array_mildis
      OWNER to "ervu-dashboard";

      -- создание таблицы для массива регионов
      CREATE TABLE IF NOT EXISTS ervu_dashboard.array_reg
      (
        recruitment_reg_id uuid NOT NULL,
        vk_array_id character varying,
        CONSTRAINT array_reg_pkey PRIMARY KEY (recruitment_reg_id)
      )
      TABLESPACE pg_default;
      ALTER TABLE IF EXISTS ervu_dashboard.array_reg
      OWNER to "ervu-dashboard";
    </sql>
  </changeSet>
</databaseChangeLog>
