Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: migrate setting value column from text to jsonb (#18346)
Danny Xu5676c1732cda
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.goindex d0f7f3a16a..50e41eca83 100644--- a/backend/api/v1/setting_service.go+++ b/backend/api/v1/setting_service.go@@ -53,11 +53,6 @@ func NewSettingService(}}-// Backend-only settings that should never be exposed via the API.-var disallowedSettings = []storepb.SettingName{- storepb.SettingName_SYSTEM, // Internal system settings (auth secret, workspace ID, enterprise license)-}-// ListSettings lists all settings.func (s *SettingService) ListSettings(ctx context.Context, _ *connect.Request[v1pb.ListSettingsRequest]) (*connect.Response[v1pb.ListSettingsResponse], error) {settings, err := s.store.ListSettingV2(ctx, &store.FindSettingMessage{})@@ -641,12 +636,9 @@ var disallowedDomains = map[string]bool{}func isSettingDisallowed(name storepb.SettingName) bool {- for _, disallowed := range disallowedSettings {- if name == disallowed {- return true- }- }- return false+ // Backend-only settings that should never be exposed via the API.+ // SYSTEM: Internal system settings (auth secret, workspace ID, enterprise license)+ return name == storepb.SettingName_SYSTEM}func validateApprovalTemplate(template *v1pb.ApprovalTemplate) error {diff --git a/backend/migrator/migration/3.13/0014##change_setting_value_to_jsonb.sql b/backend/migrator/migration/3.13/0014##change_setting_value_to_jsonb.sqlnew file mode 100644index 0000000000..745d01068a--- /dev/null+++ b/backend/migrator/migration/3.13/0014##change_setting_value_to_jsonb.sql@@ -0,0 +1,3 @@+-- Change setting.value column from text to jsonb+-- All setting values are already JSON strings serialized by protojson.Marshal+ALTER TABLE setting ALTER COLUMN value TYPE jsonb USING value::jsonb;diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sqlindex b5e06ca5e0..8439cbb41a 100644--- a/backend/migrator/migration/LATEST.sql+++ b/backend/migrator/migration/LATEST.sql@@ -38,7 +38,8 @@ CREATE TABLE setting (-- PASSWORD_RESTRICTION, ENVIRONMENT-- Enum: SettingName (proto/store/store/setting.proto)name text NOT NULL,- value text NOT NULL+ -- Stored as JSON marshalled by protojson.Marshal (camelCase keys)+ value jsonb NOT NULL);CREATE UNIQUE INDEX idx_setting_unique_name ON setting(name);@@ -549,15 +550,15 @@ INSERT INTO project (id, name, resource_id) VALUES (1, 'Default', 'default');ALTER SEQUENCE project_id_seq RESTART WITH 101;-- Initialize settings with static values-INSERT INTO setting (name, value) VALUES ('APP_IM', '{}');-INSERT INTO setting (name, value) VALUES ('DATA_CLASSIFICATION', '{}');-INSERT INTO setting (name, value) VALUES ('WORKSPACE_APPROVAL', '{"rules":[{"template":{"flow":{"roles":["roles/projectOwner"]},"title":"Fallback Rule","description":"Requires project owner approval when no other rules match."},"condition":{"expression":"true"}}]}');-INSERT INTO setting (name, value) VALUES ('PASSWORD_RESTRICTION', '{"minLength":8}');+INSERT INTO setting (name, value) VALUES ('APP_IM', '{}'::jsonb);+INSERT INTO setting (name, value) VALUES ('DATA_CLASSIFICATION', '{}'::jsonb);+INSERT INTO setting (name, value) VALUES ('WORKSPACE_APPROVAL', '{"rules":[{"template":{"flow":{"roles":["roles/projectOwner"]},"title":"Fallback Rule","description":"Requires project owner approval when no other rules match."},"condition":{"expression":"true"}}]}'::jsonb);+INSERT INTO setting (name, value) VALUES ('PASSWORD_RESTRICTION', '{"minLength":8}'::jsonb);INSERT INTO setting (name, value) VALUES ('WORKSPACE_PROFILE',- '{"enableMetricCollection":true,"directorySyncToken":"' || gen_random_uuid()::text || '"}'+ ('{"enableMetricCollection":true,"directorySyncToken":"' || gen_random_uuid()::text || '"}')::jsonb);-INSERT INTO setting (name, value) VALUES ('ENVIRONMENT', '{"environments":[{"title":"Test","id":"test"},{"title":"Prod","id":"prod"}]}');+INSERT INTO setting (name, value) VALUES ('ENVIRONMENT', '{"environments":[{"title":"Test","id":"test"},{"title":"Prod","id":"prod"}]}'::jsonb);-- Initialize settings with dynamically generated values-- Generate random alphanumeric string (0-9, a-z, A-Z) compatible with Go's common.RandomString@@ -569,7 +570,7 @@ VALUES ('authSecret', (SELECT string_agg(substr('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', floor(random() * 62 + 1)::int, 1), '')FROM generate_series(1, 32)),'workspaceId', gen_random_uuid()::text- )::TEXT+ ));-- Initialize workspace IAM policydiff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex cfbf0828b4..e7dd7847e4 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -12,7 +12,7 @@ import (func TestLatestVersion(t *testing.T) {files, err := getSortedVersionedFiles()require.NoError(t, err)- require.Equal(t, semver.MustParse("3.13.13"), *files[len(files)-1].version)+ require.Equal(t, semver.MustParse("3.13.14"), *files[len(files)-1].version)}func TestVersionUnique(t *testing.T) {diff --git a/backend/runner/metricreport/reporter.go b/backend/runner/metricreport/reporter.goindex 2f631615fd..cdaf70a9a9 100644--- a/backend/runner/metricreport/reporter.go+++ b/backend/runner/metricreport/reporter.go@@ -174,7 +174,7 @@ func (m *Reporter) isMetricCollectionEnabled(ctx context.Context) bool {return true}- if setting == nil || setting.Value == "" {+ if setting == nil {// Default to enabled if setting is not foundreturn true}diff --git a/backend/store/setting.go b/backend/store/setting.goindex ed0b381a01..e41e044a1f 100644--- a/backend/store/setting.go+++ b/backend/store/setting.go@@ -122,7 +122,7 @@ func (s *Store) UpsertEnterpriseLicense(ctx context.Context, license string) err}systemSetting := &storepb.SystemSetting{}- if setting != nil && setting.Value != "" {+ if setting != nil {if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(setting.Value), systemSetting); err != nil {return errors.Wrap(err, "failed to unmarshal system setting")}