diff --git a/database/schema/upgrade_scripts/125-delete_system_vuln_package.sql b/database/schema/upgrade_scripts/125-delete_system_vuln_package.sql new file mode 100644 index 000000000..210fb3bc1 --- /dev/null +++ b/database/schema/upgrade_scripts/125-delete_system_vuln_package.sql @@ -0,0 +1,20 @@ +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; +GRANT SELECT, DELETE ON system_vulnerable_package TO ve_db_user_manager; diff --git a/database/schema/ve_db_postgresql.sql b/database/schema/ve_db_postgresql.sql index d208b80f4..fbcf50fc9 100644 --- a/database/schema/ve_db_postgresql.sql +++ b/database/schema/ve_db_postgresql.sql @@ -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); @@ -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; @@ -701,6 +702,8 @@ 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; +GRANT SELECT, DELETE ON system_vulnerable_package TO ve_db_user_manager; -- create function to create all partitions CREATE OR REPLACE FUNCTION create_sys_vuln_pkg_partitions(parts INTEGER)