From e2c6623244b14abb9903b0fba0bb570123bcfcf0 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: Sun, 17 Aug 2025 21:57:33 -0400 Subject: [PATCH] add group ID column to repository table's unique constraint --- models/migrations/v1_26/v324.go | 29 ++++++++++------------------- models/repo/repo.go | 2 +- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/models/migrations/v1_26/v324.go b/models/migrations/v1_26/v324.go index 5d96bfa3ca..b70de1901b 100644 --- a/models/migrations/v1_26/v324.go +++ b/models/migrations/v1_26/v324.go @@ -1,24 +1,15 @@ -// Copyright 2025 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - package v1_26 -import ( - "fmt" +import "xorm.io/xorm" - "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) +func AddGroupColumnsToRepositoryTable(x *xorm.Engine) error { + type Repository struct { + GroupID int64 `xorm:"UNIQUE(s) INDEX DEFAULT NULL"` + GroupSortOrder int } - - return nil + _, err := x.SyncWithOptions(xorm.SyncOptions{ + IgnoreConstrains: false, + IgnoreIndices: false, + }, new(Repository)) + return err } diff --git a/models/repo/repo.go b/models/repo/repo.go index f0f819c711..7a7edb29fb 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -220,7 +220,7 @@ type Repository struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT 0"` - GroupID int64 `xorm:"INDEX DEFAULT NULL"` + GroupID int64 `xorm:"UNIQUE(s) INDEX DEFAULT NULL"` GroupSortOrder int `xorm:"INDEX"` }