You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DROPINDEX IF EXISTS idx_component_dependencies_component_purl;
6
+
DROPINDEX IF EXISTS component_purl_idx;
7
+
DROPINDEX IF EXISTS asset_version_name_idx;
8
+
DROPINDEX IF EXISTS idx_component_dependencies_dependency_purl;
9
+
DROPINDEX IF EXISTS idx_component_dependencies_null_roots;
10
+
DROPINDEX IF EXISTS asset_id_idx;
11
+
DROPINDEX IF EXISTS idx_component_dependencies_component_id;
12
+
DROPINDEX IF EXISTS idx_component_dependencies_dependency_id;
13
+
DROPINDEX IF EXISTS idx_component_dependencies_recursive_lookup;
14
+
DROPINDEX IF EXISTS dependency_purl_idx;
15
+
16
+
-- remove the current id column and replace it with a composite key on all columns to make enforce deduplication on a data level and reduce complexity (also on indexes)
17
+
18
+
-- currently component_id can be NULL if its a root node; but primary keys cannot contain NULL values, so we replace it with a ROOT constant
VALUES('ROOT','',NULL,NULL,NULL) ON CONFLICT (id) DO NOTHING; -- add a ROOT component to the components table to be referenced
21
+
22
+
UPDATEpublic.component_dependenciesSET component_id ='ROOT'WHERE component_id IS NULL; -- use an explicit value for ROOT component dependencies instead of NULL
23
+
24
+
ALTERTABLEpublic.component_dependencies DROP CONSTRAINT component_dependencies_pkey, DROP COLUMN id; -- drop primary key constraint and the primary key column
25
+
26
+
-- remove all duplicate entries from the table so that the new primary key does not fail on creation
27
+
DELETEFROMpublic.component_dependencies a
28
+
USING public.component_dependencies b
29
+
WHEREa.ctid<b.ctid-- use the internal column id to choose only 1 candidate per duplicate row
30
+
ANDa.asset_id=b.asset_id
31
+
ANDa.asset_version_name=b.asset_version_name
32
+
ANDa.dependency_id=b.dependency_id
33
+
ANDa.component_id=b.component_id;
34
+
35
+
ALTERTABLEpublic.component_dependencies ADD PRIMARY KEY (asset_id, asset_version_name, dependency_id, component_id); -- add the new primary key consisting of all 4 attributes
0 commit comments