mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 22:13:26 +09:00
chore: rename migration package for next release to v28 (#38844)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modelmigration/migrationtest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
migrationtest.MainTest(m)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddMaxParallelToActionRunJob(_ context.Context, x base.EngineMigration) error {
|
||||
type ActionRunJob struct {
|
||||
MaxParallel int `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
|
||||
_, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreConstrains: true,
|
||||
IgnoreDropIndices: true,
|
||||
}, new(ActionRunJob))
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modelmigration/migrationtest"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddMaxParallelToActionRunJob(t *testing.T) {
|
||||
type ActionRunJob struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
Name string `xorm:"VARCHAR(255)"`
|
||||
}
|
||||
|
||||
x, deferable := migrationtest.PrepareTestEnv(t, 0, new(ActionRunJob))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := x.Insert(&ActionRunJob{Name: "job-a"})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, AddMaxParallelToActionRunJob(t.Context(), x))
|
||||
|
||||
// pre-existing rows must default to unlimited
|
||||
var maxParallel int
|
||||
has, err := x.SQL("SELECT max_parallel FROM action_run_job WHERE id = ?", 1).Get(&maxParallel)
|
||||
require.NoError(t, err)
|
||||
require.True(t, has)
|
||||
require.Equal(t, 0, maxParallel)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// AddDeferredMatrixColumnsToActionRunJob adds the columns backing deferred (dynamic) matrix expansion
|
||||
func AddDeferredMatrixColumnsToActionRunJob(_ context.Context, x base.EngineMigration) error {
|
||||
type ActionRunJob struct {
|
||||
// IsMatrixDeferred marks jobs whose matrix depends on other jobs' outputs and is therefore expanded only once those jobs finish;
|
||||
IsMatrixDeferred bool `xorm:"NOT NULL DEFAULT FALSE"`
|
||||
// DeferredMatrixPayload preserves the raw, unevaluated payload across expansion so a rerun can re-derive the matrix
|
||||
DeferredMatrixPayload []byte `xorm:"LONGBLOB"`
|
||||
}
|
||||
_, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreDropIndices: true,
|
||||
IgnoreConstrains: true,
|
||||
}, new(ActionRunJob))
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// AddBlockOnCodeownerReviews adds block on codeowner reviews branch protection
|
||||
func AddBlockOnCodeownerReviews(_ context.Context, x base.EngineMigration) error {
|
||||
type ProtectedBranch struct {
|
||||
BlockOnCodeownerReviews bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
_, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreConstrains: true,
|
||||
IgnoreDropIndices: true,
|
||||
}, new(ProtectedBranch))
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
func AddLicensePathToRepoLicense(ctx context.Context, x base.EngineMigration) error {
|
||||
// Drop the old 2-column UNIQUE(s) index on (repo_id, license) and, on
|
||||
// re-runs, the index created under the new name.
|
||||
// xorm Sync cannot reliably update an index when its column set changes.
|
||||
indexes, err := x.Dialect().GetIndexes(x.DB(), ctx, "repo_license")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, idx := range indexes {
|
||||
if idx.Name == "s" || idx.Name == "path" {
|
||||
if _, err := x.Exec(x.Dialect().DropIndexSQL("repo_license", idx)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add license_path column. The DEFAULT backfills existing rows: all repos
|
||||
// created before this migration used the single LICENSE file convention.
|
||||
type RepoLicense struct {
|
||||
LicensePath string `xorm:"VARCHAR(255) NOT NULL DEFAULT 'LICENSE'"`
|
||||
}
|
||||
if _, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreDropIndices: true,
|
||||
IgnoreConstrains: true,
|
||||
}, new(RepoLicense)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create new 3-column UNIQUE(path) index on (repo_id, license, license_path);
|
||||
// xorm prefixes the name to UQE_repo_license_path.
|
||||
newIndex := schemas.NewIndex("path", schemas.UniqueType)
|
||||
newIndex.AddColumn("repo_id", "license", "license_path")
|
||||
if _, err := x.Exec(x.Dialect().CreateIndexSQL("repo_license", newIndex)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modelmigration/migrationtest"
|
||||
"gitea.dev/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// repoLicenseBeforeV345 mirrors the pre-migration repo_license table: no
|
||||
// license_path column and a 2-column UNIQUE(s) index on (repo_id, license).
|
||||
type repoLicenseBeforeV345 struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"UNIQUE(s) NOT NULL"`
|
||||
CommitID string
|
||||
License string `xorm:"VARCHAR(255) UNIQUE(s) NOT NULL"`
|
||||
CreatedUnix timeutil.TimeStamp `xorm:"created"`
|
||||
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
|
||||
}
|
||||
|
||||
func (repoLicenseBeforeV345) TableName() string { return "repo_license" }
|
||||
|
||||
func Test_AddLicensePathToRepoLicense(t *testing.T) {
|
||||
x, deferable := migrationtest.PrepareTestEnv(t, 0, new(repoLicenseBeforeV345))
|
||||
defer deferable()
|
||||
|
||||
_, err := x.Insert(&repoLicenseBeforeV345{RepoID: 1, CommitID: "c1", License: "MIT"})
|
||||
require.NoError(t, err)
|
||||
_, err = x.Insert(&repoLicenseBeforeV345{RepoID: 1, CommitID: "c1", License: "Apache-2.0"})
|
||||
require.NoError(t, err)
|
||||
_, err = x.Insert(&repoLicenseBeforeV345{RepoID: 2, CommitID: "c2", License: "MIT"})
|
||||
require.NoError(t, err)
|
||||
|
||||
indexes, err := x.Dialect().GetIndexes(x.DB(), context.Background(), "repo_license")
|
||||
require.NoError(t, err)
|
||||
oldIdx, ok := indexes["s"] // GetIndexes strips the UQE_repo_license_ prefix
|
||||
require.True(t, ok, "old 2-column unique s index should exist before migration")
|
||||
assert.Equal(t, schemas.UniqueType, oldIdx.Type)
|
||||
assert.Equal(t, []string{"repo_id", "license"}, oldIdx.Cols)
|
||||
|
||||
require.NoError(t, AddLicensePathToRepoLicense(t.Context(), x))
|
||||
require.NoError(t, AddLicensePathToRepoLicense(t.Context(), x)) // idempotent
|
||||
|
||||
indexes, err = x.Dialect().GetIndexes(x.DB(), context.Background(), "repo_license")
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, indexes, "s", "old 2-column unique s index should be gone after migration")
|
||||
newIdx, ok := indexes["path"] // GetIndexes strips the UQE_repo_license_ prefix
|
||||
require.True(t, ok, "new index must be named path (UQE_repo_license_path)")
|
||||
assert.Equal(t, schemas.UniqueType, newIdx.Type)
|
||||
assert.Equal(t, []string{"repo_id", "license", "license_path"}, newIdx.Cols)
|
||||
|
||||
// pre-existing rows must default to the LICENSE path
|
||||
type licenseRow struct {
|
||||
RepoID int64
|
||||
License string
|
||||
LicensePath string
|
||||
}
|
||||
var rows []licenseRow
|
||||
require.NoError(t, x.SQL("SELECT repo_id, license, license_path FROM repo_license ORDER BY id").Find(&rows))
|
||||
require.Len(t, rows, 3)
|
||||
for _, r := range rows {
|
||||
assert.Equal(t, "LICENSE", r.LicensePath)
|
||||
}
|
||||
|
||||
// the new index is unique per (repo_id, license, license_path): the exact
|
||||
// duplicate must be rejected, while a second path for the same license
|
||||
// in the same repo is allowed
|
||||
_, err = x.Exec("INSERT INTO repo_license (repo_id, commit_id, license, license_path) VALUES (1, 'c1', 'MIT', 'LICENSE')")
|
||||
require.Error(t, err)
|
||||
_, err = x.Exec("INSERT INTO repo_license (repo_id, commit_id, license, license_path) VALUES (1, 'c1', 'MIT', 'LICENSES/MIT.txt')")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddWatchOptions(_ context.Context, x base.EngineMigration) error {
|
||||
type Watch struct {
|
||||
PullRequests bool `xorm:"NOT NULL DEFAULT true"`
|
||||
Issues bool `xorm:"NOT NULL DEFAULT true"`
|
||||
Releases bool `xorm:"NOT NULL DEFAULT true"`
|
||||
}
|
||||
_, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreConstrains: true,
|
||||
IgnoreIndices: true,
|
||||
}, new(Watch))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user