Skip to content

Commit 6d0f840

Browse files
committed
Add migration for milestone deadline_unix column
1 parent 4a266fb commit 6d0f840

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

models/issues/milestone.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
repo_model "code.gitea.io/gitea/models/repo"
14-
"code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/optional"
1615
api "code.gitea.io/gitea/modules/structs"
1716
"code.gitea.io/gitea/modules/timeutil"
1817
"code.gitea.io/gitea/modules/util"
1918

2019
"xorm.io/builder"
21-
"xorm.io/xorm"
2220
)
2321

2422
// ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
@@ -84,21 +82,11 @@ func (m *Milestone) BeforeUpdate() {
8482

8583
// AfterLoad is invoked from XORM after setting the value of a field of
8684
// this object.
87-
func (m *Milestone) AfterLoad(session *xorm.Session) {
85+
func (m *Milestone) AfterLoad() {
8886
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
8987
if m.DeadlineUnix == 0 {
9088
return
9189
}
92-
// for legacy reasons, all years after 9000 are considered as no deadline
93-
if m.DeadlineUnix.Year() > 9000 {
94-
m.DeadlineUnix = 0
95-
m.IsOverdue = false
96-
if _, err := session.ID(m.ID).NoAutoTime().Cols("deadline_unix", "is_overdue").Update(m); err != nil {
97-
log.Error("AfterLoad update legacy deadline failed: %v", err)
98-
}
99-
return
100-
}
101-
10290
m.DeadlineString = m.DeadlineUnix.FormatDate()
10391
if m.IsClosed {
10492
m.IsOverdue = m.ClosedDateUnix >= m.DeadlineUnix

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ func prepareMigrationTasks() []*migration {
364364
newMigration(304, "Add index for release sha1", v1_23.AddIndexForReleaseSha1),
365365
newMigration(305, "Add Repository Licenses", v1_23.AddRepositoryLicenses),
366366
newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection),
367+
newMigration(307, "Fix milestone deadline_unix when there is no due date", v1_23.FixMilestoneNoDueDate),
367368
}
368369
return preparedMigrations
369370
}

models/migrations/v1_23/v307.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixMilestoneNoDueDate(x *xorm.Engine) error {
13+
type Milestone struct {
14+
DeadlineUnix timeutil.TimeStamp
15+
}
16+
// Wednesday, December 1, 9999 12:00:00 AM GMT+00:00
17+
_, err := x.Table("milestone").Where("deadline_unix > 253399622400").
18+
Cols("deadline_unix").
19+
Update(&Milestone{DeadlineUnix: 0})
20+
return err
21+
}

0 commit comments

Comments
 (0)