Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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())
}
}
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func All() []plugin.MigrationScript {
new(modifyCicdDeploymentsToText),
new(increaseCqIssuesProjectKeyLength),
new(addAuthSessions),
new(changeIssueComponentToText),
new(addCqProjectMetricsHistory),
}
}