Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: migrate sql review policy (#12410)
ecmadao382aebbc768c
diff --git a/backend/migrator/migration/prod/2.20/0001##review_config.sql b/backend/migrator/migration/prod/2.20/0001##review_config.sqlnew file mode 100644index 0000000000..c7236eefd3--- /dev/null+++ b/backend/migrator/migration/prod/2.20/0001##review_config.sql@@ -0,0 +1,47 @@+-- Create review config table.+CREATE TABLE review_config+(+ id TEXT NOT NULL 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()),+ name TEXT NOT NULL,+ payload JSONB NOT NULL DEFAULT '{}'+);++-- Migrate sql review policy to the new table.+INSERT INTO review_config+ (id, row_status, creator_id, created_ts, updater_id, updated_ts, name, payload)+SELECT+ environment.resource_id,+ policy.row_status,+ policy.creator_id,+ policy.created_ts,+ policy.updater_id,+ policy.updated_ts,+ policy.payload->>'name',+ jsonb_build_object('sqlReviewRules', policy.payload->'ruleList')+FROM policy+INNER JOIN environment ON policy.resource_id = environment.id+WHERE type = 'bb.policy.sql-review';++-- Migrate environment sql review policy to bb.policy.tag policy.+INSERT INTO policy+ (creator_id, created_ts, updater_id, updated_ts, resource_type, resource_id, type, payload)+SELECT+ policy.creator_id,+ policy.created_ts,+ policy.updater_id,+ policy.updated_ts,+ policy.resource_type,+ policy.resource_id,+ 'bb.policy.tag',+ -- We're using environment.resource_id as review config resource_id.+ jsonb_build_object('tags', jsonb_build_object('bb.tag.review_config', CONCAT('reviewConfigs/', environment.resource_id)))+FROM policy+INNER JOIN environment ON policy.resource_id = environment.id+WHERE type = 'bb.policy.sql-review';++-- TODO: remove legacy bb.policy.sql-review policy after migration.diff --git a/backend/migrator/migration/prod/LATEST.sql b/backend/migrator/migration/prod/LATEST.sqlindex 62f3061400..dfb8862409 100644--- a/backend/migrator/migration/prod/LATEST.sql+++ b/backend/migrator/migration/prod/LATEST.sql@@ -967,4 +967,17 @@ CREATE TABLE user_group (name TEXT NOT NULL,description TEXT NOT NULL DEFAULT '',payload JSONB NOT NULL DEFAULT '{}'+);++-- review config table.+CREATE TABLE review_config+(+ id TEXT NOT NULL 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()),+ name TEXT NOT NULL,+ payload JSONB NOT NULL DEFAULT '{}');\ No newline at end of filediff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex e93677fafd..42ead16bcb 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -230,5 +230,5 @@ func TestMigrationCompatibility(t *testing.T) {func TestGetCutoffVersion(t *testing.T) {releaseVersion, err := getProdCutoffVersion()require.NoError(t, err)- require.Equal(t, semver.MustParse("2.20.0"), releaseVersion)+ require.Equal(t, semver.MustParse("2.20.1"), releaseVersion)}diff --git a/frontend/src/types/proto/store/policy.ts b/frontend/src/types/proto/store/policy.tsindex 9af28a0546..bf088f6f40 100644--- a/frontend/src/types/proto/store/policy.ts+++ b/frontend/src/types/proto/store/policy.ts@@ -206,7 +206,7 @@ export interface SQLReviewRule {export interface TagPolicy {/*** tags is the key - value map for resources.- * for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ * for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"*/tags: { [key: string]: string };}diff --git a/frontend/src/types/proto/v1/org_policy_service.ts b/frontend/src/types/proto/v1/org_policy_service.tsindex 107725ac48..e3b81b0a78 100644--- a/frontend/src/types/proto/v1/org_policy_service.ts+++ b/frontend/src/types/proto/v1/org_policy_service.ts@@ -534,7 +534,7 @@ export interface RestrictIssueCreationForSQLReviewPolicy {export interface TagPolicy {/*** tags is the key - value map for resources.- * for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ * for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"*/tags: { [key: string]: string };}diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yamlindex 758ab64b0c..77fb7a8fef 100644--- a/proto/gen/grpc-doc/openapi.yaml+++ b/proto/gen/grpc-doc/openapi.yaml@@ -13235,7 +13235,7 @@ components:type: stringdescription: |-tags is the key - value map for resources.- for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"Task:type: objectproperties:diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 9184e97f59..2d583092e4 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -3011,7 +3011,7 @@ Format: users/{userUID} or groups/{group email} || Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| tags | [TagPolicy.TagsEntry](#bytebase-store-TagPolicy-TagsEntry) | repeated | tags is the key - value map for resources. for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}" |+| tags | [TagPolicy.TagsEntry](#bytebase-store-TagPolicy-TagsEntry) | repeated | tags is the key - value map for resources. for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}" |diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.htmlindex 844faff4c5..cd6e951909 100644--- a/proto/gen/grpc-doc/store/index.html+++ b/proto/gen/grpc-doc/store/index.html@@ -7783,7 +7783,7 @@ roles/CREATOR </p></td><td><a href="#bytebase.store.TagPolicy.TagsEntry">TagPolicy.TagsEntry</a></td><td>repeated</td><td><p>tags is the key - value map for resources.-for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}" </p></td>+for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}" </p></td></tr></tbody>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex cc41ab4c5b..69517e30e6 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -5838,7 +5838,7 @@ MaskingExceptionPolicy is the allowlist of users who can access sensitive data.| Field | Type | Label | Description || ----- | ---- | ----- | ----------- |-| tags | [TagPolicy.TagsEntry](#bytebase-v1-TagPolicy-TagsEntry) | repeated | tags is the key - value map for resources. for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}" |+| tags | [TagPolicy.TagsEntry](#bytebase-v1-TagPolicy-TagsEntry) | repeated | tags is the key - value map for resources. for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}" |diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.htmlindex 6cd4f4807a..fd18c65092 100644--- a/proto/gen/grpc-doc/v1/index.html+++ b/proto/gen/grpc-doc/v1/index.html@@ -16615,7 +16615,7 @@ roles/CREATOR </p></td><td><a href="#bytebase.v1.TagPolicy.TagsEntry">TagPolicy.TagsEntry</a></td><td>repeated</td><td><p>tags is the key - value map for resources.-for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}" </p></td>+for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}" </p></td></tr></tbody>diff --git a/proto/generated-go/store/policy.pb.go b/proto/generated-go/store/policy.pb.goindex 50069853a5..fcd6d33172 100644--- a/proto/generated-go/store/policy.pb.go+++ b/proto/generated-go/store/policy.pb.go@@ -564,7 +564,7 @@ type TagPolicy struct {unknownFields protoimpl.UnknownFields// tags is the key - value map for resources.- // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"Tags map[string]string `protobuf:"bytes,1,rep,name=tags,proto3" json:"tags,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`}diff --git a/proto/generated-go/v1/org_policy_service.pb.go b/proto/generated-go/v1/org_policy_service.pb.goindex 4454925ed7..86408c38b5 100644--- a/proto/generated-go/v1/org_policy_service.pb.go+++ b/proto/generated-go/v1/org_policy_service.pb.go@@ -1474,7 +1474,7 @@ type TagPolicy struct {unknownFields protoimpl.UnknownFields// tags is the key - value map for resources.- // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"Tags map[string]string `protobuf:"bytes,1,rep,name=tags,proto3" json:"tags,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`}diff --git a/proto/store/policy.proto b/proto/store/policy.protoindex 1cc96f822b..a16c2e479c 100644--- a/proto/store/policy.proto+++ b/proto/store/policy.proto@@ -89,6 +89,6 @@ enum SQLReviewRuleLevel {message TagPolicy {// tags is the key - value map for resources.- // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"map<string, string> tags = 1;}diff --git a/proto/v1/org_policy_service.proto b/proto/v1/org_policy_service.protoindex 320fda6608..63743f379c 100644--- a/proto/v1/org_policy_service.proto+++ b/proto/v1/org_policy_service.proto@@ -340,6 +340,6 @@ message RestrictIssueCreationForSQLReviewPolicy {message TagPolicy {// tags is the key - value map for resources.- // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "{review config id}"+ // for example, the environment resource can have the sql review config tag, like "bb.tag.review_config": "reviewConfigs/{review config resource id}"map<string, string> tags = 1;}