21 lines
1010 B
PL/PgSQL
21 lines
1010 B
PL/PgSQL
begin;
|
|
set local lock_timeout = '5s';
|
|
set local statement_timeout = '30s';
|
|
lock table device_b2_contour_links in access exclusive mode;
|
|
do $$
|
|
begin
|
|
if obj_description('device_b2_contour_links'::regclass) is distinct from 'nodedc.device-b2-shared-contours/v1'
|
|
or (select pg_get_constraintdef(oid) from pg_constraint
|
|
where conrelid='device_b2_contour_links'::regclass and contype='p')
|
|
is distinct from 'PRIMARY KEY (source_id, contour_id, project_id)' then
|
|
raise exception 'device_b2_shared_contours_rollback_predecessor_mismatch';
|
|
end if;
|
|
if exists(select 1 from device_b2_contour_links group by source_id,contour_id having count(*)>1) then
|
|
raise exception 'device_b2_shared_contours_rollback_would_lose_links';
|
|
end if;
|
|
end $$;
|
|
alter table device_b2_contour_links drop constraint device_b2_contour_links_pkey;
|
|
alter table device_b2_contour_links add primary key (source_id, contour_id);
|
|
comment on table device_b2_contour_links is 'nodedc.device-b2-foundation/v1';
|
|
commit;
|