Skip to content

Commit a5e659d

Browse files
author
Kostas Petrakis
committed
fix(pipeline): fix priority
- The newly introduced priority field is set to NULL by default, which causes pre-existing pipelines to crash devlake when starting after a version upgrade.
1 parent 4b418b9 commit a5e659d

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
var _ plugin.MigrationScript = (*fixNullPriority)(nil)
28+
29+
type fixNullPriority struct{}
30+
31+
type blueprint20251022 struct {
32+
Priority int `json:"priority"`
33+
}
34+
35+
func (blueprint20251022) TableName() string {
36+
return "_devlake_blueprints"
37+
}
38+
39+
type pipeline20251022 struct {
40+
Priority int `json:"priority"`
41+
}
42+
43+
func (pipeline20251022) TableName() string {
44+
return "_devlake_pipelines"
45+
}
46+
47+
func (*fixNullPriority) Up(basicRes context.BasicRes) errors.Error {
48+
// Set default value 0 for NULL priority values in existing rows
49+
db := basicRes.GetDal()
50+
err := db.UpdateColumn(&blueprint20251022{}, "priority", 0, dal.Where("priority IS NULL"))
51+
if err != nil {
52+
return err
53+
}
54+
err = db.UpdateColumn(&pipeline20251022{}, "priority", 0, dal.Where("priority IS NULL"))
55+
if err != nil {
56+
return err
57+
}
58+
return nil
59+
}
60+
61+
func (*fixNullPriority) Version() uint64 {
62+
return 20251022195645
63+
}
64+
65+
func (*fixNullPriority) Name() string {
66+
return "fix null priority values in blueprints and pipelines"
67+
}

backend/core/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,6 @@ func All() []plugin.MigrationScript {
140140
new(extendFieldSizeForCq),
141141
new(addIssueFixVerion),
142142
new(addPipelinePriority),
143+
new(fixNullPriority),
143144
}
144145
}

0 commit comments

Comments
 (0)