33 lines
1.4 KiB
PL/PgSQL
33 lines
1.4 KiB
PL/PgSQL
begin;
|
|
set local lock_timeout = '5s';
|
|
set local statement_timeout = '30s';
|
|
|
|
-- Separate, versioned foundation transition. Never run from application startup.
|
|
-- Preserve every assignment; only the identity of an assignment becomes a triple.
|
|
lock table device_b2_contour_links in access exclusive mode;
|
|
create temporary table device_b2_links_before on commit drop as
|
|
select * from device_b2_contour_links;
|
|
do $$
|
|
begin
|
|
if obj_description('device_b2_contour_links'::regclass) is distinct from 'nodedc.device-b2-foundation/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)' then
|
|
raise exception 'device_b2_shared_contours_predecessor_mismatch';
|
|
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, project_id);
|
|
comment on table device_b2_contour_links is 'nodedc.device-b2-shared-contours/v1';
|
|
do $$
|
|
begin
|
|
if exists(
|
|
(select * from device_b2_links_before except all select * from device_b2_contour_links)
|
|
union all
|
|
(select * from device_b2_contour_links except all select * from device_b2_links_before)
|
|
) then
|
|
raise exception 'device_b2_shared_contours_row_preservation_failed';
|
|
end if;
|
|
end $$;
|
|
commit;
|