Skip to content
Snippets Groups Projects
Verified Commit 267cbc79 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

fossology_license: Improve add query endpoint

This also clarifies the intent.
parent 09cecc5a
No related branches found
Tags v0.0.162
1 merge request!224indexer.storage: Schema improvments
-- SWH Indexer DB schema upgrade
-- from_version: 129
-- to_version: 130
-- description:
insert into dbversion(version, release, description)
values(130, now(), 'Work In Progress');
create or replace function swh_content_fossology_license_add(conflict_update boolean)
returns void
language plpgsql
as $$
begin
-- insert unknown licenses first
insert into fossology_license (name)
select distinct license from tmp_content_fossology_license tmp
where not exists (select 1 from fossology_license where name=tmp.license)
on conflict(name) do nothing;
if conflict_update then
insert into content_fossology_license (id, license_id, indexer_configuration_id)
select tcl.id,
(select id from fossology_license where name = tcl.license) as license,
indexer_configuration_id
from tmp_content_fossology_license tcl
on conflict(id, license_id, indexer_configuration_id)
do update set license_id = excluded.license_id;
return;
end if;
insert into content_fossology_license (id, license_id, indexer_configuration_id)
select tcl.id,
(select id from fossology_license where name = tcl.license) as license,
indexer_configuration_id
from tmp_content_fossology_license tcl
on conflict(id, license_id, indexer_configuration_id)
do nothing;
return;
end
$$;
comment on function swh_content_fossology_license_add(boolean) IS 'Add new content licenses';
......@@ -14,7 +14,7 @@ create table dbversion
);
insert into dbversion(version, release, description)
values(129, now(), 'Work In Progress');
values(130, now(), 'Work In Progress');
-- Computing metadata on sha1's contents
-- a SHA1 checksum (not necessarily originating from Git)
......
......@@ -228,13 +228,14 @@ begin
on conflict(name) do nothing;
if conflict_update then
-- delete from content_fossology_license c
-- using tmp_content_fossology_license tmp, indexer_configuration i
-- where c.id = tmp.id and i.id=tmp.indexer_configuration_id
delete from content_fossology_license
where id in (select tmp.id
from tmp_content_fossology_license tmp
inner join indexer_configuration i on i.id=tmp.indexer_configuration_id);
insert into content_fossology_license (id, license_id, indexer_configuration_id)
select tcl.id,
(select id from fossology_license where name = tcl.license) as license,
indexer_configuration_id
from tmp_content_fossology_license tcl
on conflict(id, license_id, indexer_configuration_id)
do update set license_id = excluded.license_id;
return;
end if;
insert into content_fossology_license (id, license_id, indexer_configuration_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment