<?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="e.makarova">
        <comment>create_link_user_application_ip_address</comment>
        <sql>
		CREATE TABLE IF NOT EXISTS public.link_user_application_ip_address
		(
		link_user_application_ip_address_id bigserial,
		user_application_list_id bigint NOT NULL,
		ip_address character varying COLLATE pg_catalog."default" NOT NULL,
		CONSTRAINT pk_link_user_application_ip_address PRIMARY KEY (link_user_application_ip_address_id),
		CONSTRAINT ip_address UNIQUE (user_application_list_id, ip_address),
		CONSTRAINT fk1_user_application_list FOREIGN KEY (user_application_list_id)
        REFERENCES public.user_application_list (user_application_list_id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE CASCADE
		)

		TABLESPACE pg_default;

		ALTER TABLE IF EXISTS public.link_user_application_ip_address
		OWNER to ervu_account_applications;

		GRANT ALL ON TABLE public.link_user_application_ip_address TO ervu_account_applications;

		COMMENT ON TABLE public.link_user_application_ip_address
		IS 'Таблица связи заявок и ip адрессов пользователя';

		COMMENT ON COLUMN public.link_user_application_ip_address.user_application_list_id
		IS 'Идентификатор списка заявок пользователя';

		COMMENT ON COLUMN public.link_user_application_ip_address.ip_address
		IS 'ip адресс';	
        </sql>
    </changeSet>
    <changeSet id="0002" author="e.makarova">
    <comment>drop columns ip_address and ip_address_additional</comment>
	<sql>
        ALTER TABLE IF EXISTS public.user_application_list DROP COLUMN ip_address;
		ALTER TABLE IF EXISTS public.user_application_list DROP COLUMN ip_address_additional;
	</sql>
  </changeSet>
</databaseChangeLog>