Skip to content

Commit

Permalink
fix: delete from system_vulnerable_package when deleting system
Browse files Browse the repository at this point in the history
  • Loading branch information
jdobes committed Jul 24, 2023
1 parent fd1dc0e commit 7afa0ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions database/schema/upgrade_scripts/125-delete_system_vuln_package.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE OR REPLACE FUNCTION delete_system(inventory_id_in UUID)
RETURNS TABLE (deleted_inventory_id UUID) AS
$delete_system$
DECLARE
system_id_in INT;
rh_account_id_in INT;
BEGIN
-- opt out to refresh cache and then delete
SELECT id, rh_account_id FROM system_platform WHERE inventory_id = inventory_id_in INTO system_id_in, rh_account_id_in FOR UPDATE;
UPDATE system_platform SET opt_out = true WHERE id = system_id_in;
DELETE FROM system_vulnerabilities WHERE system_id = system_id_in AND rh_account_id = rh_account_id_in;
DELETE FROM system_vulnerable_package WHERE system_id = system_id_in AND rh_account_id = rh_account_id_in;
DELETE FROM system_repo WHERE system_id = system_id_in;
RETURN QUERY DELETE FROM system_platform WHERE id = system_id_in RETURNING inventory_id;
END;
$delete_system$
LANGUAGE 'plpgsql';

GRANT SELECT, DELETE ON system_vulnerable_package TO ve_db_user_taskomatic;
4 changes: 3 additions & 1 deletion database/schema/ve_db_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CREATE TABLE IF NOT EXISTS db_version (
) TABLESPACE pg_default;

-- set the schema version directly in the insert statement here!!
INSERT INTO db_version (name, version) VALUES ('schema_version', 124);
INSERT INTO db_version (name, version) VALUES ('schema_version', 125);
-- INSERT INTO db_version (name, version) VALUES ('schema_version', :schema_version);


Expand Down Expand Up @@ -113,6 +113,7 @@ $delete_system$
SELECT id, rh_account_id FROM system_platform WHERE inventory_id = inventory_id_in INTO system_id_in, rh_account_id_in FOR UPDATE;
UPDATE system_platform SET opt_out = true WHERE id = system_id_in;
DELETE FROM system_vulnerabilities WHERE system_id = system_id_in AND rh_account_id = rh_account_id_in;
DELETE FROM system_vulnerable_package WHERE system_id = system_id_in AND rh_account_id = rh_account_id_in;
DELETE FROM system_repo WHERE system_id = system_id_in;
RETURN QUERY DELETE FROM system_platform WHERE id = system_id_in RETURNING inventory_id;
END;
Expand Down Expand Up @@ -701,6 +702,7 @@ CREATE TABLE IF NOT EXISTS system_vulnerable_package (
) PARTITION BY HASH (rh_account_id);

GRANT SELECT, INSERT, UPDATE, DELETE ON system_vulnerable_package TO ve_db_user_evaluator;
GRANT SELECT, DELETE ON system_vulnerable_package TO ve_db_user_taskomatic;

-- create function to create all partitions
CREATE OR REPLACE FUNCTION create_sys_vuln_pkg_partitions(parts INTEGER)
Expand Down

0 comments on commit 7afa0ca

Please sign in to comment.