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: remove unused (#10010)
Danny Xu1030876ba7a6
diff --git a/backend/api/v1/schema_design_transformer.go b/backend/api/v1/schema_design_transformer.goindex 4751f88912..70908a30ca 100644--- a/backend/api/v1/schema_design_transformer.go+++ b/backend/api/v1/schema_design_transformer.go@@ -492,14 +492,12 @@ func (i *indexState) toString(buf *strings.Builder) error {}type defaultValue interface {- isDefaultValue()toString() string}type defaultValueNull struct {}-func (*defaultValueNull) isDefaultValue() {}func (*defaultValueNull) toString() string {return "NULL"}@@ -508,7 +506,6 @@ type defaultValueString struct {value string}-func (*defaultValueString) isDefaultValue() {}func (d *defaultValueString) toString() string {return fmt.Sprintf("'%s'", strings.ReplaceAll(d.value, "'", "''"))}@@ -517,7 +514,6 @@ type defaultValueExpression struct {value string}-func (*defaultValueExpression) isDefaultValue() {}func (d *defaultValueExpression) toString() string {return d.value}diff --git a/backend/common/convert.go b/backend/common/convert.goindex 4d560a1e6f..ec4b231eb4 100644--- a/backend/common/convert.go+++ b/backend/common/convert.go@@ -84,21 +84,6 @@ var ProjectMemberCELAttributes = []cel.EnvOption{cel.ParserExpressionSizeLimit(celLimit),}-// ConvertParsedRisk converts parsed risk to unparsed format.-func ConvertParsedRisk(expression *exprproto.ParsedExpr) (*expr.Expr, error) {- if expression == nil || expression.Expr == nil {- return nil, nil- }- ast := cel.ParsedExprToAst(expression)- expressionStr, err := cel.AstToString(ast)- if err != nil {- return nil, status.Errorf(codes.InvalidArgument, "failed to deparse expression: %v", err)- }- return &expr.Expr{- Expression: expressionStr,- }, nil-}-// ConvertUnparsedRisk converts unparsed risk to parsed format.func ConvertUnparsedRisk(expression *expr.Expr) (*exprproto.ParsedExpr, error) {if expression == nil || expression.Expression == "" {@@ -120,21 +105,6 @@ func ConvertUnparsedRisk(expression *expr.Expr) (*exprproto.ParsedExpr, error) {return expr, nil}-// ConvertParsedApproval converts parsed approval to unparsed format.-func ConvertParsedApproval(expression *exprproto.ParsedExpr) (*expr.Expr, error) {- if expression == nil || expression.Expr == nil {- return nil, nil- }- ast := cel.ParsedExprToAst(expression)- expressionStr, err := cel.AstToString(ast)- if err != nil {- return nil, status.Errorf(codes.InvalidArgument, "failed to deparse expression: %v", err)- }- return &expr.Expr{- Expression: expressionStr,- }, nil-}-// ConvertUnparsedApproval converts unparsed approval to parsed format.func ConvertUnparsedApproval(expression *expr.Expr) (*exprproto.ParsedExpr, error) {if expression == nil || expression.Expression == "" {diff --git a/backend/common/error.go b/backend/common/error.goindex 6be17bed33..fe89da0a13 100644--- a/backend/common/error.go+++ b/backend/common/error.go@@ -93,18 +93,6 @@ func ErrorCode(err error) Code {return Internal}-// ErrorMessage unwraps an application error and returns its message.-// Non-application errors always return "Internal error".-func ErrorMessage(err error) string {- var e *Error- if err == nil {- return ""- } else if errors.As(err, &e) {- return e.Err.Error()- }- return "Internal error."-}-// Wrapf is a helper function to wrap an Error with given code and formatted message.func Wrapf(err error, code Code, format string, args ...any) *Error {return &Error{diff --git a/backend/common/log/slog_utils.go b/backend/common/log/slog_utils.goindex 1ddf2e50f0..7f25dc721f 100644--- a/backend/common/log/slog_utils.go+++ b/backend/common/log/slog_utils.go@@ -49,7 +49,3 @@ func BBStack(key string) slog.Attr {stack := stacktrace.TakeStacktrace(20 /* n */, 3 /* skip */)return slog.Any(key, stack)}--func BBStrings(key string, ss []string) slog.Attr {- return slog.Any(key, ss)-}diff --git a/backend/common/util.go b/backend/common/util.goindex 0f7e42021c..4c2546fd2a 100644--- a/backend/common/util.go+++ b/backend/common/util.go@@ -9,7 +9,6 @@ import ("path""path/filepath""regexp"- "sort""strconv""strings""time"@@ -35,16 +34,6 @@ const (ExternalURLPlaceholder = "https://www.bytebase.com/docs/get-started/install/external-url")-// FindString returns the search index of sorted strings.-func FindString(stringList []string, search string) int {- sort.Strings(stringList)- i := sort.SearchStrings(stringList, search)- if i == len(stringList) {- return -1- }- return i-}-var letters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")// RandomString returns a random string with length n.diff --git a/backend/legacyapi/api.go b/backend/legacyapi/api.goindex f41f7e9580..92068b2af3 100644--- a/backend/legacyapi/api.go+++ b/backend/legacyapi/api.go@@ -1,12 +1,6 @@// Package api provides the definition of all APIs.package api-import (- "strings"-- "github.com/pkg/errors"-)-// UnknownID is the ID for unknowns.const UnknownID = -1@@ -34,14 +28,3 @@ const (// DefaultPageSize is the default number of items in a page.DefaultPageSize = 1000)--// StringToSortOrder converts a valid string to SortOrder.-func StringToSortOrder(s string) (SortOrder, error) {- switch strings.ToUpper(s) {- case string(ASC):- return ASC, nil- case string(DESC):- return DESC, nil- }- return SortOrder(""), errors.Errorf("%q cannot be converted to SortOrder", s)-}diff --git a/backend/legacyapi/policy.go b/backend/legacyapi/policy.goindex 72c7f811fb..063aaaee1d 100644--- a/backend/legacyapi/policy.go+++ b/backend/legacyapi/policy.go@@ -186,15 +186,6 @@ type DisableCopyDataPolicy struct {Active bool `json:"active"`}-// UnmarshalDisableCopyDataPolicyPolicy will unmarshal payload to disable copy data policy.-func UnmarshalDisableCopyDataPolicyPolicy(payload string) (*DisableCopyDataPolicy, error) {- var p DisableCopyDataPolicy- if err := json.Unmarshal([]byte(payload), &p); err != nil {- return nil, errors.Wrapf(err, "failed to unmarshal disable copy data policy %q", payload)- }- return &p, nil-}-// String will return the string representation of the policy.func (p *DisableCopyDataPolicy) String() (string, error) {s, err := json.Marshal(p)@@ -234,23 +225,3 @@ func UnmarshalEnvironmentTierPolicy(payload string) (*EnvironmentTierPolicy, err}return &p, nil}--// GetPolicyResourceType gets the policy resource type.-func GetPolicyResourceType(resourceType string) (PolicyResourceType, error) {- var rt PolicyResourceType- switch resourceType {- case "workspace":- rt = PolicyResourceTypeWorkspace- case "environment":- rt = PolicyResourceTypeEnvironment- case "project":- rt = PolicyResourceTypeProject- case "instance":- rt = PolicyResourceTypeInstance- case "database":- rt = PolicyResourceTypeDatabase- default:- return PolicyResourceTypeUnknown, errors.Errorf("invalid policy resource type %q", rt)- }- return rt, nil-}diff --git a/backend/legacyapi/project.go b/backend/legacyapi/project.goindex c292fe0430..53e6f10eed 100644--- a/backend/legacyapi/project.go+++ b/backend/legacyapi/project.go@@ -1,9 +1,6 @@package apiimport (- "regexp"- "strings"-"github.com/pkg/errors""github.com/bytebase/bytebase/backend/common"@@ -165,36 +162,3 @@ func ValidateRepositorySchemaPathTemplate(schemaPathTemplate string, tenantMode}return nil}--// FormatTemplate formats the template by using the tokens as a replacement mapping.-// Note that the returned (modified) template should not be used as a regexp.-func FormatTemplate(template string, tokens map[string]string) (string, error) {- keys, _ := common.ParseTemplateTokens(template)- for _, key := range keys {- if _, ok := tokens[key]; !ok {- return "", errors.Errorf("token %q not found", key)- }- template = strings.ReplaceAll(template, key, tokens[key])- }- return template, nil-}--// Similar to FormatTemplate, except that it will also escape special regexp characters in the delimiters-// of the template string, which will produce the correct regexp string.-func formatTemplateRegexp(template string, tokens map[string]string) (string, error) {- keys, delimiters := common.ParseTemplateTokens(template)- for _, key := range keys {- if _, ok := tokens[key]; !ok {- return "", errors.Errorf("token %q not found", key)- }- template = strings.ReplaceAll(template, key, tokens[key])- }- for _, delimiter := range delimiters {- quoted := regexp.QuoteMeta(delimiter)- if quoted != delimiter {- // The delimiter is a special regexp character, we should escape it.- template = strings.Replace(template, delimiter, quoted, 1)- }- }- return template, nil-}diff --git a/backend/legacyapi/project_setting.go b/backend/legacyapi/project_setting.godeleted file mode 100644index cc775d0d19..0000000000--- a/backend/legacyapi/project_setting.go+++ /dev/null@@ -1,43 +0,0 @@-package api--import (- "encoding/json"- "errors"-)--// LGTMCheckValue is the type of the LGTM check value.-type LGTMCheckValue string--const (- // LGTMValueDisabled means no LGTM check.- LGTMValueDisabled LGTMCheckValue = "DISABLED"- // LGTMValueProjectOwner means check LGTM from project owners.- LGTMValueProjectOwner LGTMCheckValue = "PROJECT_OWNER"- // LGTMValueProjectMember means check LGTM from project members.- LGTMValueProjectMember LGTMCheckValue = "PROJECT_MEMBER"-)--// LGTMCheckSetting is the setting of LGTM check.-type LGTMCheckSetting struct {- Value LGTMCheckValue `json:"value" jsonapi:"attr,value"`-}--// GetDefaultLGTMCheckSetting returns the default LGTM check setting.-func GetDefaultLGTMCheckSetting() LGTMCheckSetting {- return LGTMCheckSetting{- Value: LGTMValueDisabled,- }-}--// Scan implements database/sql Scanner interface, converts JSONB to LGTMCheckSetting struct.-func (s *LGTMCheckSetting) Scan(src any) error {- if bs, ok := src.([]byte); ok {- if string(bs) == "{}" {- // handle '{}', return default values- *s = GetDefaultLGTMCheckSetting()- return nil- }- return json.Unmarshal(bs, s)- }- return errors.New("failed to scan lgtm_check")-}diff --git a/backend/legacyapi/project_test.go b/backend/legacyapi/project_test.goindex aad895a78d..5f7ddaa613 100644--- a/backend/legacyapi/project_test.go+++ b/backend/legacyapi/project_test.go@@ -150,103 +150,3 @@ func TestValidateRepositorySchemaPathTemplate(t *testing.T) {}}}--func TestFormatTemplate(t *testing.T) {- tests := []struct {- name string- template string- tokens map[string]string- want string- errPart string- }{- {- "valid",- "{{DB_NAME}}_hello_{{LOCATION}}",- map[string]string{- "{{DB_NAME}}": "db1",- "{{LOCATION}}": "us-central1",- },- "db1_hello_us-central1",- "",- },- {- "tokenNotFound",- "{{DB_NAME}}_hello_{{LOCATION}}",- map[string]string{- "{{DB_NAME}}": "db1",- },- "",- "not found",- },- {- "template with regex meta",- "{{DB_NAME}}_hello_${{LOCATION}}",- map[string]string{- "{{DB_NAME}}": "db1",- "{{LOCATION}}": "us-central1",- },- "db1_hello_$us-central1",- "",- },- }-- for _, test := range tests {- got, err := FormatTemplate(test.template, test.tokens)- if test.errPart == "" {- require.NoError(t, err)- } else {- require.Contains(t, err.Error(), test.errPart)- }- require.Equal(t, got, test.want)- }-}--func TestBuildTemplateExpr(t *testing.T) {- tests := []struct {- name string- template string- tokens map[string]string- want string- errPart string- }{- {- "valid",- "{{DB_NAME}}_hello-{{LOCATION}}",- map[string]string{- "{{DB_NAME}}": "db1",- "{{LOCATION}}": "us-central1",- },- "db1_hello-us-central1",- "",- },- {- "tokenNotFound",- "{{DB_NAME}}_hello_{{LOCATION}}",- map[string]string{- "{{DB_NAME}}": "db1",- },- "",- "not found",- },- {- "template with regex meta",- "{{DB_NAME}}_hello_${{LOCATION}}",- map[string]string{- "{{DB_NAME}}": "db1",- "{{LOCATION}}": "us-central1",- },- "db1_hello_\\$us-central1",- "",- },- }-- for _, test := range tests {- got, err := formatTemplateRegexp(test.template, test.tokens)- if test.errPart == "" {- require.NoError(t, err)- } else {- require.Contains(t, err.Error(), test.errPart)- }- require.Equal(t, got, test.want)- }-}diff --git a/backend/plugin/advisor/sql_review.go b/backend/plugin/advisor/sql_review.goindex c2b3584309..1a4defddb5 100644--- a/backend/plugin/advisor/sql_review.go+++ b/backend/plugin/advisor/sql_review.go@@ -988,12 +988,6 @@ func getViewDefinition(checkContext SQLReviewCheckContext, viewList []string) (sreturn buf.String(), nil}-// RuleExists returns true if rule exists.-func RuleExists(ruleType SQLReviewRuleType, engine storepb.Engine) bool {- _, err := getAdvisorTypeByRule(ruleType, engine)- return err == nil-}-func getAdvisorTypeByRule(ruleType SQLReviewRuleType, engine storepb.Engine) (Type, error) {switch ruleType {case SchemaRuleStatementRequireWhere:diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex 04bfb73520..fb21211487 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -171,17 +171,6 @@ func RefreshToken(ctx context.Context, s *store.Store, webURL string) common.Tok}}-// GetTaskStatement gets the statement of a task.-func GetTaskStatement(taskPayload string) (string, error) {- var taskStatement struct {- Statement string `json:"statement"`- }- if err := json.Unmarshal([]byte(taskPayload), &taskStatement); err != nil {- return "", err- }- return taskStatement.Statement, nil-}-// GetTaskSheetID gets the sheetID of a task.func GetTaskSheetID(taskPayload string) (int, error) {var taskSheetID struct {