diff --git a/pkg/coredata/migrations/20250522T160900Z.sql b/pkg/coredata/migrations/20250522T160900Z.sql new file mode 100644 index 000000000..82c78b463 --- /dev/null +++ b/pkg/coredata/migrations/20250522T160900Z.sql @@ -0,0 +1,2 @@ +ALTER TABLE risks ADD COLUMN inherent_risk_score INTEGER GENERATED ALWAYS AS (inherent_impact * inherent_likelihood) STORED; +ALTER TABLE risks ADD COLUMN residual_risk_score INTEGER GENERATED ALWAYS AS (residual_impact * residual_likelihood) STORED; diff --git a/pkg/coredata/risk.go b/pkg/coredata/risk.go index 77820a027..c8e75b18a 100644 --- a/pkg/coredata/risk.go +++ b/pkg/coredata/risk.go @@ -38,8 +38,10 @@ type ( OwnerID *gid.GID `db:"owner_id"` InherentLikelihood int `db:"inherent_likelihood"` InherentImpact int `db:"inherent_impact"` + InherentRiskScore int `db:"inherent_risk_score"` ResidualLikelihood int `db:"residual_likelihood"` ResidualImpact int `db:"residual_impact"` + ResidualRiskScore int `db:"residual_risk_score"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` } @@ -56,14 +58,6 @@ func (r *Risk) CursorKey(orderBy RiskOrderField) page.CursorKey { panic(fmt.Sprintf("unsupported order by: %s", orderBy)) } -func (r *Risk) InherentRiskScore() int { - return r.InherentLikelihood * r.InherentImpact -} - -func (r *Risk) ResidualRiskScore() int { - return r.ResidualLikelihood * r.ResidualImpact -} - func (r *Risks) LoadByMeasureID( ctx context.Context, conn pg.Conn, @@ -85,8 +79,10 @@ WITH rsks AS ( r.note, r.inherent_likelihood, r.inherent_impact, + r.inherent_risk_score, r.residual_likelihood, r.residual_impact, + r.residual_risk_score, r.created_at, r.updated_at FROM @@ -107,8 +103,10 @@ SELECT note, inherent_likelihood, inherent_impact, + inherent_risk_score, residual_likelihood, residual_impact, + residual_risk_score, created_at, updated_at FROM @@ -154,8 +152,10 @@ SELECT note, inherent_likelihood, inherent_impact, + inherent_risk_score, residual_likelihood, residual_impact, + residual_risk_score, category, created_at, updated_at @@ -203,8 +203,10 @@ SELECT note, inherent_likelihood, inherent_impact, + inherent_risk_score, residual_likelihood, residual_impact, + residual_risk_score, created_at, updated_at FROM risks diff --git a/pkg/server/api/console/v1/types/risk.go b/pkg/server/api/console/v1/types/risk.go index 7ec37b26f..fd403068b 100644 --- a/pkg/server/api/console/v1/types/risk.go +++ b/pkg/server/api/console/v1/types/risk.go @@ -51,10 +51,10 @@ func NewRisk(r *coredata.Risk) *Risk { Treatment: r.Treatment, InherentLikelihood: r.InherentLikelihood, InherentImpact: r.InherentImpact, - InherentRiskScore: r.InherentRiskScore(), + InherentRiskScore: r.InherentRiskScore, ResidualLikelihood: r.ResidualLikelihood, ResidualImpact: r.ResidualImpact, - ResidualRiskScore: r.ResidualRiskScore(), + ResidualRiskScore: r.ResidualRiskScore, Category: r.Category, CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt,