-
Notifications
You must be signed in to change notification settings - Fork 199
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
Feature/implement risk rule ( WIP ) BAL-2445 #2528
Open
Blokh
wants to merge
10
commits into
dev
Choose a base branch
from
feature/implement_risk_rule
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05d6dac
create risk rule policy and risk ruleset
Blokh f72c12b
feat: generated schema, services, modules, typeboxes for rule engine …
Blokh c27a411
updated sprisma schema and services
Blokh e7e1066
feat(added rules swagger): added rules swagger
Blokh a0d8f96
feat: ran format
Blokh 3c2c215
Merge branch 'dev' into feature/implement_risk_rule
Blokh 2b51595
updated data modeling ofr rule set logic
Blokh 62b007f
feat: fnished create rules CRUD
Blokh ad7fa9c
Feature/impelemnt rules mapping (#2644)
Blokh 1d56a23
feat: fixed rules logic mapping logic
Blokh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Submodule data-migrations
updated
from 24b233 to 971b89
162 changes: 162 additions & 0 deletions
162
...rvice/prisma/migrations/20240717150250_craete_rules_with_ruleset_and_policy/migration.sql
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,162 @@ | ||
-- CreateEnum | ||
CREATE TYPE "IndicatorRiskLevel" AS ENUM ('positive', 'moderate', 'critical'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "RuleEngine" AS ENUM ('Ballerine', 'JsonLogic'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "RulesetOperator" AS ENUM ('and', 'or'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "WorkflowDefinitionRiskRulePolicy" ( | ||
"id" TEXT NOT NULL, | ||
"workflowDefinitionId" TEXT NOT NULL, | ||
"riskRulesPolicyId" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "WorkflowDefinitionRiskRulePolicy_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "RiskRuleSetRule" ( | ||
"id" TEXT NOT NULL, | ||
"riskRuleSetId" TEXT NOT NULL, | ||
"ruleId" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "RiskRuleSetRule_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "RiskRulesPolicy" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"projectId" TEXT NOT NULL, | ||
"isPublic" BOOLEAN NOT NULL DEFAULT false, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "RiskRulesPolicy_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "RiskRuleSet" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"riskRulePolicyId" TEXT NOT NULL, | ||
"operator" "RulesetOperator" NOT NULL, | ||
"projectId" TEXT, | ||
"isPublic" BOOLEAN NOT NULL DEFAULT false, | ||
"domain" TEXT NOT NULL, | ||
"indicator" TEXT NOT NULL, | ||
"riskLevel" "IndicatorRiskLevel" NOT NULL, | ||
"baseRiskScore" INTEGER NOT NULL, | ||
"additionalRiskScore" INTEGER NOT NULL, | ||
"minRiskScore" INTEGER, | ||
"maxRiskScore" INTEGER, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"ruleId" TEXT, | ||
|
||
CONSTRAINT "RiskRuleSet_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Rule" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"projectId" TEXT, | ||
"isPublic" BOOLEAN NOT NULL DEFAULT false, | ||
"key" TEXT NOT NULL, | ||
"operator" TEXT NOT NULL, | ||
"comparisonValue" JSONB NOT NULL, | ||
"engine" "RuleEngine" NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Rule_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "_riskRuleSetRules" ( | ||
"A" TEXT NOT NULL, | ||
"B" TEXT NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "WorkflowDefinitionRiskRulePolicy_workflowDefinitionId_key" ON "WorkflowDefinitionRiskRulePolicy"("workflowDefinitionId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "WorkflowDefinitionRiskRulePolicy_workflowDefinitionId_idx" ON "WorkflowDefinitionRiskRulePolicy"("workflowDefinitionId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "WorkflowDefinitionRiskRulePolicy_riskRulesPolicyId_idx" ON "WorkflowDefinitionRiskRulePolicy"("riskRulesPolicyId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "WorkflowDefinitionRiskRulePolicy_workflowDefinitionId_riskR_key" ON "WorkflowDefinitionRiskRulePolicy"("workflowDefinitionId", "riskRulesPolicyId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "RiskRuleSetRule_riskRuleSetId_idx" ON "RiskRuleSetRule"("riskRuleSetId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "RiskRuleSetRule_ruleId_idx" ON "RiskRuleSetRule"("ruleId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "RiskRuleSetRule_riskRuleSetId_ruleId_key" ON "RiskRuleSetRule"("riskRuleSetId", "ruleId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "RiskRulesPolicy_projectId_idx" ON "RiskRulesPolicy"("projectId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "RiskRuleSet_riskRulePolicyId_idx" ON "RiskRuleSet"("riskRulePolicyId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "RiskRuleSet_id_riskRulePolicyId_key" ON "RiskRuleSet"("id", "riskRulePolicyId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "_riskRuleSetRules_AB_unique" ON "_riskRuleSetRules"("A", "B"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "_riskRuleSetRules_B_index" ON "_riskRuleSetRules"("B"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "WorkflowDefinitionRiskRulePolicy" ADD CONSTRAINT "WorkflowDefinitionRiskRulePolicy_riskRulesPolicyId_fkey" FOREIGN KEY ("riskRulesPolicyId") REFERENCES "RiskRulesPolicy"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "WorkflowDefinitionRiskRulePolicy" ADD CONSTRAINT "WorkflowDefinitionRiskRulePolicy_workflowDefinitionId_fkey" FOREIGN KEY ("workflowDefinitionId") REFERENCES "WorkflowDefinition"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "RiskRuleSetRule" ADD CONSTRAINT "RiskRuleSetRule_riskRuleSetId_fkey" FOREIGN KEY ("riskRuleSetId") REFERENCES "RiskRuleSet"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "RiskRuleSetRule" ADD CONSTRAINT "RiskRuleSetRule_ruleId_fkey" FOREIGN KEY ("ruleId") REFERENCES "Rule"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "RiskRulesPolicy" ADD CONSTRAINT "RiskRulesPolicy_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "RiskRuleSet" ADD CONSTRAINT "RiskRuleSet_riskRulePolicyId_fkey" FOREIGN KEY ("riskRulePolicyId") REFERENCES "RiskRulesPolicy"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Rule" ADD CONSTRAINT "Rule_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_riskRuleSetRules" ADD CONSTRAINT "_riskRuleSetRules_A_fkey" FOREIGN KEY ("A") REFERENCES "RiskRuleSet"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "_riskRuleSetRules" ADD CONSTRAINT "_riskRuleSetRules_B_fkey" FOREIGN KEY ("B") REFERENCES "Rule"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- Checkers | ||
ALTER TABLE "Rule" | ||
ADD CONSTRAINT "is_rule_public_or_project_id_check" | ||
CHECK (("isPublic" = true AND "projectId" IS NULL) OR ("isPublic" = false AND "projectId" IS NOT NULL)); | ||
|
||
ALTER TABLE "RiskRuleSet" | ||
ADD CONSTRAINT "is_risk_rule_set_public_or_project_id_check" | ||
CHECK (("isPublic" = true AND "projectId" IS NULL) OR ("isPublic" = false AND "projectId" IS NOT NULL)); | ||
|
||
ALTER TABLE "RiskRulesPolicy" | ||
ADD CONSTRAINT "is_risk_rule_policy_public_or_project_id_check" | ||
CHECK (("isPublic" = true AND "projectId" IS NULL) OR ("isPublic" = false AND "projectId" IS NOT NULL)); |
13 changes: 13 additions & 0 deletions
13
services/workflows-service/prisma/migrations/20240718140108_create_rule_policy/migration.sql
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,13 @@ | ||
/* | ||
Warnings: | ||
|
||
- You are about to drop the column `operator` on the `Rule` table. All the data in the column will be lost. | ||
- Added the required column `operation` to the `Rule` table without a default value. This is not possible if the table is not empty. | ||
|
||
*/ | ||
-- DropIndex | ||
DROP INDEX "WorkflowDefinitionRiskRulePolicy_workflowDefinitionId_key"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Rule" DROP COLUMN "operator", | ||
ADD COLUMN "operation" TEXT NOT NULL; |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operator