From a79c96748dd177b816d9e9224a9f9cd853401003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Sat, 20 Dec 2025 16:14:25 -0500 Subject: [PATCH] update migrations --- models/migrations/v1_26/v324.go | 28 ++++++++++++++++------------ models/migrations/v1_26/v331.go | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 models/migrations/v1_26/v331.go 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 +}