<?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="saliakhov">
        <comment>edit</comment>
		<sql>
			DROP VIEW IF EXISTS metrics.view_convert_info_records_from_easu;

			ALTER TABLE metrics.convert_info_records_from_easu DROP COLUMN IF EXISTS count_unique;
			ALTER TABLE metrics.convert_info_records_from_easu DROP COLUMN IF EXISTS count_all;

			ALTER TABLE metrics.convert_info_records_from_easu ADD COLUMN IF NOT EXISTS count_completed_record int8 DEFAULT 0 NOT NULL;

			CREATE OR REPLACE VIEW metrics.view_convert_info_records_from_easu
			AS SELECT convert_info_records_from_easu.convert_info_records_from_easu_id,
				convert_info_records_from_easu.count_completed_record + convert_info_records_from_easu.count_flk_and_duplicate AS count_all,
				round(convert_info_records_from_easu.count_completed_record::numeric * 100::numeric / (convert_info_records_from_easu.count_completed_record + convert_info_records_from_easu.count_flk_and_duplicate)::numeric) AS percent_completed_record,
				round(convert_info_records_from_easu.count_flk_and_duplicate::numeric * 100::numeric / (convert_info_records_from_easu.count_completed_record + convert_info_records_from_easu.count_flk_and_duplicate)::numeric) AS percent_flk_and_duplicate
			   FROM metrics.convert_info_records_from_easu;
		</sql>
	</changeSet>
	
	<changeSet id="0002" author="saliakhov">
        <comment>edit</comment>
		<sql>
			DROP VIEW IF EXISTS metrics.view_convert_info_loaded_records;  

			ALTER TABLE metrics.convert_info_loaded_records ADD COLUMN IF NOT EXISTS count_not_success int8 DEFAULT 0 NOT NULL;
			  
			CREATE OR REPLACE VIEW metrics.view_convert_info_loaded_records
			AS SELECT convert_info_loaded_records.convert_info_loaded_records_id,
				convert_info_loaded_records.count_success + convert_info_loaded_records.count_error + convert_info_loaded_records.count_not_success AS count_all,
				round(convert_info_loaded_records.count_error::numeric * 100::numeric / (convert_info_loaded_records.count_success + convert_info_loaded_records.count_error + convert_info_loaded_records.count_not_success)::numeric) AS percent_error,
				round(convert_info_loaded_records.count_success::numeric * 100::numeric / (convert_info_loaded_records.count_success + convert_info_loaded_records.count_error + convert_info_loaded_records.count_not_success)::numeric) AS percent_success,
				round(convert_info_loaded_records.count_not_success::numeric * 100::numeric / (convert_info_loaded_records.count_success + convert_info_loaded_records.count_error + convert_info_loaded_records.count_not_success)::numeric) AS percent_not_success
			   FROM metrics.convert_info_loaded_records; 
		</sql>
	</changeSet>
</databaseChangeLog>