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

	
	<changeSet id="0001" author="hairullin">
        <comment>ALTER VIEW registration_change_address.view_personal_info_stat</comment>
		<sql>
			 CREATE OR REPLACE VIEW registration_change_address.view_personal_info_stat
			 AS
			 SELECT personal_info_stat.personal_info_stat_id,
				personal_info_stat.count_refused + personal_info_stat.count_accepted_to_send + personal_info_stat.count_unloaded AS count_all,
				COALESCE(round(personal_info_stat.count_refused::numeric * 100::numeric / NULLIF((personal_info_stat.count_refused + personal_info_stat.count_accepted_to_send + personal_info_stat.count_unloaded)::numeric, 0::numeric)), 0::numeric) AS percent_refused,
				COALESCE(round(personal_info_stat.count_unloaded::numeric * 100::numeric / NULLIF((personal_info_stat.count_refused + personal_info_stat.count_accepted_to_send + personal_info_stat.count_unloaded)::numeric, 0::numeric)), 0::numeric) AS percent_unloaded,
				COALESCE(round(personal_info_stat.count_accepted_to_send::numeric * 100::numeric / NULLIF((personal_info_stat.count_refused + personal_info_stat.count_accepted_to_send + personal_info_stat.count_unloaded)::numeric, 0::numeric)), 0::numeric) AS percent_accepted_to_send
			   FROM registration_change_address.personal_info_stat;

			ALTER TABLE registration_change_address.view_personal_info_stat
				OWNER TO ervu_business_metrics;
		</sql>
	</changeSet>
	
	
	<changeSet id="0002" author="hairullin">
        <comment>CREATE TABLE idm_reconcile.account_blocked</comment>
		<sql>
				CREATE TABLE IF NOT EXISTS idm_reconcile.account_blocked
			(
				account_id character varying(36) COLLATE pg_catalog."default" NOT NULL,
				blocked boolean default 'false',
				CONSTRAINT account_blocked_pkey PRIMARY KEY (account_id)
			)
			TABLESPACE pg_default;
			ALTER TABLE IF EXISTS idm_reconcile.account_blocked
				OWNER to ervu_business_metrics;
		</sql>
	</changeSet>
</databaseChangeLog>