mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-06 19:26:47 +02:00
Some checks failed
/ release (push) Waiting to run
testing-integration / test-unit (push) Waiting to run
testing-integration / test-sqlite (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Integration tests for the release process / release-simulation (push) Has been cancelled
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8422 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_22
|
|
|
|
import (
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
// AddUniqueIndexForProjectIssue adds unique indexes for project issue table
|
|
func AddUniqueIndexForProjectIssue(x *xorm.Engine) error {
|
|
// remove possible duplicated records in table project_issue
|
|
type result struct {
|
|
IssueID int64
|
|
ProjectID int64
|
|
Cnt int
|
|
}
|
|
var results []result
|
|
if err := x.Select("issue_id, project_id, count(*) as cnt").
|
|
Table("project_issue").
|
|
GroupBy("issue_id, project_id").
|
|
Having("count(*) > 1").
|
|
Find(&results); err != nil {
|
|
return err
|
|
}
|
|
for _, r := range results {
|
|
var ids []int64
|
|
if err := x.SQL("SELECT id FROM project_issue WHERE issue_id = ? and project_id = ? limit ?", r.IssueID, r.ProjectID, r.Cnt-1).Find(&ids); err != nil {
|
|
return err
|
|
}
|
|
if _, err := x.Table("project_issue").In("id", ids).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
// add unique index for project_issue table
|
|
type ProjectIssue struct { //revive:disable-line:exported
|
|
ID int64 `xorm:"pk autoincr"`
|
|
IssueID int64 `xorm:"INDEX unique(s)"`
|
|
ProjectID int64 `xorm:"INDEX unique(s)"`
|
|
}
|
|
|
|
return x.Sync(new(ProjectIssue))
|
|
}
|