<?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="hairullinb">
        <comment>create column total_registered.age.convicts</comment>
		<sql>
			ALTER TABLE IF EXISTS total_registered.age 
			ADD COLUMN IF NOT EXISTS convicts VARCHAR;

			UPDATE total_registered.age
			SET convicts = 'ALL';

			ALTER TABLE IF EXISTS total_registered.age 
			DROP CONSTRAINT IF EXISTS age_pkey;

			ALTER TABLE IF EXISTS total_registered.age 
			ADD CONSTRAINT age_pkey PRIMARY KEY (registered,recruitment_id,recording_date,"all_M_W",schema,convicts);
		</sql>
	</changeSet>
	
	<changeSet id="0002" author="hairullinb">
        <comment>create column total_registered.child_minor.convicts</comment>
		<sql>
			ALTER TABLE IF EXISTS total_registered.child_minor 
			ADD COLUMN IF NOT EXISTS convicts VARCHAR;

			UPDATE total_registered.child_minor
			SET convicts = 'ALL';

			ALTER TABLE IF EXISTS total_registered.child_minor 
			DROP CONSTRAINT IF EXISTS child_minor_pkey;

			ALTER TABLE IF EXISTS total_registered.child_minor 
			ADD CONSTRAINT child_minor_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema,convicts);
		</sql>
	</changeSet>
	
	<changeSet id="0003" author="hairullinb">
        <comment>create column total_registered.marital_status.convicts</comment>
		<sql>
			ALTER TABLE IF EXISTS total_registered.marital_status 
			ADD COLUMN IF NOT EXISTS convicts VARCHAR;

			UPDATE total_registered.marital_status
			SET convicts = 'ALL';

			ALTER TABLE IF EXISTS total_registered.marital_status 
			DROP CONSTRAINT IF EXISTS marital_status_pkey;

			ALTER TABLE IF EXISTS total_registered.marital_status 
			ADD CONSTRAINT marital_status_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema,convicts);
		</sql>
	</changeSet>
	
	<changeSet id="0004" author="hairullinb">
        <comment>create column total_registered.driver_license.convicts</comment>
		<sql>
			ALTER TABLE IF EXISTS total_registered.driver_license
			ADD COLUMN IF NOT EXISTS convicts VARCHAR;

			UPDATE total_registered.driver_license
			SET convicts = 'ALL';

			ALTER TABLE IF EXISTS total_registered.driver_license 
			DROP CONSTRAINT IF EXISTS driver_license_pkey;

			ALTER TABLE IF EXISTS total_registered.driver_license 
			ADD CONSTRAINT driver_license_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema,convicts);
		</sql>
	</changeSet>
	
	<changeSet id="0005" author="hairullinb">
        <comment>create column total_registered.education_level.convicts</comment>
		<sql>
			ALTER TABLE IF EXISTS total_registered.education_level
			ADD COLUMN IF NOT EXISTS convicts VARCHAR;

			UPDATE total_registered.education_level
			SET convicts = 'ALL';

			ALTER TABLE IF EXISTS total_registered.education_level 
			DROP CONSTRAINT IF EXISTS education_level_pkey;

			ALTER TABLE IF EXISTS total_registered.education_level 
			ADD CONSTRAINT education_level_pkey PRIMARY KEY ("all_M_W",recording_date,recruitment_id,schema,convicts);
		</sql>
	</changeSet>
	
	<changeSet id="0006" author="hairullinb">
        <comment>alter column total_registered.busyness.convicts</comment>
		<sql>
			ALTER TABLE total_registered.busyness 
			DROP COLUMN IF EXISTS convicts, 
			DROP COLUMN IF EXISTS convicts_percent;

			ALTER TABLE IF EXISTS total_registered.busyness
			ADD COLUMN IF NOT EXISTS convicts VARCHAR;

			UPDATE total_registered.busyness
			SET convicts = 'ALL';

			ALTER TABLE IF EXISTS total_registered.busyness 
			DROP CONSTRAINT IF EXISTS busyness_pkey;

			ALTER TABLE IF EXISTS total_registered.busyness 
			ADD CONSTRAINT busyness_pkey PRIMARY KEY (registered,recruitment_id,recording_date,"all_M_W",schema,convicts);
		</sql>
	</changeSet>
</databaseChangeLog>
