Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete from system_vulnerable_package when deleting system #1465

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 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,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;
5 changes: 4 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,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)
Expand Down