-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(APIv2): RHINENG-8970 implemented missing fields on rules
- Loading branch information
Showing
19 changed files
with
3,826 additions
and
2,632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE OR REPLACE FUNCTION v2_rules_delete() RETURNS trigger LANGUAGE plpgsql AS | ||
$func$ | ||
BEGIN | ||
-- Delete the rule reference record separately | ||
DELETE FROM "rule_references_containers" WHERE "rule_id" = OLD."id"; | ||
DELETE FROM "rules" WHERE "id" = OLD."id"; | ||
RETURN OLD; | ||
END | ||
$func$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
CREATE OR REPLACE FUNCTION v2_rules_insert() RETURNS trigger LANGUAGE plpgsql AS | ||
$func$ | ||
DECLARE result_id uuid; | ||
BEGIN | ||
INSERT INTO "rules" ( | ||
"ref_id", | ||
"title", | ||
"severity", | ||
"description", | ||
"rationale", | ||
"created_at", | ||
"updated_at", | ||
"remediation_available", | ||
"benchmark_id", | ||
"upstream", | ||
"precedence", | ||
"rule_group_id", | ||
"value_checks", | ||
"identifier" | ||
) VALUES ( | ||
NEW."ref_id", | ||
NEW."title", | ||
NEW."severity", | ||
NEW."description", | ||
NEW."rationale", | ||
NEW."created_at", | ||
NEW."updated_at", | ||
NEW."remediation_available", | ||
NEW."security_guide_id", | ||
NEW."upstream", | ||
NEW."precedence", | ||
NEW."rule_group_id", | ||
NEW."value_checks", | ||
NEW."identifier" | ||
) RETURNING "id" INTO "result_id"; | ||
|
||
-- Insert a new rule reference record separately | ||
INSERT INTO "rule_references_containers" ("rule_references", "rule_id", "created_at", "updated_at") | ||
SELECT NEW."references", "result_id", NOW(), NOW(); | ||
|
||
NEW."id" := "result_id"; | ||
RETURN NEW; | ||
END | ||
$func$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
CREATE OR REPLACE FUNCTION v2_rules_update() RETURNS trigger LANGUAGE plpgsql AS | ||
$func$ | ||
BEGIN | ||
-- Update the rule reference record separately | ||
UPDATE "rule_references_container" SET "rule_references" = NEW."references" WHERE "rule_id" = OLD."id"; | ||
|
||
UPDATE "rules" SET | ||
"ref_id" = NEW."ref_id", | ||
"title" = NEW."title", | ||
"severity" = NEW."severity", | ||
"description" = NEW."description", | ||
"rationale" = NEW."rationale", | ||
"created_at" = NEW."created_at", | ||
"updated_at" = NEW."updated_at", | ||
"remediation_available" = NEW."remediation_available", | ||
"benchmark_id" = NEW."security_guide_id", | ||
"upstream" = NEW."upstream", | ||
"precedence" = NEW."precedence", | ||
"rule_group_id" = NEW."rule_group_id", | ||
"value_checks" = NEW."value_checks", | ||
"identifier" = NEW."identifier" | ||
WHERE "id" = OLD."id"; | ||
|
||
RETURN NEW; | ||
END | ||
$func$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class UpdateV2RulesToVersion2 < ActiveRecord::Migration[7.1] | ||
def change | ||
|
||
update_view :v2_rules, version: 2, revert_to_version: 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CreateFunctionV2RulesInsert < ActiveRecord::Migration[7.1] | ||
def change | ||
create_function :v2_rules_insert | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CreateFunctionV2RulesUpdate < ActiveRecord::Migration[7.1] | ||
def change | ||
create_function :v2_rules_update | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CreateFunctionV2RulesDelete < ActiveRecord::Migration[7.1] | ||
def change | ||
create_function :v2_rules_delete | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CreateTriggerV2RulesInsert < ActiveRecord::Migration[7.1] | ||
def change | ||
create_trigger :v2_rules_insert, on: :v2_rules | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CreateTriggerV2RulesUpdate < ActiveRecord::Migration[7.1] | ||
def change | ||
create_trigger :v2_rules_update, on: :v2_rules | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CreateTriggerV2RulesDelete < ActiveRecord::Migration[7.1] | ||
def change | ||
create_trigger :v2_rules_delete, on: :v2_rules | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE TRIGGER "v2_rules_delete" INSTEAD OF DELETE ON "v2_rules" | ||
FOR EACH ROW EXECUTE FUNCTION v2_rules_delete(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE TRIGGER "v2_rules_insert" INSTEAD OF INSERT ON "v2_rules" | ||
FOR EACH ROW EXECUTE FUNCTION v2_rules_insert(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE TRIGGER "v2_rules_update" INSTEAD OF UPDATE ON "v2_rules" | ||
FOR EACH ROW EXECUTE FUNCTION v2_rules_update(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
SELECT | ||
"rules"."id", | ||
"rules"."ref_id", | ||
"rules"."title", | ||
"rules"."severity", | ||
"rules"."description", | ||
"rules"."rationale", | ||
"rules"."created_at", | ||
"rules"."updated_at", | ||
"rules"."remediation_available", | ||
"rules"."benchmark_id" AS "security_guide_id", | ||
"rules"."upstream", | ||
"rules"."precedence", | ||
"rules"."rule_group_id", | ||
"rules"."value_checks", | ||
"rules"."identifier", | ||
"rule_references_containers"."rule_references" AS "references" | ||
FROM "rules" LEFT OUTER JOIN "rule_references_containers" ON "rule_references_containers"."rule_id" = "rules"."id"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.