Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(schema): risk (#5167)

p0nye68760f7ba26
diff --git a/backend/store/migration/prod/1.15/0000##risk.sql b/backend/store/migration/prod/1.15/0000##risk.sql
new file mode 100644
index 0000000000..ac4c753eea
--- /dev/null
+++ b/backend/store/migration/prod/1.15/0000##risk.sql
@@ -0,0 +1,23 @@
+-- risk stores the definition of a risk.
+CREATE TABLE risk (
+ id BIGSERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ source TEXT NOT NULL CHECK (source LIKE 'bb.risk.%'),
+ -- how risky is the risk, the higher the riskier
+ level BIGINT NOT NULL,
+ name TEXT NOT NULL,
+ active BOOLEAN NOT NULL,
+ expression JSONB NOT NULL
+);
+
+ALTER SEQUENCE risk_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_risk_updated_ts
+BEFORE
+UPDATE
+ ON risk FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
diff --git a/backend/store/migration/prod/LATEST.sql b/backend/store/migration/prod/LATEST.sql
index 13326bca28..4cbe55b647 100644
--- a/backend/store/migration/prod/LATEST.sql
+++ b/backend/store/migration/prod/LATEST.sql
@@ -1102,3 +1102,28 @@ BEFORE
UPDATE
ON external_approval FOR EACH ROW
EXECUTE FUNCTION trigger_update_updated_ts();
+
+
+-- risk stores the definition of a risk.
+CREATE TABLE risk (
+ id BIGSERIAL PRIMARY KEY,
+ row_status row_status NOT NULL DEFAULT 'NORMAL',
+ creator_id INTEGER NOT NULL REFERENCES principal (id),
+ created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updater_id INTEGER NOT NULL REFERENCES principal (id),
+ updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ source TEXT NOT NULL CHECK (source LIKE 'bb.risk.%'),
+ -- how risky is the risk, the higher the riskier
+ level BIGINT NOT NULL,
+ name TEXT NOT NULL,
+ active BOOLEAN NOT NULL,
+ expression JSONB NOT NULL
+);
+
+ALTER SEQUENCE risk_id_seq RESTART WITH 101;
+
+CREATE TRIGGER update_risk_updated_ts
+BEFORE
+UPDATE
+ ON risk FOR EACH ROW
+EXECUTE FUNCTION trigger_update_updated_ts();
diff --git a/backend/store/pg_engine_test.go b/backend/store/pg_engine_test.go
index e52ac9d853..5c26813ef0 100644
--- a/backend/store/pg_engine_test.go
+++ b/backend/store/pg_engine_test.go
@@ -222,5 +222,5 @@ func TestMigrationCompatibility(t *testing.T) {
func TestGetCutoffVersion(t *testing.T) {
releaseVersion, err := getProdCutoffVersion()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("1.14.3"), releaseVersion)
+ require.Equal(t, semver.MustParse("1.15.0"), releaseVersion)
}