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
Copy file name to clipboardExpand all lines: database/migrations/20260518100544_remove_obsolete_indexes_and_columns_from_component_dependencies.down.sql
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
19
+
INSERT INTOpublic.componentsVALUES('ROOT','',NULL,NULL,NULL); -- add a ROOT component to the components table to be referenced
20
+
UPDATEpublic.component_dependenciesSET component_id ='ROOT'WHERE component_id IS NULL; -- use an explicit value for ROOT component dependencies instead of NULL
21
+
22
+
ALTERTABLEpublic.component_dependencies DROP CONSTRAINT component_dependencies_pkey, DROP COLUMN id; -- drop primary key constraint and the primary key column
23
+
24
+
-- remove all duplicate entries from the table so that the new primary key does not fail on creation
25
+
DELETEFROMpublic.component_dependencies a
26
+
USING public.component_dependencies b
27
+
WHEREa.ctid<b.ctid-- use the internal column id to choose only 1 candidate per duplicate row
28
+
ANDa.asset_id=b.asset_id
29
+
ANDa.asset_version_name=b.asset_version_name
30
+
ANDa.dependency_id=b.dependency_id
31
+
ANDa.component_id=b.component_id;
32
+
33
+
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