Skip to content

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

chore: revert changes for classification (#11172)

ecmadao709327892b7f
diff --git a/backend/common/db_schema.go b/backend/common/db_schema.go
index 1c19caf1c3..48eba355c3 100644
--- a/backend/common/db_schema.go
+++ b/backend/common/db_schema.go
@@ -1,43 +1,14 @@
package common
import (
- "fmt"
- "os"
"regexp"
"strings"
)
-// classificationIDPattern is the pattern for classification, it should joined id (numbers) by "-", like 1-2, 1-2-3.
-const classificationIDPattern = "^[0-9]+(-([0-9])+){0,}"
-
var numberReg = regexp.MustCompile("^[0-9]+$")
-func getClassificationAndUserCommentFromLegacy(comment string) (string, string) {
- classificationIDReg := regexp.MustCompile(classificationIDPattern)
- classification := classificationIDReg.FindString(comment)
- if classification == comment {
- // the extract classification id matches full comment, for example, raw comment is "1-2-3"
- return classification, ""
- }
-
- // we will handle "{classification id}-{comment}" and "{classification id} {comment}"
- classificationIDReg = regexp.MustCompile(fmt.Sprintf(`%s[-|\s]{1}`, classificationIDPattern))
- classification = classificationIDReg.FindString(comment)
-
- userComment := strings.TrimPrefix(comment, classification)
- classification = strings.TrimSuffix(classification, "-")
- classification = strings.TrimSuffix(classification, " ")
- return classification, userComment
-}
-
// GetClassificationAndUserComment parses classification and user comment from the given comment.
func GetClassificationAndUserComment(comment string) (string, string) {
- workspaceID := os.Getenv("BYTEBASE_WORKSPACE_ID")
- if workspaceID == "a4fea42c-c097-47c3-b661-4a6fcea1cf6d" {
- // handle legacy data in specific workspace
- return getClassificationAndUserCommentFromLegacy(comment)
- }
-
sections := strings.Split(comment, "-")
classification := []string{}
userComment := ""
diff --git a/backend/common/db_schema_test.go b/backend/common/db_schema_test.go
index 7a07e49675..4930c245b5 100644
--- a/backend/common/db_schema_test.go
+++ b/backend/common/db_schema_test.go
@@ -2,7 +2,6 @@ package common
import (
"fmt"
- "os"
"testing"
"github.com/stretchr/testify/assert"
@@ -13,101 +12,76 @@ func TestClassification(t *testing.T) {
rawComment string
classification string
userComment string
- rebuildComment string
- workspaceID string
}{
{
rawComment: "1abc",
classification: "",
userComment: "1abc",
- rebuildComment: "1abc",
},
{
rawComment: "abc",
classification: "",
userComment: "abc",
- rebuildComment: "abc",
},
{
rawComment: "-abc",
classification: "",
userComment: "-abc",
- rebuildComment: "-abc",
},
{
rawComment: "0-abc",
classification: "0",
userComment: "abc",
- rebuildComment: "0-abc",
},
{
rawComment: "1-2-abc",
classification: "1-2",
userComment: "abc",
- rebuildComment: "1-2-abc",
- },
- {
- rawComment: "1-2 abc",
- classification: "1-2",
- userComment: "abc",
- rebuildComment: "1-2-abc",
- workspaceID: "a4fea42c-c097-47c3-b661-4a6fcea1cf6d",
- },
- {
- rawComment: "1 abc",
- classification: "1",
- userComment: "abc",
- rebuildComment: "1-abc",
- workspaceID: "a4fea42c-c097-47c3-b661-4a6fcea1cf6d",
},
{
rawComment: "1",
classification: "1",
userComment: "",
- rebuildComment: "1",
},
{
rawComment: "1- 2",
classification: "1",
userComment: " 2",
- rebuildComment: "1- 2",
- },
- {
- rawComment: "1 2",
- classification: "1",
- userComment: "2",
- rebuildComment: "1-2",
- workspaceID: "a4fea42c-c097-47c3-b661-4a6fcea1cf6d",
},
{
rawComment: "1-2",
classification: "1-2",
userComment: "",
- rebuildComment: "1-2",
},
{
rawComment: "1-2a",
classification: "1",
userComment: "2a",
- rebuildComment: "1-2a",
},
{
rawComment: "1:a",
classification: "",
userComment: "1:a",
- rebuildComment: "1:a",
+ },
+ {
+ rawComment: "1-2 abc",
+ classification: "1",
+ userComment: "2 abc",
+ },
+ {
+ rawComment: "1 2",
+ classification: "",
+ userComment: "1 2",
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("test classification for comment: %v", test.rawComment), func(t *testing.T) {
- err := os.Setenv("BYTEBASE_WORKSPACE_ID", test.workspaceID)
- assert.NoError(t, err)
classification, userComment := GetClassificationAndUserComment(test.rawComment)
assert.Equal(t, test.classification, classification)
assert.Equal(t, test.userComment, userComment)
rebuildComment := GetCommentFromClassificationAndUserComment(classification, userComment)
- assert.Equal(t, test.rebuildComment, rebuildComment)
+ assert.Equal(t, test.rawComment, rebuildComment)
})
}
}
diff --git a/backend/server/init.go b/backend/server/init.go
index 7882cc3351..3e49aae777 100644
--- a/backend/server/init.go
+++ b/backend/server/init.go
@@ -2,7 +2,6 @@ package server
import (
"context"
- "os"
"time"
"github.com/google/uuid"
@@ -49,15 +48,11 @@ func (s *Server) getInitSetting(ctx context.Context, datastore *store.Store) (st
secret = authSetting.Value
// initial workspace
- workspaceIDSetting, _, err := datastore.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
+ if _, _, err := datastore.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
Name: api.SettingWorkspaceID,
Value: uuid.New().String(),
Description: "The workspace identifier",
- }, api.SystemBotID)
- if err != nil {
- return "", 0, err
- }
- if err := os.Setenv("BYTEBASE_WORKSPACE_ID", workspaceIDSetting.Value); err != nil {
+ }, api.SystemBotID); err != nil {
return "", 0, err
}