<?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>CREATE VIEW</comment>
		<sql>
			CREATE OR REPLACE VIEW actualization.view_app_reason
			AS SELECT app_reason.app_reason_id,
				COALESCE(round(app_reason.count_place_of_stay::numeric * 100::numeric / NULLIF((app_reason.count_place_of_stay + app_reason.count_work + app_reason.count_place_of_study + app_reason.count_family_status + app_reason.count_education+count_education + app_reason.count_renaming)::numeric, 0::numeric)), 0::numeric) AS percent_place_of_stay,
				COALESCE(round(app_reason.count_work::numeric * 100::numeric / NULLIF((app_reason.count_place_of_stay + app_reason.count_work + app_reason.count_place_of_study + app_reason.count_family_status + app_reason.count_education+count_education + app_reason.count_renaming)::numeric, 0::numeric)), 0::numeric) AS percent_work,
				COALESCE(round(app_reason.count_place_of_study::numeric * 100::numeric / NULLIF((app_reason.count_place_of_stay + app_reason.count_work + app_reason.count_place_of_study + app_reason.count_family_status + app_reason.count_education+count_education + app_reason.count_renaming)::numeric, 0::numeric)), 0::numeric) AS percent_place_of_study,
				COALESCE(round(app_reason.count_family_status::numeric * 100::numeric / NULLIF((app_reason.count_place_of_stay + app_reason.count_work + app_reason.count_place_of_study + app_reason.count_family_status + app_reason.count_education+count_education + app_reason.count_renaming)::numeric, 0::numeric)), 0::numeric) AS percent_family_status,
				COALESCE(round(app_reason.count_education::numeric * 100::numeric / NULLIF((app_reason.count_place_of_stay + app_reason.count_work + app_reason.count_place_of_study + app_reason.count_family_status + app_reason.count_education+count_education + app_reason.count_renaming)::numeric, 0::numeric)), 0::numeric) AS percent_education,
				COALESCE(round(app_reason.count_renaming::numeric * 100::numeric / NULLIF((app_reason.count_place_of_stay + app_reason.count_work + app_reason.count_place_of_study + app_reason.count_family_status + app_reason.count_education+count_education + app_reason.count_renaming)::numeric, 0::numeric)), 0::numeric) AS percent_renaming
			   FROM actualization.app_reason;
		</sql>
	</changeSet>
	
	<changeSet id="0002" author="saliakhov">
        <comment>EDIT TABLE</comment>
		<sql>
			ALTER TABLE metrics.citizen_appeals 
			ALTER COLUMN average_response_time TYPE numeric(10,1);
		</sql>
	</changeSet>
</databaseChangeLog>