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: consolidate feature enablement (#3683)
Tianzhou (天舟)b34f3e61e760
diff --git a/api/plan.go b/api/plan.goindex 90f3ee1b9c..30551d884f 100644--- a/api/plan.go+++ b/api/plan.go@@ -3,8 +3,6 @@ package apiimport ("fmt""math"-- "github.com/bytebase/bytebase/common")// PlanType is the type for a plan.@@ -204,7 +202,7 @@ func (e FeatureType) AccessErrorMessage() string {// minimumSupportedPlan will find the minimum plan which supports the target feature.func (e FeatureType) minimumSupportedPlan() PlanType {- for i, enabled := range featureMatrix[e].planToggle {+ for i, enabled := range featureMatrix[e] {if enabled {return PlanType(i)}@@ -213,101 +211,34 @@ func (e FeatureType) minimumSupportedPlan() PlanType {return ENTERPRISE}-type featureConfig struct {- // whether a particular feature is enabled in the release build. This allows us to progressively develop the feature- // without exposing to the public.- enabled bool- // whether a particular feature is available in [FREE, TEAM, Enterprise] plan respectively.- planToggle [3]bool-}--// featureMatrix is a map from the a particular feature to the respective enablement of a particular plan.-var featureMatrix = map[FeatureType]featureConfig{+// featureMatrix is a map from the a particular feature to the respective enablement of a particular+// plan in [FREE, TEAM, Enterprise].+var featureMatrix = map[FeatureType][3]bool{// Admin & Security- Feature3rdPartyAuth: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureRBAC: {- enabled: true,- planToggle: [3]bool{false, true, true},- },+ Feature3rdPartyAuth: {false, true, true},+ FeatureRBAC: {false, true, true},// Branding- FeatureBranding: {- enabled: true,- planToggle: [3]bool{false, false, true},- },+ FeatureBranding: {false, false, true},// Change Workflow- FeatureDataSource: {- enabled: true,- planToggle: [3]bool{false, false, false},- },- FeatureDBAWorkflow: {- enabled: true,- planToggle: [3]bool{false, false, true},- },- FeatureLGTM: {- enabled: true,- planToggle: [3]bool{false, false, true},- },- FeatureIMApproval: {- enabled: true,- planToggle: [3]bool{false, false, true},- },- FeatureMultiTenancy: {- enabled: true,- planToggle: [3]bool{false, false, true},- },- FeatureOnlineMigration: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureSchemaDrift: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureSQLReview: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureTaskScheduleTime: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureVCSSQLReviewWorkflow: {- enabled: true,- planToggle: [3]bool{false, false, true},- },+ FeatureDataSource: {false, false, false},+ FeatureDBAWorkflow: {false, false, true},+ FeatureLGTM: {false, false, true},+ FeatureIMApproval: {false, false, true},+ FeatureMultiTenancy: {false, false, true},+ FeatureOnlineMigration: {false, true, true},+ FeatureSchemaDrift: {false, true, true},+ FeatureSQLReview: {false, true, true},+ FeatureTaskScheduleTime: {false, true, true},+ FeatureVCSSQLReviewWorkflow: {false, false, true},// Database management- FeaturePITR: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureReadReplicaConnection: {- enabled: true,- planToggle: [3]bool{false, false, true},- },- FeatureSyncSchemaAllVersions: {- enabled: true,- planToggle: [3]bool{false, false, true},- },+ FeaturePITR: {false, true, true},+ FeatureReadReplicaConnection: {false, false, true},+ FeatureSyncSchemaAllVersions: {false, false, true},// Policy Control- FeatureApprovalPolicy: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureBackupPolicy: {- enabled: true,- planToggle: [3]bool{false, true, true},- },- FeatureEnvironmentTierPolicy: {- enabled: true,- planToggle: [3]bool{false, false, true},- },- FeatureSensitiveData: {- enabled: true,- planToggle: [3]bool{false, false, true},- },+ FeatureApprovalPolicy: {false, true, true},+ FeatureBackupPolicy: {false, true, true},+ FeatureEnvironmentTierPolicy: {false, false, true},+ FeatureSensitiveData: {false, false, true},}// Plan is the API message for a plan.@@ -345,14 +276,5 @@ var PlanLimitValues = map[PlanLimit][3]int64{// Feature returns whether a particular feature is available in a particular plan.func Feature(feature FeatureType, plan PlanType) bool {- return featureMatrix[feature].planToggle[plan]-}--// FeatureEnabled returns whether a particular feature is enabled.-func FeatureEnabled(feature FeatureType, mode common.ReleaseMode) bool {- // Feature is always enabled in dev mode.- if mode == common.ReleaseModeDev {- return true- }- return featureMatrix[feature].enabled+ return featureMatrix[feature][plan]}diff --git a/store/feature_flag.go b/common/feature_flag.gosimilarity index 98%rename from store/feature_flag.gorename to common/feature_flag.goindex c6f4d797f9..d5ddd4498a 100644--- a/store/feature_flag.go+++ b/common/feature_flag.go@@ -1,4 +1,4 @@-package store+package common// Have a single place to track all ongoing feature development that requires code to work with both// old and new schecma. We need to gate the feature to make the code be compatible with both devdiff --git a/store/feature_flag_dev.go b/common/feature_flag_dev.gosimilarity index 94%rename from store/feature_flag_dev.gorename to common/feature_flag_dev.goindex 09039aad86..5893ce5dc9 100644--- a/store/feature_flag_dev.go+++ b/common/feature_flag_dev.go@@ -1,7 +1,7 @@//go:build !release// +build !release-package store+package common// FeatureFlag in dev build always returns true.// Because dev schema always has the latest change and is compatible with the new feature code.diff --git a/store/feature_flag_prod.go b/common/feature_flag_prod.gosimilarity index 94%rename from store/feature_flag_prod.gorename to common/feature_flag_prod.goindex cd1036885c..fc5301fc2a 100644--- a/store/feature_flag_prod.go+++ b/common/feature_flag_prod.go@@ -1,7 +1,7 @@//go:build release// +build release-package store+package common// FeatureFlag in release build always returns false.// Because we would remove the FeatureFlag check entirely after the schema change for the featurediff --git a/server/project.go b/server/project.goindex a5f3aa8560..75a68a9560 100644--- a/server/project.go+++ b/server/project.go@@ -327,10 +327,6 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {})g.POST("/project/:projectID/repository/:repositoryID/sql-review-ci", func(c echo.Context) error {- if !api.FeatureEnabled(api.FeatureVCSSQLReviewWorkflow, s.profile.Mode) {- return echo.NewHTTPError(http.StatusBadRequest, "SQL review CI feature is not enabled")- }-ctx := c.Request().Context()projectID, err := strconv.Atoi(c.Param("projectID"))if err != nil {