feat: implement policy engine entity layer and initial database schema definition
This commit is contained in:
+13
-13
@@ -496,7 +496,7 @@ CREATE TABLE IF NOT EXISTS masters.tbl_amount_types (
|
||||
|
||||
-- ─── Policy Engine ──────────────────────────────────────────────────────────
|
||||
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.policies (
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.tbl_policies (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
"tenantId" UUID NOT NULL REFERENCES tenant.tbl_tenants(id) ON DELETE CASCADE,
|
||||
policy_name VARCHAR(200) NOT NULL,
|
||||
@@ -511,23 +511,23 @@ CREATE TABLE IF NOT EXISTS policy_engine.policies (
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.policy_target_audiences (
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.tbl_policy_target_audiences (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
policy_id UUID NOT NULL REFERENCES policy_engine.policies(id) ON DELETE CASCADE,
|
||||
policy_id UUID NOT NULL REFERENCES policy_engine.tbl_policies(id) ON DELETE CASCADE,
|
||||
target_type VARCHAR NOT NULL,
|
||||
target_id UUID
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.policy_rules (
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.tbl_policy_rules (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
policy_id UUID NOT NULL REFERENCES policy_engine.policies(id) ON DELETE CASCADE,
|
||||
policy_id UUID NOT NULL REFERENCES policy_engine.tbl_policies(id) ON DELETE CASCADE,
|
||||
rule_category_id UUID REFERENCES masters.tbl_rule_categories(id) ON DELETE SET NULL,
|
||||
priority INT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.rule_conditions (
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.tbl_policy_rule_conditions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
rule_id UUID NOT NULL REFERENCES policy_engine.policy_rules(id) ON DELETE CASCADE,
|
||||
rule_id UUID NOT NULL REFERENCES policy_engine.tbl_policy_rules(id) ON DELETE CASCADE,
|
||||
field_id UUID NOT NULL,
|
||||
operator_id UUID NOT NULL,
|
||||
value_text TEXT,
|
||||
@@ -535,16 +535,16 @@ CREATE TABLE IF NOT EXISTS policy_engine.rule_conditions (
|
||||
sequence INT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.policy_actions (
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.tbl_policy_actions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
rule_id UUID NOT NULL REFERENCES policy_engine.policy_rules(id) ON DELETE CASCADE,
|
||||
rule_id UUID NOT NULL REFERENCES policy_engine.tbl_policy_rules(id) ON DELETE CASCADE,
|
||||
action_type_id UUID NOT NULL REFERENCES masters.tbl_action_types(id) ON DELETE CASCADE,
|
||||
sequence INT NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.policy_action_values (
|
||||
CREATE TABLE IF NOT EXISTS policy_engine.tbl_policy_action_values (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
action_id UUID NOT NULL REFERENCES policy_engine.policy_actions(id) ON DELETE CASCADE,
|
||||
action_id UUID NOT NULL REFERENCES policy_engine.tbl_policy_actions(id) ON DELETE CASCADE,
|
||||
field_definition_id UUID REFERENCES masters.tbl_field_definitions(id) ON DELETE SET NULL,
|
||||
field_code VARCHAR NOT NULL,
|
||||
value_index INT NOT NULL DEFAULT 0,
|
||||
@@ -560,8 +560,8 @@ CREATE TABLE IF NOT EXISTS policy_engine.policy_action_values (
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_policy_action_values_action
|
||||
ON policy_engine.policy_action_values(action_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_tbl_policy_action_values_action
|
||||
ON policy_engine.tbl_policy_action_values(action_id);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import { PolicyAction } from './policy-action.entity';
|
||||
import { FieldDefinition } from '../../master-data/entities/field-definition.entity';
|
||||
|
||||
@Entity({ name: 'policy_action_values', schema: 'policy_engine' })
|
||||
@Entity({ name: 'tbl_policy_action_values', schema: 'policy_engine' })
|
||||
export class PolicyActionValue {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { PolicyRule } from './policy-rule.entity';
|
||||
import { PolicyActionValue } from './policy-action-value.entity';
|
||||
import { ActionType } from '../../master-data/entities/action-type.entity';
|
||||
|
||||
@Entity({ name: 'policy_actions', schema: 'policy_engine' })
|
||||
@Entity({ name: 'tbl_policy_actions', schema: 'policy_engine' })
|
||||
export class PolicyAction {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RuleCondition } from './rule-condition.entity';
|
||||
import { PolicyAction } from './policy-action.entity';
|
||||
import { RuleCategory } from '../../master-data/entities/rule-category.entity';
|
||||
|
||||
@Entity({ name: 'policy_rules', schema: 'policy_engine' })
|
||||
@Entity({ name: 'tbl_policy_rules', schema: 'policy_engine' })
|
||||
export class PolicyRule {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 't
|
||||
import { Policy } from './policy.entity';
|
||||
import { AudienceType } from './policy.enums';
|
||||
|
||||
@Entity({ name: 'policy_target_audience', schema: 'policy_engine' })
|
||||
@Entity({ name: 'tbl_policy_target_audiences', schema: 'policy_engine' })
|
||||
export class PolicyTargetAudience {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { PolicyTargetAudience } from './policy-target-audience.entity';
|
||||
import { PolicyRule } from './policy-rule.entity';
|
||||
import { Jurisdiction } from '../../master-data/entities/jurisdiction.entity';
|
||||
|
||||
@Entity({ name: 'policies', schema: 'policy_engine' })
|
||||
@Entity({ name: 'tbl_policies', schema: 'policy_engine' })
|
||||
export class Policy extends TenantOwnedEntity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 't
|
||||
import { PolicyRule } from './policy-rule.entity';
|
||||
import { LogicalOperator } from './policy.enums';
|
||||
|
||||
@Entity({ name: 'policy_rule_conditions', schema: 'policy_engine' })
|
||||
@Entity({ name: 'tbl_policy_rule_conditions', schema: 'policy_engine' })
|
||||
export class RuleCondition {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
Reference in New Issue
Block a user