From dd136858f1ea40ad3c94191d647487fa4f31926c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 18 Oct 2024 20:33:49 +0200 Subject: Adding upstream version 9.0.0. Signed-off-by: Daniel Baumann --- models/migrations/v1_18/main_test.go | 14 +++++++++++ models/migrations/v1_18/v224.go | 27 +++++++++++++++++++++ models/migrations/v1_18/v225.go | 28 +++++++++++++++++++++ models/migrations/v1_18/v226.go | 14 +++++++++++ models/migrations/v1_18/v227.go | 23 ++++++++++++++++++ models/migrations/v1_18/v228.go | 25 +++++++++++++++++++ models/migrations/v1_18/v229.go | 46 +++++++++++++++++++++++++++++++++++ models/migrations/v1_18/v229_test.go | 45 ++++++++++++++++++++++++++++++++++ models/migrations/v1_18/v230.go | 17 +++++++++++++ models/migrations/v1_18/v230_test.go | 47 ++++++++++++++++++++++++++++++++++++ 10 files changed, 286 insertions(+) create mode 100644 models/migrations/v1_18/main_test.go create mode 100644 models/migrations/v1_18/v224.go create mode 100644 models/migrations/v1_18/v225.go create mode 100644 models/migrations/v1_18/v226.go create mode 100644 models/migrations/v1_18/v227.go create mode 100644 models/migrations/v1_18/v228.go create mode 100644 models/migrations/v1_18/v229.go create mode 100644 models/migrations/v1_18/v229_test.go create mode 100644 models/migrations/v1_18/v230.go create mode 100644 models/migrations/v1_18/v230_test.go (limited to 'models/migrations/v1_18') diff --git a/models/migrations/v1_18/main_test.go b/models/migrations/v1_18/main_test.go new file mode 100644 index 0000000..329aa20 --- /dev/null +++ b/models/migrations/v1_18/main_test.go @@ -0,0 +1,14 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "testing" + + migration_tests "code.gitea.io/gitea/models/migrations/test" +) + +func TestMain(m *testing.M) { + migration_tests.MainTest(m) +} diff --git a/models/migrations/v1_18/v224.go b/models/migrations/v1_18/v224.go new file mode 100644 index 0000000..f3d522b --- /dev/null +++ b/models/migrations/v1_18/v224.go @@ -0,0 +1,27 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "xorm.io/xorm" +) + +func CreateUserBadgesTable(x *xorm.Engine) error { + type Badge struct { + ID int64 `xorm:"pk autoincr"` + Description string + ImageURL string + } + + type userBadge struct { + ID int64 `xorm:"pk autoincr"` + BadgeID int64 + UserID int64 `xorm:"INDEX"` + } + + if err := x.Sync(new(Badge)); err != nil { + return err + } + return x.Sync(new(userBadge)) +} diff --git a/models/migrations/v1_18/v225.go b/models/migrations/v1_18/v225.go new file mode 100644 index 0000000..b0ac377 --- /dev/null +++ b/models/migrations/v1_18/v225.go @@ -0,0 +1,28 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "code.gitea.io/gitea/modules/setting" + + "xorm.io/xorm" +) + +func AlterPublicGPGKeyContentFieldsToMediumText(x *xorm.Engine) error { + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + if setting.Database.Type.IsMySQL() { + if _, err := sess.Exec("ALTER TABLE `gpg_key` CHANGE `content` `content` MEDIUMTEXT"); err != nil { + return err + } + if _, err := sess.Exec("ALTER TABLE `public_key` CHANGE `content` `content` MEDIUMTEXT"); err != nil { + return err + } + } + return sess.Commit() +} diff --git a/models/migrations/v1_18/v226.go b/models/migrations/v1_18/v226.go new file mode 100644 index 0000000..f87e24b --- /dev/null +++ b/models/migrations/v1_18/v226.go @@ -0,0 +1,14 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "xorm.io/builder" + "xorm.io/xorm" +) + +func FixPackageSemverField(x *xorm.Engine) error { + _, err := x.Exec(builder.Update(builder.Eq{"semver_compatible": false}).From("`package`").Where(builder.In("`type`", "conan", "generic"))) + return err +} diff --git a/models/migrations/v1_18/v227.go b/models/migrations/v1_18/v227.go new file mode 100644 index 0000000..5fe5dcd --- /dev/null +++ b/models/migrations/v1_18/v227.go @@ -0,0 +1,23 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +type SystemSetting struct { + ID int64 `xorm:"pk autoincr"` + SettingKey string `xorm:"varchar(255) unique"` // ensure key is always lowercase + SettingValue string `xorm:"text"` + Version int `xorm:"version"` // prevent to override + Created timeutil.TimeStamp `xorm:"created"` + Updated timeutil.TimeStamp `xorm:"updated"` +} + +func CreateSystemSettingsTable(x *xorm.Engine) error { + return x.Sync(new(SystemSetting)) +} diff --git a/models/migrations/v1_18/v228.go b/models/migrations/v1_18/v228.go new file mode 100644 index 0000000..3e7a36d --- /dev/null +++ b/models/migrations/v1_18/v228.go @@ -0,0 +1,25 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +func AddTeamInviteTable(x *xorm.Engine) error { + type TeamInvite struct { + ID int64 `xorm:"pk autoincr"` + Token string `xorm:"UNIQUE(token) INDEX NOT NULL DEFAULT ''"` + InviterID int64 `xorm:"NOT NULL DEFAULT 0"` + OrgID int64 `xorm:"INDEX NOT NULL DEFAULT 0"` + TeamID int64 `xorm:"UNIQUE(team_mail) INDEX NOT NULL DEFAULT 0"` + Email string `xorm:"UNIQUE(team_mail) NOT NULL DEFAULT ''"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + } + + return x.Sync(new(TeamInvite)) +} diff --git a/models/migrations/v1_18/v229.go b/models/migrations/v1_18/v229.go new file mode 100644 index 0000000..10d9f35 --- /dev/null +++ b/models/migrations/v1_18/v229.go @@ -0,0 +1,46 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "fmt" + + "code.gitea.io/gitea/models/issues" + + "xorm.io/builder" + "xorm.io/xorm" +) + +func UpdateOpenMilestoneCounts(x *xorm.Engine) error { + var openMilestoneIDs []int64 + err := x.Table("milestone").Select("id").Where(builder.Neq{"is_closed": 1}).Find(&openMilestoneIDs) + if err != nil { + return fmt.Errorf("error selecting open milestone IDs: %w", err) + } + + for _, id := range openMilestoneIDs { + _, err := x.ID(id). + SetExpr("num_issues", builder.Select("count(*)").From("issue").Where( + builder.Eq{"milestone_id": id}, + )). + SetExpr("num_closed_issues", builder.Select("count(*)").From("issue").Where( + builder.Eq{ + "milestone_id": id, + "is_closed": true, + }, + )). + Update(&issues.Milestone{}) + if err != nil { + return fmt.Errorf("error updating issue counts in milestone %d: %w", id, err) + } + _, err = x.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?", + id, + ) + if err != nil { + return fmt.Errorf("error setting completeness on milestone %d: %w", id, err) + } + } + + return nil +} diff --git a/models/migrations/v1_18/v229_test.go b/models/migrations/v1_18/v229_test.go new file mode 100644 index 0000000..b20d0ff --- /dev/null +++ b/models/migrations/v1_18/v229_test.go @@ -0,0 +1,45 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "testing" + + "code.gitea.io/gitea/models/issues" + migration_tests "code.gitea.io/gitea/models/migrations/test" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func Test_UpdateOpenMilestoneCounts(t *testing.T) { + type ExpectedMilestone issues.Milestone + + // Prepare and load the testing database + x, deferable := migration_tests.PrepareTestEnv(t, 0, new(issues.Milestone), new(ExpectedMilestone), new(issues.Issue)) + defer deferable() + if x == nil || t.Failed() { + return + } + + if err := UpdateOpenMilestoneCounts(x); err != nil { + require.NoError(t, err) + return + } + + expected := []ExpectedMilestone{} + err := x.Table("expected_milestone").Asc("id").Find(&expected) + require.NoError(t, err) + + got := []issues.Milestone{} + err = x.Table("milestone").Asc("id").Find(&got) + require.NoError(t, err) + + for i, e := range expected { + got := got[i] + assert.Equal(t, e.ID, got.ID) + assert.Equal(t, e.NumIssues, got.NumIssues) + assert.Equal(t, e.NumClosedIssues, got.NumClosedIssues) + } +} diff --git a/models/migrations/v1_18/v230.go b/models/migrations/v1_18/v230.go new file mode 100644 index 0000000..ea5b4d0 --- /dev/null +++ b/models/migrations/v1_18/v230.go @@ -0,0 +1,17 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "xorm.io/xorm" +) + +// AddConfidentialColumnToOAuth2ApplicationTable: add ConfidentialClient column, setting existing rows to true +func AddConfidentialClientColumnToOAuth2ApplicationTable(x *xorm.Engine) error { + type oauth2Application struct { + ID int64 + ConfidentialClient bool `xorm:"NOT NULL DEFAULT TRUE"` + } + return x.Sync(new(oauth2Application)) +} diff --git a/models/migrations/v1_18/v230_test.go b/models/migrations/v1_18/v230_test.go new file mode 100644 index 0000000..82b3b8f --- /dev/null +++ b/models/migrations/v1_18/v230_test.go @@ -0,0 +1,47 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_18 //nolint + +import ( + "testing" + + migration_tests "code.gitea.io/gitea/models/migrations/test" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) { + // premigration + type oauth2Application struct { + ID int64 + } + + // Prepare and load the testing database + x, deferable := migration_tests.PrepareTestEnv(t, 0, new(oauth2Application)) + defer deferable() + if x == nil || t.Failed() { + return + } + + if err := AddConfidentialClientColumnToOAuth2ApplicationTable(x); err != nil { + require.NoError(t, err) + return + } + + // postmigration + type ExpectedOAuth2Application struct { + ID int64 + ConfidentialClient bool + } + + got := []ExpectedOAuth2Application{} + err := x.Table("oauth2_application").Select("id, confidential_client").Find(&got) + require.NoError(t, err) + + assert.NotEmpty(t, got) + for _, e := range got { + assert.True(t, e.ConfidentialClient) + } +} -- cgit v1.2.3