Skip to content

Commit 7165b5b

Browse files
authored
fix(plugins): fix raw table schemas and cleanup legacy table structures in testmo (#8566)
When using a new database, there were issues with the testmo plugin. This fixes pipeline issues by ensuring proper raw table naming conventions and schema consistency for testmo data import.
1 parent 5da21bf commit 7165b5b

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/dal"
23+
"github.com/apache/incubator-devlake/core/errors"
24+
"github.com/apache/incubator-devlake/core/plugin"
25+
)
26+
27+
type fixRawTableNamesAndSchemas struct{}
28+
29+
func (*fixRawTableNamesAndSchemas) Up(basicRes context.BasicRes) errors.Error {
30+
db := basicRes.GetDal()
31+
32+
legacy := []string{
33+
"testmo_projects",
34+
"testmo_milestones",
35+
"testmo_automation_runs",
36+
"testmo_runs",
37+
}
38+
for _, tbl := range legacy {
39+
if db.HasTable(tbl) {
40+
if err := db.DropTables(tbl); err != nil {
41+
return err
42+
}
43+
}
44+
}
45+
46+
current := []string{
47+
"_raw_testmo_projects",
48+
"_raw_testmo_milestones",
49+
"_raw_testmo_automation_runs",
50+
"_raw_testmo_runs",
51+
}
52+
for _, tbl := range current {
53+
if db.HasTable(tbl) {
54+
err := db.All(&[]struct{}{}, dal.From(tbl), dal.Where("_raw_data_table = '' AND 1 = 0"))
55+
if err != nil {
56+
if dropErr := db.DropTables(tbl); dropErr != nil {
57+
return dropErr
58+
}
59+
}
60+
}
61+
}
62+
63+
return nil
64+
}
65+
66+
func (*fixRawTableNamesAndSchemas) Version() uint64 { return 20250905000001 }
67+
func (*fixRawTableNamesAndSchemas) Name() string { return "Fix raw table names and schemas" }
68+
69+
var _ plugin.MigrationScript = (*fixRawTableNamesAndSchemas)(nil)

backend/plugins/testmo/models/migrationscripts/archived/run.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package archived
1919

2020
import (
2121
"time"
22+
23+
corearchived "github.com/apache/incubator-devlake/core/models/migrationscripts/archived"
2224
)
2325

2426
type TestmoRun struct {
@@ -40,9 +42,8 @@ type TestmoRun struct {
4042
TestmoCreatedAt *time.Time `json:"created_at"`
4143
TestmoUpdatedAt *time.Time `json:"updated_at"`
4244

43-
// Inline definition of NoPKModel
44-
CreatedAt time.Time `json:"createdAt"`
45-
UpdatedAt time.Time `json:"updatedAt"`
45+
// Include standard NoPKModel with RawDataOrigin columns
46+
corearchived.NoPKModel
4647
}
4748

4849
func (TestmoRun) TableName() string {

backend/plugins/testmo/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ func All() []plugin.MigrationScript {
2424
new(addInitTables),
2525
new(addScopeConfigIdToProjects),
2626
new(replaceTestsWithRuns),
27+
new(fixRawTableNamesAndSchemas),
2728
}
2829
}

0 commit comments

Comments
 (0)