Skip to content

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

refactor: migrate ENTERPRISE_LICENSE to SYSTEM setting (#18345)

Danny Xu7d55ba2e55b9
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index cd1e731d0e..d0f7f3a16a 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -55,8 +55,7 @@ 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)
- storepb.SettingName_ENTERPRISE_LICENSE, // Managed via SubscriptionService
+ storepb.SettingName_SYSTEM, // Internal system settings (auth secret, workspace ID, enterprise license)
}
// ListSettings lists all settings.
diff --git a/backend/api/v1/setting_service_converter.go b/backend/api/v1/setting_service_converter.go
index 8360513369..07b7fbfb04 100644
--- a/backend/api/v1/setting_service_converter.go
+++ b/backend/api/v1/setting_service_converter.go
@@ -175,8 +175,8 @@ func convertStoreSettingNameToV1(storeName storepb.SettingName) v1pb.Setting_Set
return v1pb.Setting_PASSWORD_RESTRICTION
case storepb.SettingName_ENVIRONMENT:
return v1pb.Setting_ENVIRONMENT
- case storepb.SettingName_SYSTEM, storepb.SettingName_ENTERPRISE_LICENSE:
- // Backend-only settings, not exposed in v1 API
+ case storepb.SettingName_SYSTEM:
+ // Backend-only setting, not exposed in v1 API
default:
}
return v1pb.Setting_SETTING_NAME_UNSPECIFIED
diff --git a/backend/enterprise/plugin/hub/hub.go b/backend/enterprise/plugin/hub/hub.go
index 836c41e08d..6aab3acf7b 100644
--- a/backend/enterprise/plugin/hub/hub.go
+++ b/backend/enterprise/plugin/hub/hub.go
@@ -14,7 +14,6 @@ import (
"github.com/bytebase/bytebase/backend/common/log"
"github.com/bytebase/bytebase/backend/enterprise/config"
"github.com/bytebase/bytebase/backend/enterprise/plugin"
- storepb "github.com/bytebase/bytebase/backend/generated-go/store"
v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
"github.com/bytebase/bytebase/backend/store"
)
@@ -81,14 +80,7 @@ func (p *Provider) StoreLicense(ctx context.Context, license string) error {
return err
}
}
- if _, err := p.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
- Name: storepb.SettingName_ENTERPRISE_LICENSE,
- Value: license,
- }); err != nil {
- return err
- }
-
- return nil
+ return p.store.UpsertEnterpriseLicense(ctx, license)
}
// LoadSubscription will load the hub subscription.
@@ -120,12 +112,12 @@ func (p *Provider) parseLicense(ctx context.Context, license string) (*v1pb.Subs
func (p *Provider) findEnterpriseLicense(ctx context.Context) (*v1pb.Subscription, error) {
// Find enterprise license.
- setting, err := p.store.GetSettingV2(ctx, storepb.SettingName_ENTERPRISE_LICENSE)
+ licenseStr, err := p.store.GetEnterpriseLicense(ctx)
if err != nil {
return nil, errors.Wrapf(err, "failed to load enterprise license from settings")
}
- if setting != nil && setting.Value != "" {
- license, err := p.parseLicense(ctx, setting.Value)
+ if licenseStr != "" {
+ license, err := p.parseLicense(ctx, licenseStr)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse enterprise license")
}
diff --git a/backend/generated-go/store/setting.pb.go b/backend/generated-go/store/setting.pb.go
index 17966123db..34dd7d2a11 100644
--- a/backend/generated-go/store/setting.pb.go
+++ b/backend/generated-go/store/setting.pb.go
@@ -30,13 +30,13 @@ const (
SettingName_SYSTEM SettingName = 1
SettingName_WORKSPACE_PROFILE SettingName = 4
SettingName_WORKSPACE_APPROVAL SettingName = 5
- SettingName_ENTERPRISE_LICENSE SettingName = 7
- SettingName_APP_IM SettingName = 8
- SettingName_AI SettingName = 10
- SettingName_DATA_CLASSIFICATION SettingName = 14
- SettingName_SEMANTIC_TYPES SettingName = 15
- SettingName_PASSWORD_RESTRICTION SettingName = 18
- SettingName_ENVIRONMENT SettingName = 19
+ // 7 was ENTERPRISE_LICENSE, migrated to SYSTEM setting
+ SettingName_APP_IM SettingName = 8
+ SettingName_AI SettingName = 10
+ SettingName_DATA_CLASSIFICATION SettingName = 14
+ SettingName_SEMANTIC_TYPES SettingName = 15
+ SettingName_PASSWORD_RESTRICTION SettingName = 18
+ SettingName_ENVIRONMENT SettingName = 19
)
// Enum value maps for SettingName.
@@ -46,7 +46,6 @@ var (
1: "SYSTEM",
4: "WORKSPACE_PROFILE",
5: "WORKSPACE_APPROVAL",
- 7: "ENTERPRISE_LICENSE",
8: "APP_IM",
10: "AI",
14: "DATA_CLASSIFICATION",
@@ -59,7 +58,6 @@ var (
"SYSTEM": 1,
"WORKSPACE_PROFILE": 4,
"WORKSPACE_APPROVAL": 5,
- "ENTERPRISE_LICENSE": 7,
"APP_IM": 8,
"AI": 10,
"DATA_CLASSIFICATION": 14,
@@ -365,7 +363,9 @@ type SystemSetting struct {
// Authentication secret for token signing (32-character random string).
AuthSecret string `protobuf:"bytes,1,opt,name=auth_secret,json=authSecret,proto3" json:"auth_secret,omitempty"`
// Unique workspace identifier (UUID).
- WorkspaceId string `protobuf:"bytes,2,opt,name=workspace_id,json=workspaceId,proto3" json:"workspace_id,omitempty"`
+ WorkspaceId string `protobuf:"bytes,2,opt,name=workspace_id,json=workspaceId,proto3" json:"workspace_id,omitempty"`
+ // Enterprise license JWT token.
+ License string `protobuf:"bytes,3,opt,name=license,proto3" json:"license,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@@ -414,6 +414,13 @@ func (x *SystemSetting) GetWorkspaceId() string {
return ""
}
+func (x *SystemSetting) GetLicense() string {
+ if x != nil {
+ return x.License
+ }
+ return ""
+}
+
type WorkspaceProfileSetting struct {
state protoimpl.MessageState `protogen:"open.v1"`
// The external URL is used for sso authentication callback.
@@ -2348,11 +2355,12 @@ var File_store_setting_proto protoreflect.FileDescriptor
const file_store_setting_proto_rawDesc = "" +
"\n" +
- "\x13store/setting.proto\x12\x0ebytebase.store\x1a\x1egoogle/protobuf/duration.proto\x1a\x16google/type/expr.proto\x1a\x14store/approval.proto\x1a\x1bstore/project_webhook.proto\"S\n" +
+ "\x13store/setting.proto\x12\x0ebytebase.store\x1a\x1egoogle/protobuf/duration.proto\x1a\x16google/type/expr.proto\x1a\x14store/approval.proto\x1a\x1bstore/project_webhook.proto\"m\n" +
"\rSystemSetting\x12\x1f\n" +
"\vauth_secret\x18\x01 \x01(\tR\n" +
"authSecret\x12!\n" +
- "\fworkspace_id\x18\x02 \x01(\tR\vworkspaceId\"\xfa\x06\n" +
+ "\fworkspace_id\x18\x02 \x01(\tR\vworkspaceId\x12\x18\n" +
+ "\alicense\x18\x03 \x01(\tR\alicense\"\xfa\x06\n" +
"\x17WorkspaceProfileSetting\x12!\n" +
"\fexternal_url\x18\x01 \x01(\tR\vexternalUrl\x12'\n" +
"\x0fdisallow_signup\x18\x02 \x01(\bR\x0edisallowSignup\x12\x1f\n" +
@@ -2517,14 +2525,13 @@ const file_store_setting_proto_rawDesc = "" +
"\x05color\x18\x04 \x01(\tR\x05color\x1a7\n" +
"\tTagsEntry\x12\x10\n" +
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
- "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01*\xea\x01\n" +
+ "\x05value\x18\x02 \x01(\tR\x05value:\x028\x01*\xd2\x01\n" +
"\vSettingName\x12\x1c\n" +
"\x18SETTING_NAME_UNSPECIFIED\x10\x00\x12\n" +
"\n" +
"\x06SYSTEM\x10\x01\x12\x15\n" +
"\x11WORKSPACE_PROFILE\x10\x04\x12\x16\n" +
- "\x12WORKSPACE_APPROVAL\x10\x05\x12\x16\n" +
- "\x12ENTERPRISE_LICENSE\x10\a\x12\n" +
+ "\x12WORKSPACE_APPROVAL\x10\x05\x12\n" +
"\n" +
"\x06APP_IM\x10\b\x12\x06\n" +
"\x02AI\x10\n" +
diff --git a/backend/generated-go/store/setting_equal.pb.go b/backend/generated-go/store/setting_equal.pb.go
index 08402ca9d7..80ff6877a0 100644
--- a/backend/generated-go/store/setting_equal.pb.go
+++ b/backend/generated-go/store/setting_equal.pb.go
@@ -21,6 +21,9 @@ func (x *SystemSetting) Equal(y *SystemSetting) bool {
if x.WorkspaceId != y.WorkspaceId {
return false
}
+ if x.License != y.License {
+ return false
+ }
return true
}
diff --git a/backend/migrator/migration/3.13/0013##migrate_enterprise_license.sql b/backend/migrator/migration/3.13/0013##migrate_enterprise_license.sql
new file mode 100644
index 0000000000..15db523408
--- /dev/null
+++ b/backend/migrator/migration/3.13/0013##migrate_enterprise_license.sql
@@ -0,0 +1,12 @@
+-- Migrate ENTERPRISE_LICENSE to SYSTEM setting
+-- Only backfill if the license string is not empty
+UPDATE setting
+SET value = jsonb_set(
+ value::jsonb,
+ '{license}',
+ to_jsonb((SELECT value FROM setting WHERE name = 'ENTERPRISE_LICENSE'))
+)::TEXT
+WHERE name = 'SYSTEM'
+ AND (SELECT value FROM setting WHERE name = 'ENTERPRISE_LICENSE') != '';
+
+DELETE FROM setting WHERE name = 'ENTERPRISE_LICENSE';
diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sql
index f4d8c2d380..b5e06ca5e0 100644
--- a/backend/migrator/migration/LATEST.sql
+++ b/backend/migrator/migration/LATEST.sql
@@ -34,8 +34,8 @@ CREATE TABLE principal (
CREATE TABLE setting (
id serial PRIMARY KEY,
-- name: SYSTEM, WORKSPACE_PROFILE, WORKSPACE_APPROVAL,
- -- ENTERPRISE_LICENSE, APP_IM, AI,
- -- DATA_CLASSIFICATION, SEMANTIC_TYPES, PASSWORD_RESTRICTION, ENVIRONMENT
+ -- APP_IM, AI, DATA_CLASSIFICATION, SEMANTIC_TYPES,
+ -- PASSWORD_RESTRICTION, ENVIRONMENT
-- Enum: SettingName (proto/store/store/setting.proto)
name text NOT NULL,
value text NOT NULL
@@ -549,7 +549,6 @@ 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 ('ENTERPRISE_LICENSE', '');
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"}}]}');
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 3d2d3a10d3..cfbf0828b4 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.12"), *files[len(files)-1].version)
+ require.Equal(t, semver.MustParse("3.13.13"), *files[len(files)-1].version)
}
func TestVersionUnique(t *testing.T) {
diff --git a/backend/store/setting.go b/backend/store/setting.go
index 9ea6f1a96b..ed0b381a01 100644
--- a/backend/store/setting.go
+++ b/backend/store/setting.go
@@ -5,6 +5,7 @@ import (
"database/sql"
"github.com/pkg/errors"
+ "google.golang.org/protobuf/encoding/protojson"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/common/qb"
@@ -104,6 +105,46 @@ func (s *Store) GetWorkspaceID(ctx context.Context) (string, error) {
return systemSetting.WorkspaceId, nil
}
+// GetEnterpriseLicense retrieves the enterprise license from SYSTEM setting.
+func (s *Store) GetEnterpriseLicense(ctx context.Context) (string, error) {
+ systemSetting, err := s.GetSystemSetting(ctx)
+ if err != nil {
+ return "", errors.Wrap(err, "failed to get system setting")
+ }
+ return systemSetting.License, nil
+}
+
+// UpsertEnterpriseLicense updates the enterprise license in SYSTEM setting.
+func (s *Store) UpsertEnterpriseLicense(ctx context.Context, license string) error {
+ setting, err := s.GetSettingV2(ctx, storepb.SettingName_SYSTEM)
+ if err != nil {
+ return errors.Wrap(err, "failed to get system setting")
+ }
+
+ systemSetting := &storepb.SystemSetting{}
+ if setting != nil && setting.Value != "" {
+ if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(setting.Value), systemSetting); err != nil {
+ return errors.Wrap(err, "failed to unmarshal system setting")
+ }
+ }
+
+ systemSetting.License = license
+
+ value, err := protojson.Marshal(systemSetting)
+ if err != nil {
+ return errors.Wrap(err, "failed to marshal system setting")
+ }
+
+ if _, err := s.UpsertSettingV2(ctx, &SetSettingMessage{
+ Name: storepb.SettingName_SYSTEM,
+ Value: string(value),
+ }); err != nil {
+ return errors.Wrap(err, "failed to upsert system setting")
+ }
+
+ return nil
+}
+
// GetWorkspaceApprovalSetting gets the workspace approval setting.
func (s *Store) GetWorkspaceApprovalSetting(ctx context.Context) (*storepb.WorkspaceApprovalSetting, error) {
setting, err := s.GetSettingV2(ctx, storepb.SettingName_WORKSPACE_APPROVAL)
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index d2662428d0..84b9c96176 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -4580,6 +4580,7 @@ ISSUE_CREATE represents creating an issue. |
| ----- | ---- | ----- | ----------- |
| auth_secret | [string](#string) | | Authentication secret for token signing (32-character random string). |
| workspace_id | [string](#string) | | Unique workspace identifier (UUID). |
+| license | [string](#string) | | Enterprise license JWT token. |
@@ -4716,8 +4717,7 @@ We support three levels of AlertLevel: INFO, WARNING, and ERROR.
| SYSTEM | 1 | |
| WORKSPACE_PROFILE | 4 | |
| WORKSPACE_APPROVAL | 5 | |
-| ENTERPRISE_LICENSE | 7 | |
-| APP_IM | 8 | |
+| APP_IM | 8 | 7 was ENTERPRISE_LICENSE, migrated to SYSTEM setting |
| AI | 10 | |
| DATA_CLASSIFICATION | 14 | |
| SEMANTIC_TYPES | 15 | |
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index a33a9fa75c..c7ab7f74e8 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -12064,6 +12064,13 @@ are /[a-z][0-9]-/. </p></td>
<td><p>Unique workspace identifier (UUID). </p></td>
</tr>
+ <tr>
+ <td>license</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p>Enterprise license JWT token. </p></td>
+ </tr>
+
</tbody>
</table>
@@ -12433,16 +12440,10 @@ Default to this mode.</p></td>
<td><p></p></td>
</tr>
- <tr>
- <td>ENTERPRISE_LICENSE</td>
- <td>7</td>
- <td><p></p></td>
- </tr>
-
<tr>
<td>APP_IM</td>
<td>8</td>
- <td><p></p></td>
+ <td><p>7 was ENTERPRISE_LICENSE, migrated to SYSTEM setting</p></td>
</tr>
<tr>
diff --git a/proto/store/store/setting.proto b/proto/store/store/setting.proto
index 93c5364c47..7ed4a2b261 100644
--- a/proto/store/store/setting.proto
+++ b/proto/store/store/setting.proto
@@ -14,6 +14,8 @@ message SystemSetting {
string auth_secret = 1;
// Unique workspace identifier (UUID).
string workspace_id = 2;
+ // Enterprise license JWT token.
+ string license = 3;
}
enum SettingName {
@@ -21,7 +23,7 @@ enum SettingName {
SYSTEM = 1;
WORKSPACE_PROFILE = 4;
WORKSPACE_APPROVAL = 5;
- ENTERPRISE_LICENSE = 7;
+ // 7 was ENTERPRISE_LICENSE, migrated to SYSTEM setting
APP_IM = 8;
AI = 10;
DATA_CLASSIFICATION = 14;