move migrations to aprop place

This commit is contained in:
Michael Jerger 2025-04-02 17:56:48 +02:00
parent 995aef372f
commit aa0c7fab21
5 changed files with 23 additions and 10 deletions

View file

@ -18,8 +18,8 @@ type FederationHost struct {
ID int64 `xorm:"pk autoincr"`
HostFqdn string `xorm:"host_fqdn UNIQUE INDEX VARCHAR(255) NOT NULL"`
NodeInfo NodeInfo `xorm:"extends NOT NULL"`
HostPort string `xorm:"NOT NULL"`
HostSchema string `xorm:"NOT NULL"`
HostPort string `xorm:"NOT NULL DEFAULT '443'"`
HostSchema string `xorm:"NOT NULL DEFAULT 'https'"`
LatestActivity time.Time `xorm:"NOT NULL"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`

View file

@ -94,6 +94,8 @@ var migrations = []*Migration{
NewMigration("Add `created_unix` column to `user_redirect` table", AddCreatedUnixToRedirect),
// v27 -> v28
NewMigration("Add pronoun privacy settings to user", AddHidePronounsOptionToUser),
// v28 -> v29
NewMigration("Migrate `User.NormalizedFederatedURI` column to extract port & schema into FederatedHost", MigrateNormalizedFederatedURI),
}
// GetCurrentDBVersion returns the current Forgejo database version.

View file

@ -1,10 +1,13 @@
// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package v1_23 //nolint
package forgejo_migrations //nolint:revive
import (
"code.gitea.io/gitea/models/migrations/base"
"time"
"forgejo.org/models/migrations/base"
"forgejo.org/modules/timeutil"
"xorm.io/xorm"
)
@ -20,8 +23,18 @@ func MigrateNormalizedFederatedURI(x *xorm.Engine) error {
type User struct {
NormalizedFederatedURI string
}
type FederationHost struct {
ID int64 `xorm:"pk autoincr"`
HostFqdn string `xorm:"host_fqdn UNIQUE INDEX VARCHAR(255) NOT NULL"`
NodeInfo NodeInfo `xorm:"extends NOT NULL"`
HostPort string `xorm:"NOT NULL DEFAULT '443'"`
HostSchema string `xorm:"NOT NULL DEFAULT 'https'"`
LatestActivity time.Time `xorm:"NOT NULL"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`
}
// TODO: add new fields to FederationHost
if err := x.Sync(new(User), new(FederatedUser)); err != nil {
if err := x.Sync(new(User), new(FederatedUser), new(FederationHost)); err != nil {
return err
}

View file

@ -1,14 +1,14 @@
// Copyright 2025 The Forgejo Authors.
// SPDX-License-Identifier: GPL-3.0-or-later
package v1_23 //nolint
package forgejo_migrations //nolint:revive
import (
"testing"
"time"
migration_tests "code.gitea.io/gitea/models/migrations/test"
"code.gitea.io/gitea/modules/timeutil"
migration_tests "forgejo.org/models/migrations/test"
"forgejo.org/modules/timeutil"
"github.com/stretchr/testify/require"
"xorm.io/xorm/schemas"

View file

@ -367,8 +367,6 @@ func prepareMigrationTasks() []*migration {
// Migration to Forgejo v10
newMigration(303, "Gitea last drop", v1_23.GiteaLastDrop),
newMigration(304, "Migrate `secret` column to store keying material", forgejo_migrations.MigrateTwoFactorToKeying),
newMigration(305, "Migrate `User.NormalizedFederatedURI` column to extract port & schema into FederatedHost", v1_23.MigrateNormalizedFederatedURI),
}
return preparedMigrations
}