diff --git a/models/migrations/v1_26/v324.go b/models/migrations/v1_26/v324.go index 5c67ed5998..5d96bfa3ca 100644 --- a/models/migrations/v1_26/v324.go +++ b/models/migrations/v1_26/v324.go @@ -3,18 +3,22 @@ package v1_26 -import "xorm.io/xorm" +import ( + "fmt" -func AddGroupColumnsToRepositoryTable(x *xorm.Engine) error { - type Repository struct { - LowerName string `xorm:"UNIQUE(s) UNIQUE(g) INDEX NOT NULL"` - GroupID int64 `xorm:"UNIQUE(g) INDEX DEFAULT 0"` - OwnerID int64 `xorm:"UNIQUE(s) UNIQUE(g) index"` - GroupSortOrder int + "xorm.io/xorm" +) + +func FixClosedMilestoneCompleteness(x *xorm.Engine) error { + // Update all milestones to recalculate completeness with the new logic: + // - Closed milestones with 0 issues should show 100% + // - All other milestones should calculate based on closed/total ratio + _, err := x.Exec("UPDATE `milestone` SET completeness=(CASE WHEN is_closed = ? AND num_issues = 0 THEN 100 ELSE 100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) END)", + true, + ) + if err != nil { + return fmt.Errorf("error updating milestone completeness: %w", err) } - _, err := x.SyncWithOptions(xorm.SyncOptions{ - IgnoreConstrains: false, - IgnoreIndices: false, - }, new(Repository)) - return err + + return nil } diff --git a/models/migrations/v1_26/v331.go b/models/migrations/v1_26/v331.go new file mode 100644 index 0000000000..25b5b14c6a --- /dev/null +++ b/models/migrations/v1_26/v331.go @@ -0,0 +1,20 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_26 + +import "xorm.io/xorm" + +func AddGroupColumnsToRepositoryTable(x *xorm.Engine) error { + type Repository struct { + LowerName string `xorm:"UNIQUE(s) UNIQUE(g) INDEX NOT NULL"` + GroupID int64 `xorm:"UNIQUE(s) INDEX DEFAULT 0"` + OwnerID int64 `xorm:"UNIQUE(s) UNIQUE(g) index"` + GroupSortOrder int + } + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: false, + IgnoreIndices: false, + }, new(Repository)) + return err +}