sql
<changeSet author="pantilimonov" id="20180327-01">
<preConditions onFail="MARK_RAN">
<sqlCheck expectedResult="0">
select sum(d) from (
select 1 d from user_sequences where sequence_name = upper('SEQ_N_KPGZ_BAN')
union all select 1 from user_tables where TABLE_NAME = upper('N_KPGZ_BAN')
union all select 1 from user_tables where TABLE_NAME = upper('N_PARTICIPANT_KPGZ_BAN')
union all select 0 from dual
);
</sqlCheck>
</preConditions>
<comment>
[4826]
Необходимо в базе данных создать таблицу для регистрации КПГЗ, относящихся к лекарственным препаратам,
и заказчиков, для которых необходимо выводить уведомление об ошибке при детализации объекта закупки, созданного в рамках 44-ФЗ.
</comment>
<sql>
<![CDATA[
create sequence eaist_nsi.seq_n_kpgz_ban
start with 1
increment by 1
maxvalue 9999999999999999999999999999
minvalue 1
nocycle
cache 100
noorder
nokeep
global;
create table eaist_nsi.n_kpgz_ban (
id number primary key using index(
create index idx_n_kpgz_ban_id on eaist_nsi.n_kpgz_ban(id)
),
created_date date not null,
deleted_date date,
entity_id number not null,
code varchar2(500 char) not null,
status number(1, 0),
notice varchar2(4000 char),
is223 number(1, 0),
reason varchar2(1 char)
);
insert /*+ with_plsql */ into eaist_nsi.n_kpgz_ban
with
function get_id(old_val in integer) return number is
begin
if old_val = 0 then
return seq_n_kpgz_ban.nextval;
else
return seq_n_kpgz_ban.currval;
end if;
end get_id;
data as (
select
get_id(0) as id,
current_date as created_date,
null as deleted_date,
get_id(1) as entity_id,
'01.02.09%' as code,
1 as status,
'Детализированный объект закупки лекарственных препаратов для учреждений ДЗМ может создаваться только в системе ЕМИАС' as notice,
0 as is223,
'' as reason
from dual
)
select * from data;
comment on column eaist_nsi.n_kpgz_ban.code is 'код КПГЗ';
comment on column eaist_nsi.n_kpgz_ban.status is '1 - активно, 0 - неактивно';
comment on column eaist_nsi.n_kpgz_ban.notice is 'Текст уведомления/ошибки';
comment on column eaist_nsi.n_kpgz_ban.is223 is '1 - 223-ФЗ , 0 - 44-ФЗ';
comment on column eaist_nsi.n_kpgz_ban.reason is 'совместимость с VersionableExt.java';
create table eaist_nsi.n_participant_kpgz_ban (
participant_id number not null,
kpgz_ban_id number not null,
deleted_date date,
constraint fk_n_part_kpgz_ban_participant foreign key(participant_id) references n_participant(id),
constraint fk_n_part_kpgz_ban_ban foreign key(kpgz_ban_id) references n_kpgz_ban(id)
);
create index eaist_nsi.idx_n_part_kpgz_ban__part_id on eaist_nsi.n_participant_kpgz_ban(participant_id);
create index eaist_nsi.idx_n_part_kpgz_ban__ban_id on eaist_nsi.n_participant_kpgz_ban(kpgz_ban_id);
comment on table eaist_nsi.n_participant_kpgz_ban is 'таблица для запрета детализации объекта закупок.
p.s. хоть фк и ссылаются на ид записей(т.к. они уникальны), надо понимать,
что поиск осуществляется по entity_id = id and deleted_date is null';
insert into n_participant_kpgz_ban
select 4103, 1, null from dual
union all
select distinct entity_id, 1, null from eaist_nsi.n_participant
where PARENT_GRBS=4103 and deleted_date is null;
]]>
</sql>
</changeSet>