diff --git a/backend/core/models/migrationscripts/20260629_change_issue_component_to_text.go b/backend/core/models/migrationscripts/20260629_change_issue_component_to_text.go new file mode 100644 index 00000000000..94d965d6295 --- /dev/null +++ b/backend/core/models/migrationscripts/20260629_change_issue_component_to_text.go @@ -0,0 +1,41 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrationscripts + +import ( + "github.com/apache/incubator-devlake/core/context" + "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/plugin" +) + +var _ plugin.MigrationScript = (*changeIssueComponentToText)(nil) + +type changeIssueComponentToText struct{} + +func (*changeIssueComponentToText) Up(basicRes context.BasicRes) errors.Error { + // The 20240813 migration targeted the non-existent plural "components" column. + return basicRes.GetDal().ModifyColumnType("issues", "component", "text") +} + +func (*changeIssueComponentToText) Version() uint64 { + return 20260629120000 +} + +func (*changeIssueComponentToText) Name() string { + return "change issues.component type to text" +} diff --git a/backend/core/models/migrationscripts/20260629_change_issue_component_to_text_test.go b/backend/core/models/migrationscripts/20260629_change_issue_component_to_text_test.go new file mode 100644 index 00000000000..482c42b5001 --- /dev/null +++ b/backend/core/models/migrationscripts/20260629_change_issue_component_to_text_test.go @@ -0,0 +1,82 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrationscripts + +import ( + "testing" + + "github.com/apache/incubator-devlake/core/context" + "github.com/apache/incubator-devlake/core/dal" + "github.com/apache/incubator-devlake/core/errors" +) + +type modifyColumnTypeCall struct { + tableName string + columnName string + columnType string +} + +type recordingDal struct { + dal.Dal + call *modifyColumnTypeCall +} + +func (d *recordingDal) ModifyColumnType(tableName string, columnName string, columnType string) errors.Error { + d.call = &modifyColumnTypeCall{tableName, columnName, columnType} + return nil +} + +type basicResWithDal struct { + context.BasicRes + database dal.Dal +} + +func (r *basicResWithDal) GetDal() dal.Dal { + return r.database +} + +func TestChangeIssueComponentToText(t *testing.T) { + database := new(recordingDal) + script := new(changeIssueComponentToText) + + if err := script.Up(&basicResWithDal{database: database}); err != nil { + t.Fatalf("migration failed: %v", err) + } + + want := &modifyColumnTypeCall{"issues", "component", "text"} + if database.call == nil || *database.call != *want { + t.Fatalf("ModifyColumnType call = %#v, want %#v", database.call, want) + } + if script.Version() != 20260629120000 { + t.Fatalf("Version() = %d, want 20260629120000", script.Version()) + } + if script.Name() != "change issues.component type to text" { + t.Fatalf("Name() = %q, want %q", script.Name(), "change issues.component type to text") + } + + found := false + for _, registeredScript := range All() { + if registeredScript.Version() == script.Version() { + found = true + break + } + } + if !found { + t.Fatalf("migration version %d is not registered", script.Version()) + } +} diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go index 76f2e96838b..9292bed13b6 100644 --- a/backend/core/models/migrationscripts/register.go +++ b/backend/core/models/migrationscripts/register.go @@ -145,6 +145,7 @@ func All() []plugin.MigrationScript { new(modifyCicdDeploymentsToText), new(increaseCqIssuesProjectKeyLength), new(addAuthSessions), + new(changeIssueComponentToText), new(addCqProjectMetricsHistory), } }