-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add default board to new projects, remove uncategorized pseudo-board #29874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
efaa6ce
069687c
b82fdbd
5c49766
53aa0da
1569910
088b715
fc9846b
8660d84
98468df
7267f70
0093855
d326913
2d5c14d
d3a477a
d8781f5
2e25dd5
6f7cb7a
cbe3946
e6e5f3b
5cc2f6e
974a43e
7a5ab60
0b8fb69
a3b861d
42bd419
add886b
5541da4
8ea1715
289cc90
89c1851
f8b35c8
b12a30a
7556836
c0cf2fc
a6fcd20
5405384
4e83bdb
e2190f6
efea1c9
5f69ecc
3e330e8
aa06c97
a3b5aa0
3ad1aa1
a2baeff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
- | ||
id: 1 | ||
title: project without default column | ||
owner_id: 2 | ||
repo_id: 0 | ||
is_closed: false | ||
creator_id: 2 | ||
board_type: 1 | ||
type: 2 | ||
created_unix: 1688973000 | ||
updated_unix: 1688973000 | ||
|
||
- | ||
id: 2 | ||
title: project with multiple default columns | ||
owner_id: 2 | ||
repo_id: 0 | ||
is_closed: false | ||
creator_id: 2 | ||
board_type: 1 | ||
type: 2 | ||
created_unix: 1688973000 | ||
updated_unix: 1688973000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
- | ||
id: 1 | ||
project_id: 1 | ||
title: Done | ||
creator_id: 2 | ||
default: false | ||
created_unix: 1588117528 | ||
updated_unix: 1588117528 | ||
|
||
- | ||
id: 2 | ||
project_id: 2 | ||
title: Backlog | ||
creator_id: 2 | ||
default: true | ||
created_unix: 1588117528 | ||
updated_unix: 1588117528 | ||
|
||
- | ||
id: 3 | ||
project_id: 2 | ||
title: Uncategorized | ||
creator_id: 2 | ||
default: true | ||
created_unix: 1588117528 | ||
updated_unix: 1588117528 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_22 //nolint | ||
|
||
import ( | ||
"code.gitea.io/gitea/models/project" | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"xorm.io/builder" | ||
"xorm.io/xorm" | ||
) | ||
|
||
// CheckProjectColumnsConsistency ensures there is exactly one default board per project present | ||
func CheckProjectColumnsConsistency(x *xorm.Engine) error { | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
|
||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
limit := setting.Database.IterateBufferSize | ||
if limit <= 0 { | ||
limit = 50 | ||
} | ||
|
||
start := 0 | ||
|
||
for { | ||
var projects []project.Project | ||
if err := sess.SQL("SELECT DISTINCT `p`.`id`, `p`.`creator_id` FROM `project` `p` WHERE (SELECT COUNT(*) FROM `project_board` `pb` WHERE `pb`.`project_id` = `p`.`id` AND `pb`.`default` = ?) != 1", true). | ||
Limit(limit, start). | ||
Find(&projects); err != nil { | ||
return err | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry but this migration seems broken .... If the "SELECT" results are stable and never change, this BUT, by each For example: 150 projects.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will send a PR to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lunny I believe I still have an issue with this migration. It says: "Ensure every project has exactly one default column". It tries to do some SQL queriy on the I'm using Docker
When I currently dump the project & project_board schema, it looks like this (hope this helps): Project table: CREATE TABLE "public"."project" (
"id" bigint DEFAULT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"title" text NOT NULL,
"description" text,
"repo_id" bigint,
"creator_id" bigint NOT NULL,
"is_closed" boolean,
"board_type" bigint,
"type" bigint,
"created_unix" bigint,
"updated_unix" bigint,
"closed_date_unix" bigint,
"card_type" integer DEFAULT '0' NOT NULL,
"owner_id" bigint,
CONSTRAINT "project_pkey" PRIMARY KEY ("id")
) WITH (oids = false); Project board table: CREATE TABLE "public"."project_board" (
"id" bigint DEFAULT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
"title" text,
"default" bigint DEFAULT '0' NOT NULL,
"project_id" bigint NOT NULL,
"creator_id" bigint NOT NULL,
"created_unix" bigint,
"updated_unix" bigint,
"sorting" integer DEFAULT '0' NOT NULL,
"color" character varying(7),
CONSTRAINT "project_board_pkey" PRIMARY KEY ("id")
) WITH (oids = false); |
||
|
||
if len(projects) == 0 { | ||
break | ||
} | ||
start += len(projects) | ||
|
||
for _, p := range projects { | ||
var boards []project.Board | ||
if err := sess.Where("project_id=? AND `default` = ?", p.ID, true).OrderBy("sorting").Find(&boards); err != nil { | ||
return err | ||
} | ||
|
||
if len(boards) == 0 { | ||
if _, err := sess.Insert(project.Board{ | ||
ProjectID: p.ID, | ||
Default: true, | ||
Title: "Uncategorized", | ||
CreatorID: p.CreatorID, | ||
}); err != nil { | ||
return err | ||
} | ||
continue | ||
} | ||
|
||
var boardsToUpdate []int64 | ||
for id, b := range boards { | ||
if id > 0 { | ||
boardsToUpdate = append(boardsToUpdate, b.ID) | ||
} | ||
} | ||
|
||
if _, err := sess.Where(builder.Eq{"project_id": p.ID}.And(builder.In("id", boardsToUpdate))). | ||
Cols("`default`").Update(&project.Board{Default: false}); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if start%1000 == 0 { | ||
if err := sess.Commit(); err != nil { | ||
denyskon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return sess.Commit() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_22 //nolint | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/models/migrations/base" | ||
"code.gitea.io/gitea/models/project" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_CheckProjectColumnsConsistency(t *testing.T) { | ||
// Prepare and load the testing database | ||
x, deferable := base.PrepareTestEnv(t, 0, new(project.Project), new(project.Board)) | ||
defer deferable() | ||
if x == nil || t.Failed() { | ||
return | ||
} | ||
|
||
assert.NoError(t, CheckProjectColumnsConsistency(x)) | ||
|
||
// check if default board was added | ||
var defaultBoard project.Board | ||
has, err := x.Where("project_id=? AND `default` = ?", 1, true).Get(&defaultBoard) | ||
assert.NoError(t, err) | ||
assert.True(t, has) | ||
assert.Equal(t, int64(1), defaultBoard.ProjectID) | ||
assert.True(t, defaultBoard.Default) | ||
|
||
// check if multiple defaults were removed | ||
expectDefaultBoard, err := project.GetBoard(db.DefaultContext, 2) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(2), expectDefaultBoard.ProjectID) | ||
assert.True(t, expectDefaultBoard.Default) | ||
|
||
expectNonDefaultBoard, err := project.GetBoard(db.DefaultContext, 3) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(2), expectNonDefaultBoard.ProjectID) | ||
assert.False(t, expectNonDefaultBoard.Default) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.