Skip to content

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

refactor: cleanup unused database name template (#8616)

Danny Xuac3d9d191b00
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index 7616a23274..fb9672df44 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -147,8 +147,6 @@ func (s *ProjectService) UpdateProject(ctx context.Context, request *v1pb.Update
case "tenant_mode":
tenantMode := convertToProjectTenantMode(request.Project.TenantMode)
patch.TenantMode = &tenantMode
- case "db_name_template":
- patch.DBNameTemplate = &request.Project.DbNameTemplate
case "schema_change":
schemaChange := convertToProjectSchemaChangeType(request.Project.SchemaChange)
patch.SchemaChangeType = &schemaChange
@@ -2670,7 +2668,6 @@ func convertToProject(projectMessage *store.ProjectMessage) *v1pb.Project {
Workflow: workflow,
Visibility: visibility,
TenantMode: tenantMode,
- DbNameTemplate: projectMessage.DBNameTemplate,
SchemaChange: schemaChange,
Webhooks: projectWebhooks,
DataClassificationConfigId: projectMessage.DataClassificationConfigID,
@@ -2736,7 +2733,6 @@ func convertToProjectMessage(resourceID string, project *v1pb.Project) (*store.P
Workflow: workflow,
Visibility: visibility,
TenantMode: tenantMode,
- DBNameTemplate: project.DbNameTemplate,
SchemaChangeType: schemaChange,
}, nil
}
diff --git a/backend/legacyapi/project.go b/backend/legacyapi/project.go
index 3c93ff486e..c292fe0430 100644
--- a/backend/legacyapi/project.go
+++ b/backend/legacyapi/project.go
@@ -101,12 +101,7 @@ var (
DBNameToken: true,
EnvironmentToken: false,
}
- tenantSchemaPathTemplateTokens = map[string]bool{}
- allowedProjectDBNameTemplateTokens = map[string]bool{
- DBNameToken: true,
- LocationToken: true,
- TenantToken: true,
- }
+ tenantSchemaPathTemplateTokens = map[string]bool{}
)
// ValidateRepositoryFilePathTemplate validates the repository file path template.
@@ -171,28 +166,6 @@ func ValidateRepositorySchemaPathTemplate(schemaPathTemplate string, tenantMode
return nil
}
-// ValidateProjectDBNameTemplate validates the project database name template.
-func ValidateProjectDBNameTemplate(template string) error {
- if template == "" {
- return nil
- }
- tokens, _ := common.ParseTemplateTokens(template)
- // Must contain {{DB_NAME}}
- hasDBName := false
- for _, token := range tokens {
- if token == DBNameToken {
- hasDBName = true
- }
- if _, ok := allowedProjectDBNameTemplateTokens[token]; !ok {
- return errors.Errorf("invalid token %v in database name template", token)
- }
- }
- if !hasDBName {
- return errors.Errorf("project database name template must include token %v", DBNameToken)
- }
- 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) {
diff --git a/backend/legacyapi/project_test.go b/backend/legacyapi/project_test.go
index c87ab5f4ba..aad895a78d 100644
--- a/backend/legacyapi/project_test.go
+++ b/backend/legacyapi/project_test.go
@@ -151,41 +151,6 @@ func TestValidateRepositorySchemaPathTemplate(t *testing.T) {
}
}
-func TestValidateProjectDBNameTemplate(t *testing.T) {
- tests := []struct {
- name string
- template string
- errPart string
- }{
- {
- "location",
- "{{DB_NAME}}_hello_{{LOCATION}}",
- "",
- }, {
- "tenant",
- "{{DB_NAME}}_{{TENANT}}.sql",
- "",
- }, {
- "InvalidToken",
- "{{DB_NAME}}_{{TYPE}}",
- "invalid token {{TYPE}}",
- }, {
- "DatabaseNameTokenNotExists",
- "{{TENANT}}",
- "must include token {{DB_NAME}}",
- },
- }
-
- for _, test := range tests {
- err := ValidateProjectDBNameTemplate(test.template)
- if test.errPart == "" {
- require.NoError(t, err)
- } else {
- require.Contains(t, err.Error(), test.errPart)
- }
- }
-}
-
func TestFormatTemplate(t *testing.T) {
tests := []struct {
name string
diff --git a/backend/store/project.go b/backend/store/project.go
index acd0b71d03..44d6e1d6ff 100644
--- a/backend/store/project.go
+++ b/backend/store/project.go
@@ -22,7 +22,6 @@ type ProjectMessage struct {
Workflow api.ProjectWorkflowType
Visibility api.ProjectVisibility
TenantMode api.ProjectTenantMode
- DBNameTemplate string
SchemaChangeType api.ProjectSchemaChangeType
Webhooks []*ProjectWebhookMessage
DataClassificationConfigID string
@@ -49,7 +48,6 @@ type UpdateProjectMessage struct {
Title *string
Key *string
TenantMode *api.ProjectTenantMode
- DBNameTemplate *string
Workflow *api.ProjectWorkflowType
SchemaChangeType *api.ProjectSchemaChangeType
DataClassificationConfigID *string
@@ -159,7 +157,6 @@ func (s *Store) CreateProjectV2(ctx context.Context, create *ProjectMessage, cre
Workflow: create.Workflow,
Visibility: create.Visibility,
TenantMode: create.TenantMode,
- DBNameTemplate: create.DBNameTemplate,
SchemaChangeType: create.SchemaChangeType,
DataClassificationConfigID: create.DataClassificationConfigID,
Setting: create.Setting,
@@ -190,7 +187,7 @@ func (s *Store) CreateProjectV2(ctx context.Context, create *ProjectMessage, cre
create.Workflow,
create.Visibility,
create.TenantMode,
- create.DBNameTemplate,
+ "",
create.SchemaChangeType,
create.DataClassificationConfigID,
payload,
@@ -265,9 +262,6 @@ func (s *Store) updateProjectImplV2(ctx context.Context, tx *Tx, patch *UpdatePr
if v := patch.TenantMode; v != nil {
set, args = append(set, fmt.Sprintf("tenant_mode = $%d", len(args)+1)), append(args, *v)
}
- if v := patch.DBNameTemplate; v != nil {
- set, args = append(set, fmt.Sprintf("db_name_template = $%d", len(args)+1)), append(args, *v)
- }
if v := patch.Workflow; v != nil {
set, args = append(set, fmt.Sprintf("workflow_type = $%d", len(args)+1)), append(args, *v)
}
@@ -302,7 +296,6 @@ func (s *Store) updateProjectImplV2(ctx context.Context, tx *Tx, patch *UpdatePr
workflow_type,
visibility,
tenant_mode,
- db_name_template,
schema_change_type,
data_classification_config_id,
setting,
@@ -317,7 +310,6 @@ func (s *Store) updateProjectImplV2(ctx context.Context, tx *Tx, patch *UpdatePr
&project.Workflow,
&project.Visibility,
&project.TenantMode,
- &project.DBNameTemplate,
&project.SchemaChangeType,
&project.DataClassificationConfigID,
&payload,
@@ -365,7 +357,6 @@ func (s *Store) listProjectImplV2(ctx context.Context, tx *Tx, find *FindProject
workflow_type,
visibility,
tenant_mode,
- db_name_template,
schema_change_type,
data_classification_config_id,
setting,
@@ -391,7 +382,6 @@ func (s *Store) listProjectImplV2(ctx context.Context, tx *Tx, find *FindProject
&projectMessage.Workflow,
&projectMessage.Visibility,
&projectMessage.TenantMode,
- &projectMessage.DBNameTemplate,
&projectMessage.SchemaChangeType,
&projectMessage.DataClassificationConfigID,
&payload,