refactor: prepare to decouple the "model migration" package and "models" package (#38533)
Migrations should never use model structs directly, because the model structs can be different in different releases. e.g. if one migration uses "User" model, it works in the early releases, then one day, when the User model changes, the migration breaks because it will use the new (incorrect) User model, it should only use the old User model. The same to "modules/structs". --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
@@ -11,7 +11,7 @@ include_file = ["main.go"]
|
|||||||
include_dir = ["cmd", "models", "modules", "options", "routers", "services"]
|
include_dir = ["cmd", "models", "modules", "options", "routers", "services"]
|
||||||
exclude_dir = [
|
exclude_dir = [
|
||||||
"models/fixtures",
|
"models/fixtures",
|
||||||
"models/migrations/fixtures",
|
"modelmigration/fixtures",
|
||||||
"modules/avatar/identicon/testdata",
|
"modules/avatar/identicon/testdata",
|
||||||
"modules/avatar/testdata",
|
"modules/avatar/testdata",
|
||||||
"modules/git/tests",
|
"modules/git/tests",
|
||||||
|
|||||||
+3
-4
@@ -53,9 +53,9 @@ linters:
|
|||||||
desc: use builtin errors package instead
|
desc: use builtin errors package instead
|
||||||
migrations:
|
migrations:
|
||||||
files:
|
files:
|
||||||
- '**/models/migrations/**/*.go'
|
- '**/modelmigration/**/*.go'
|
||||||
deny:
|
deny:
|
||||||
- pkg: gitea.dev/models$
|
- pkg: gitea.dev/models$ # FIXME: it should deny all sub packages like "gitea.dev/models/repo"
|
||||||
desc: migrations must not depend on the models package
|
desc: migrations must not depend on the models package
|
||||||
- pkg: gitea.dev/modules/structs
|
- pkg: gitea.dev/modules/structs
|
||||||
desc: migrations must not depend on modules/structs (API structures change over time)
|
desc: migrations must not depend on modules/structs (API structures change over time)
|
||||||
@@ -134,8 +134,7 @@ linters:
|
|||||||
path: _test\.go
|
path: _test\.go
|
||||||
- linters:
|
- linters:
|
||||||
- dupl
|
- dupl
|
||||||
- errcheck
|
path: modelmigration/v
|
||||||
path: models/migrations/v
|
|
||||||
- linters:
|
- linters:
|
||||||
- forbidigo
|
- forbidigo
|
||||||
path: cmd
|
path: cmd
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ LDFLAGS := $(LDFLAGS) -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
|
|||||||
|
|
||||||
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/riscv64
|
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/riscv64
|
||||||
|
|
||||||
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list gitea.dev/models/migrations/...) gitea.dev/tests/integration/migration-test gitea.dev/tests gitea.dev/tests/integration,$(shell $(GO) list ./... | grep -v /vendor/))
|
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list gitea.dev/modelmigration/...) gitea.dev/tests/integration/migration-test gitea.dev/tests gitea.dev/tests/integration,$(shell $(GO) list ./... | grep -v /vendor/))
|
||||||
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list gitea.dev/models/migrations/...)
|
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list gitea.dev/modelmigration/...)
|
||||||
|
|
||||||
FRONTEND_SOURCES := $(shell find web_src/js web_src/css -type f)
|
FRONTEND_SOURCES := $(shell find web_src/js web_src/css -type f)
|
||||||
FRONTEND_CONFIGS := vite.config.ts tailwind.config.ts
|
FRONTEND_CONFIGS := vite.config.ts tailwind.config.ts
|
||||||
@@ -477,7 +477,7 @@ migrations.individual.test:
|
|||||||
|
|
||||||
.PHONY: migrations.individual.test\#%
|
.PHONY: migrations.individual.test\#%
|
||||||
migrations.individual.test\#%:
|
migrations.individual.test\#%:
|
||||||
$(GO) test $(GOTEST_FLAGS) -tags '$(TAGS)' gitea.dev/models/migrations/$*
|
$(GO) test $(GOTEST_FLAGS) -tags '$(TAGS)' gitea.dev/modelmigration/$*
|
||||||
|
|
||||||
.PHONY: playwright
|
.PHONY: playwright
|
||||||
playwright: deps-frontend
|
playwright: deps-frontend
|
||||||
|
|||||||
+4
-4
@@ -12,9 +12,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"gitea.dev/modelmigration"
|
||||||
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/models/db"
|
||||||
"gitea.dev/models/migrations"
|
|
||||||
migrate_base "gitea.dev/models/migrations/base"
|
|
||||||
"gitea.dev/modules/container"
|
"gitea.dev/modules/container"
|
||||||
"gitea.dev/modules/log"
|
"gitea.dev/modules/log"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
@@ -129,10 +129,10 @@ func runRecreateTable(ctx context.Context, cmd *cli.Command) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
recreateTables := migrate_base.RecreateTables(beans...)
|
recreateTables := base.RecreateTables(beans...)
|
||||||
|
|
||||||
return db.InitEngineWithMigration(context.Background(), func(ctx context.Context, x db.EngineMigration) error {
|
return db.InitEngineWithMigration(context.Background(), func(ctx context.Context, x db.EngineMigration) error {
|
||||||
if err := migrations.EnsureUpToDate(ctx, x); err != nil {
|
if err := modelmigration.EnsureUpToDate(ctx, x); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return recreateTables(x)
|
return recreateTables(x)
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ For packagers who need to use paths like `/etc/gitea/app.ini`,
|
|||||||
they should define these values at build time for `make build` by environment variable like
|
they should define these values at build time for `make build` by environment variable like
|
||||||
`LDFLAGS='-X "module.Var1=Value1" -X "module.Var2=Value2"' TAGS="bindata" make build`.
|
`LDFLAGS='-X "module.Var1=Value1" -X "module.Var2=Value2"' TAGS="bindata" make build`.
|
||||||
|
|
||||||
- _`CustomConf`_: `-X "code.gitea.io/gitea/modules/setting.CustomConf=/etc/gitea/app.ini"`
|
- _`CustomConf`_: `-X "gitea.dev/modules/setting.CustomConf=/etc/gitea/app.ini"`
|
||||||
- _`AppWorkPath`_: `-X "code.gitea.io/gitea/modules/setting.AppWorkPath=/var/lib/gitea"`
|
- _`AppWorkPath`_: `-X "gitea.dev/modules/setting.AppWorkPath=/var/lib/gitea"`
|
||||||
- _`CustomPath`_: `-X "code.gitea.io/gitea/modules/setting.CustomPath=/var/lib/gitea/custom"`
|
- _`CustomPath`_: `-X "gitea.dev/modules/setting.CustomPath=/var/lib/gitea/custom"`
|
||||||
- Default PID file location: `-X "code.gitea.io/gitea/cmd.PIDFile=/run/gitea.pid"`
|
- Default PID file location: `-X "gitea.dev/cmd.PIDFile=/run/gitea.pid"`
|
||||||
|
|
||||||
Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
|
Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
|
||||||
with the appropriate `TAGS` as above.
|
with the appropriate `TAGS` as above.
|
||||||
|
|||||||
+1
-1
@@ -109,7 +109,7 @@ which lives in the [documentation repository](https://gitea.com/gitea/docs).
|
|||||||
## Database migrations
|
## Database migrations
|
||||||
|
|
||||||
If you make breaking changes to a database-persisted struct under `models/`, add a
|
If you make breaking changes to a database-persisted struct under `models/`, add a
|
||||||
new migration in `models/migrations/`. See [testing.md](testing.md#migration-tests)
|
new migration in `modelmigration/`. See [testing.md](testing.md#migration-tests)
|
||||||
for running the migration tests.
|
for running the migration tests.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ The backend is split into top-level packages, each with a focused responsibility
|
|||||||
dependencies to a minimum
|
dependencies to a minimum
|
||||||
- `models/db`: core database operations
|
- `models/db`: core database operations
|
||||||
- `models/fixtures`: sample data used by tests
|
- `models/fixtures`: sample data used by tests
|
||||||
- `models/migrations`: schema migration scripts
|
- `modelmigration`: schema migration scripts
|
||||||
- `modules`: standalone functionality with few dependencies
|
- `modules`: standalone functionality with few dependencies
|
||||||
- `modules/setting`: configuration handling
|
- `modules/setting`: configuration handling
|
||||||
- `modules/git`: interaction with the Git command line
|
- `modules/git`: interaction with the Git command line
|
||||||
|
|||||||
+1
-1
@@ -136,7 +136,7 @@ Useful environment variables:
|
|||||||
## Migration tests
|
## Migration tests
|
||||||
|
|
||||||
If you change a database-persisted struct under `models/` you will usually need a
|
If you change a database-persisted struct under `models/` you will usually need a
|
||||||
new migration in `models/migrations/`. Run the migration tests with:
|
new migration in `modelmigration`. Run the migration tests with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make test-migration
|
make test-migration
|
||||||
|
|||||||
@@ -18,10 +18,21 @@ import (
|
|||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Migrations should never use model structs directly, because the model structs can be different in different releases.
|
||||||
|
// e.g. if one migration uses "User" model, it works in the early releases, then one day,
|
||||||
|
// when the User model changes, the migration breaks because it will use the new (incorrect) User model,
|
||||||
|
// it should only use the old User model. The same to "modules/structs".
|
||||||
|
// However, many the existing migrations already abuses "modules/structs" (search "gitea.dev/models/" in the migrations).
|
||||||
|
// TODO: need to fully decouple the migration package and models & structs package
|
||||||
|
type (
|
||||||
|
EngineMigration = db.EngineMigration
|
||||||
|
Session = db.Session
|
||||||
|
)
|
||||||
|
|
||||||
// RecreateTables will recreate the tables for the provided beans using the newly provided bean definition and move all data to that new table
|
// RecreateTables will recreate the tables for the provided beans using the newly provided bean definition and move all data to that new table
|
||||||
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
|
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
|
||||||
func RecreateTables(beans ...any) func(db.EngineMigration) error {
|
func RecreateTables(beans ...any) func(EngineMigration) error {
|
||||||
return func(x db.EngineMigration) error {
|
return func(x EngineMigration) error {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
if err := sess.Begin(); err != nil {
|
if err := sess.Begin(); err != nil {
|
||||||
@@ -41,7 +52,7 @@ func RecreateTables(beans ...any) func(db.EngineMigration) error {
|
|||||||
// RecreateTable will recreate the table using the newly provided bean definition and move all data to that new table
|
// RecreateTable will recreate the table using the newly provided bean definition and move all data to that new table
|
||||||
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
|
// WARNING: YOU MUST PROVIDE THE FULL BEAN DEFINITION
|
||||||
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
|
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
|
||||||
func RecreateTable(sess db.Session, bean any) error {
|
func RecreateTable(sess Session, bean any) error {
|
||||||
// TODO: This will not work if there are foreign keys
|
// TODO: This will not work if there are foreign keys
|
||||||
|
|
||||||
tableName := sess.Engine().TableName(bean)
|
tableName := sess.Engine().TableName(bean)
|
||||||
@@ -304,7 +315,7 @@ func RecreateTable(sess db.Session, bean any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
|
// WARNING: YOU MUST COMMIT THE SESSION AT THE END
|
||||||
func DropTableColumns(sess db.Session, tableName string, columnNames ...string) (err error) {
|
func DropTableColumns(sess Session, tableName string, columnNames ...string) (err error) {
|
||||||
if tableName == "" || len(columnNames) == 0 {
|
if tableName == "" || len(columnNames) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -474,7 +485,7 @@ func DropTableColumns(sess db.Session, tableName string, columnNames ...string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ModifyColumn will modify column's type or other property. SQLITE is not supported
|
// ModifyColumn will modify column's type or other property. SQLITE is not supported
|
||||||
func ModifyColumn(x db.EngineMigration, tableName string, col *schemas.Column) error {
|
func ModifyColumn(x EngineMigration, tableName string, col *schemas.Column) error {
|
||||||
var indexes map[string]*schemas.Index
|
var indexes map[string]*schemas.Index
|
||||||
var err error
|
var err error
|
||||||
// MSSQL have to remove index at first, otherwise alter column will fail
|
// MSSQL have to remove index at first, otherwise alter column will fail
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package base
|
package base_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gitea.dev/models/migrations/migrationtest"
|
"gitea.dev/modelmigration/base"
|
||||||
|
"gitea.dev/modelmigration/migrationtest"
|
||||||
"gitea.dev/modules/timeutil"
|
"gitea.dev/modules/timeutil"
|
||||||
|
|
||||||
"xorm.io/xorm/names"
|
"xorm.io/xorm/names"
|
||||||
@@ -55,7 +56,7 @@ func Test_DropTableColumns(t *testing.T) {
|
|||||||
t.Errorf("unable to begin transaction: %v", err)
|
t.Errorf("unable to begin transaction: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := DropTableColumns(sess, "drop_test", columns[i:]...); err != nil {
|
if err := base.DropTableColumns(sess, "drop_test", columns[i:]...); err != nil {
|
||||||
sess.Close()
|
sess.Close()
|
||||||
t.Errorf("Unable to drop columns[%d:]: %s from drop_test: %v", i, columns[i:], err)
|
t.Errorf("Unable to drop columns[%d:]: %s from drop_test: %v", i, columns[i:], err)
|
||||||
return
|
return
|
||||||
@@ -82,7 +83,7 @@ func Test_DropTableColumns(t *testing.T) {
|
|||||||
t.Errorf("unable to begin transaction: %v", err)
|
t.Errorf("unable to begin transaction: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := DropTableColumns(sess, "drop_test", dropcols...); err != nil {
|
if err := base.DropTableColumns(sess, "drop_test", dropcols...); err != nil {
|
||||||
sess.Close()
|
sess.Close()
|
||||||
t.Errorf("Unable to drop columns: %s from drop_test: %v", dropcols, err)
|
t.Errorf("Unable to drop columns: %s from drop_test: %v", dropcols, err)
|
||||||
return
|
return
|
||||||
@@ -2,36 +2,36 @@
|
|||||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package migrations
|
package modelmigration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/models/migrations/v1_10"
|
"gitea.dev/modelmigration/v1_10"
|
||||||
"gitea.dev/models/migrations/v1_11"
|
"gitea.dev/modelmigration/v1_11"
|
||||||
"gitea.dev/models/migrations/v1_12"
|
"gitea.dev/modelmigration/v1_12"
|
||||||
"gitea.dev/models/migrations/v1_13"
|
"gitea.dev/modelmigration/v1_13"
|
||||||
"gitea.dev/models/migrations/v1_14"
|
"gitea.dev/modelmigration/v1_14"
|
||||||
"gitea.dev/models/migrations/v1_15"
|
"gitea.dev/modelmigration/v1_15"
|
||||||
"gitea.dev/models/migrations/v1_16"
|
"gitea.dev/modelmigration/v1_16"
|
||||||
"gitea.dev/models/migrations/v1_17"
|
"gitea.dev/modelmigration/v1_17"
|
||||||
"gitea.dev/models/migrations/v1_18"
|
"gitea.dev/modelmigration/v1_18"
|
||||||
"gitea.dev/models/migrations/v1_19"
|
"gitea.dev/modelmigration/v1_19"
|
||||||
"gitea.dev/models/migrations/v1_20"
|
"gitea.dev/modelmigration/v1_20"
|
||||||
"gitea.dev/models/migrations/v1_21"
|
"gitea.dev/modelmigration/v1_21"
|
||||||
"gitea.dev/models/migrations/v1_22"
|
"gitea.dev/modelmigration/v1_22"
|
||||||
"gitea.dev/models/migrations/v1_23"
|
"gitea.dev/modelmigration/v1_23"
|
||||||
"gitea.dev/models/migrations/v1_24"
|
"gitea.dev/modelmigration/v1_24"
|
||||||
"gitea.dev/models/migrations/v1_25"
|
"gitea.dev/modelmigration/v1_25"
|
||||||
"gitea.dev/models/migrations/v1_26"
|
"gitea.dev/modelmigration/v1_26"
|
||||||
"gitea.dev/models/migrations/v1_27"
|
"gitea.dev/modelmigration/v1_27"
|
||||||
"gitea.dev/models/migrations/v1_6"
|
"gitea.dev/modelmigration/v1_6"
|
||||||
"gitea.dev/models/migrations/v1_7"
|
"gitea.dev/modelmigration/v1_7"
|
||||||
"gitea.dev/models/migrations/v1_8"
|
"gitea.dev/modelmigration/v1_8"
|
||||||
"gitea.dev/models/migrations/v1_9"
|
"gitea.dev/modelmigration/v1_9"
|
||||||
"gitea.dev/modules/git"
|
"gitea.dev/modules/git"
|
||||||
"gitea.dev/modules/log"
|
"gitea.dev/modules/log"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
@@ -44,23 +44,23 @@ const minDBVersion = 70 // Gitea 1.5.3
|
|||||||
type migration struct {
|
type migration struct {
|
||||||
idNumber int64 // DB version is "the last migration's idNumber" + 1
|
idNumber int64 // DB version is "the last migration's idNumber" + 1
|
||||||
description string
|
description string
|
||||||
migrate func(context.Context, db.EngineMigration) error
|
migrate func(context.Context, base.EngineMigration) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMigration creates a new migration
|
// newMigration creates a new migration
|
||||||
func newMigration[T func(db.EngineMigration) error | func(context.Context, db.EngineMigration) error](idNumber int64, desc string, fn T) *migration {
|
func newMigration[T func(base.EngineMigration) error | func(context.Context, base.EngineMigration) error](idNumber int64, desc string, fn T) *migration {
|
||||||
m := &migration{idNumber: idNumber, description: desc}
|
m := &migration{idNumber: idNumber, description: desc}
|
||||||
var ok bool
|
var ok bool
|
||||||
if m.migrate, ok = any(fn).(func(context.Context, db.EngineMigration) error); !ok {
|
if m.migrate, ok = any(fn).(func(context.Context, base.EngineMigration) error); !ok {
|
||||||
m.migrate = func(ctx context.Context, x db.EngineMigration) error {
|
m.migrate = func(ctx context.Context, x base.EngineMigration) error {
|
||||||
return any(fn).(func(db.EngineMigration) error)(x)
|
return any(fn).(func(base.EngineMigration) error)(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate executes the migration
|
// Migrate executes the migration
|
||||||
func (m *migration) Migrate(ctx context.Context, x db.EngineMigration) error {
|
func (m *migration) Migrate(ctx context.Context, x base.EngineMigration) error {
|
||||||
return m.migrate(ctx, x)
|
return m.migrate(ctx, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ type Version struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use noopMigration when there is a migration that has been no-oped
|
// Use noopMigration when there is a migration that has been no-oped
|
||||||
var noopMigration = func(_ db.EngineMigration) error { return nil }
|
var noopMigration = func(_ base.EngineMigration) error { return nil }
|
||||||
|
|
||||||
var preparedMigrations []*migration
|
var preparedMigrations []*migration
|
||||||
|
|
||||||
@@ -420,12 +420,13 @@ func prepareMigrationTasks() []*migration {
|
|||||||
newMigration(340, "Add ContinueOnError column to ActionRunJob", v1_27.AddContinueOnErrorToActionRunJob),
|
newMigration(340, "Add ContinueOnError column to ActionRunJob", v1_27.AddContinueOnErrorToActionRunJob),
|
||||||
newMigration(341, "Convert legacy MSSQL DATETIME columns to DATETIME2", v1_27.FixLegacyMSSQLDateTimeColumns),
|
newMigration(341, "Convert legacy MSSQL DATETIME columns to DATETIME2", v1_27.FixLegacyMSSQLDateTimeColumns),
|
||||||
newMigration(342, "Add scoped workflows schema", v1_27.AddScopedWorkflowsSchema),
|
newMigration(342, "Add scoped workflows schema", v1_27.AddScopedWorkflowsSchema),
|
||||||
|
// Gitea 1.27.0 ends at migration ID number 342 (database version 343)
|
||||||
}
|
}
|
||||||
return preparedMigrations
|
return preparedMigrations
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentDBVersion returns the current db version
|
// GetCurrentDBVersion returns the current db version
|
||||||
func GetCurrentDBVersion(x db.EngineMigration) (int64, error) {
|
func GetCurrentDBVersion(x base.EngineMigration) (int64, error) {
|
||||||
if err := x.Sync(new(Version)); err != nil {
|
if err := x.Sync(new(Version)); err != nil {
|
||||||
return -1, fmt.Errorf("sync: %w", err)
|
return -1, fmt.Errorf("sync: %w", err)
|
||||||
}
|
}
|
||||||
@@ -458,7 +459,7 @@ func ExpectedDBVersion() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EnsureUpToDate will check if the db is at the correct version
|
// EnsureUpToDate will check if the db is at the correct version
|
||||||
func EnsureUpToDate(ctx context.Context, x db.EngineMigration) error {
|
func EnsureUpToDate(ctx context.Context, x base.EngineMigration) error {
|
||||||
currentDB, err := GetCurrentDBVersion(x)
|
currentDB, err := GetCurrentDBVersion(x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -490,7 +491,7 @@ func migrationIDNumberToDBVersion(idNumber int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Migrate database to current version
|
// Migrate database to current version
|
||||||
func Migrate(ctx context.Context, x db.EngineMigration) error {
|
func Migrate(ctx context.Context, x base.EngineMigration) error {
|
||||||
migrations := prepareMigrationTasks()
|
migrations := prepareMigrationTasks()
|
||||||
maxDBVer := calcDBVersion(migrations)
|
maxDBVer := calcDBVersion(migrations)
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
package migrations
|
package modelmigration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/models/db"
|
||||||
"gitea.dev/models/unittest"
|
"gitea.dev/models/unittest"
|
||||||
"gitea.dev/modules/git"
|
"gitea.dev/modules/git"
|
||||||
@@ -22,8 +23,8 @@ import (
|
|||||||
// PrepareTestEnv prepares the test environment and reset the database. The skip parameter should usually be 0.
|
// PrepareTestEnv prepares the test environment and reset the database. The skip parameter should usually be 0.
|
||||||
// Provide models to be sync'd with the database - in particular any models you expect fixtures to be loaded from.
|
// Provide models to be sync'd with the database - in particular any models you expect fixtures to be loaded from.
|
||||||
//
|
//
|
||||||
// fixtures in `models/migrations/fixtures/<TestName>` will be loaded automatically
|
// fixtures in `modelmigration/fixtures/<TestName>` will be loaded automatically
|
||||||
func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (db.EngineMigration, func()) {
|
func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (base.EngineMigration, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ourSkip := 2
|
ourSkip := 2
|
||||||
ourSkip += skip
|
ourSkip += skip
|
||||||
@@ -64,7 +65,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (db.EngineMigrati
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fixturesDir := filepath.Join(giteaRoot, "models", "migrations", "fixtures", t.Name())
|
fixturesDir := filepath.Join(giteaRoot, "modelmigration/fixtures", t.Name())
|
||||||
|
|
||||||
if _, err := os.Stat(fixturesDir); err == nil {
|
if _, err := os.Stat(fixturesDir); err == nil {
|
||||||
t.Logf("initializing fixtures from: %s", fixturesDir)
|
t.Logf("initializing fixtures from: %s", fixturesDir)
|
||||||
@@ -88,7 +89,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (db.EngineMigrati
|
|||||||
return x, deferFn
|
return x, deferFn
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadTableSchemasMap(t *testing.T, x db.EngineMigration) map[string]*schemas.Table {
|
func LoadTableSchemasMap(t *testing.T, x base.EngineMigration) map[string]*schemas.Table {
|
||||||
tables, err := x.DBMetas()
|
tables, err := x.DBMetas()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tableMap := make(map[string]*schemas.Table)
|
tableMap := make(map[string]*schemas.Table)
|
||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UpdateMigrationServiceTypes(x db.EngineMigration) error {
|
func UpdateMigrationServiceTypes(x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64
|
ID int64
|
||||||
OriginalServiceType int `xorm:"index default(0)"`
|
OriginalServiceType int `xorm:"index default(0)"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func ChangeSomeColumnsLengthOfExternalLoginUser(x db.EngineMigration) error {
|
func ChangeSomeColumnsLengthOfExternalLoginUser(x base.EngineMigration) error {
|
||||||
type ExternalLoginUser struct {
|
type ExternalLoginUser struct {
|
||||||
AccessToken string `xorm:"TEXT"`
|
AccessToken string `xorm:"TEXT"`
|
||||||
AccessTokenSecret string `xorm:"TEXT"`
|
AccessTokenSecret string `xorm:"TEXT"`
|
||||||
@@ -7,14 +7,14 @@ import (
|
|||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func hashContext(context string) string {
|
func hashContext(context string) string {
|
||||||
return fmt.Sprintf("%x", sha1.Sum([]byte(context)))
|
return fmt.Sprintf("%x", sha1.Sum([]byte(context)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddCommitStatusContext(x db.EngineMigration) error {
|
func AddCommitStatusContext(x base.EngineMigration) error {
|
||||||
type CommitStatus struct {
|
type CommitStatus struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
ContextHash string `xorm:"char(40) index"`
|
ContextHash string `xorm:"char(40) index"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddOriginalMigrationInfo(x db.EngineMigration) error {
|
func AddOriginalMigrationInfo(x base.EngineMigration) error {
|
||||||
// Issue see models/issue.go
|
// Issue see models/issue.go
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
OriginalAuthor string
|
OriginalAuthor string
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func ChangeSomeColumnsLengthOfRepo(x db.EngineMigration) error {
|
func ChangeSomeColumnsLengthOfRepo(x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
Description string `xorm:"TEXT"`
|
Description string `xorm:"TEXT"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddIndexOnRepositoryAndComment(x db.EngineMigration) error {
|
func AddIndexOnRepositoryAndComment(x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
OwnerID int64 `xorm:"index"`
|
OwnerID int64 `xorm:"index"`
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RemoveLingeringIndexStatus(x db.EngineMigration) error {
|
func RemoveLingeringIndexStatus(x base.EngineMigration) error {
|
||||||
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_indexer_status`"))
|
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_indexer_status`"))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddEmailNotificationEnabledToUser(x db.EngineMigration) error {
|
func AddEmailNotificationEnabledToUser(x base.EngineMigration) error {
|
||||||
// User see models/user.go
|
// User see models/user.go
|
||||||
type User struct {
|
type User struct {
|
||||||
EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
|
EmailNotificationsPreference string `xorm:"VARCHAR(20) NOT NULL DEFAULT 'enabled'"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddStatusCheckColumnsForProtectedBranches(x db.EngineMigration) error {
|
func AddStatusCheckColumnsForProtectedBranches(x base.EngineMigration) error {
|
||||||
type ProtectedBranch struct {
|
type ProtectedBranch struct {
|
||||||
EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"`
|
EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
StatusCheckContexts []string `xorm:"JSON TEXT"`
|
StatusCheckContexts []string `xorm:"JSON TEXT"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddCrossReferenceColumns(x db.EngineMigration) error {
|
func AddCrossReferenceColumns(x base.EngineMigration) error {
|
||||||
// Comment see models/comment.go
|
// Comment see models/comment.go
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
RefRepoID int64 `xorm:"index"`
|
RefRepoID int64 `xorm:"index"`
|
||||||
@@ -6,12 +6,12 @@ package v1_10
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteOrphanedAttachments(x db.EngineMigration) error {
|
func DeleteOrphanedAttachments(x base.EngineMigration) error {
|
||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
UUID string `xorm:"uuid UNIQUE"`
|
UUID string `xorm:"uuid UNIQUE"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddRepoAdminChangeTeamAccessColumnForUser(x db.EngineMigration) error {
|
func AddRepoAdminChangeTeamAccessColumnForUser(x base.EngineMigration) error {
|
||||||
type User struct {
|
type User struct {
|
||||||
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
|
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddOriginalAuthorOnMigratedReleases(x db.EngineMigration) error {
|
func AddOriginalAuthorOnMigratedReleases(x base.EngineMigration) error {
|
||||||
type Release struct {
|
type Release struct {
|
||||||
ID int64
|
ID int64
|
||||||
OriginalAuthor string
|
OriginalAuthor string
|
||||||
@@ -4,11 +4,11 @@
|
|||||||
package v1_10
|
package v1_10
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/timeutil"
|
"gitea.dev/modules/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddTaskTable(x db.EngineMigration) error {
|
func AddTaskTable(x base.EngineMigration) error {
|
||||||
// TaskType defines task type
|
// TaskType defines task type
|
||||||
type TaskType int
|
type TaskType int
|
||||||
|
|
||||||
@@ -4,11 +4,10 @@
|
|||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/models/migrations/base"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DropColumnHeadUserNameOnPullRequest(x db.EngineMigration) error {
|
func DropColumnHeadUserNameOnPullRequest(x base.EngineMigration) error {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
if err := sess.Begin(); err != nil {
|
if err := sess.Begin(); err != nil {
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddWhitelistDeployKeysToBranches(x db.EngineMigration) error {
|
func AddWhitelistDeployKeysToBranches(x base.EngineMigration) error {
|
||||||
type ProtectedBranch struct {
|
type ProtectedBranch struct {
|
||||||
ID int64
|
ID int64
|
||||||
WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
|
WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
@@ -4,11 +4,10 @@
|
|||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/models/migrations/base"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RemoveLabelUneededCols(x db.EngineMigration) error {
|
func RemoveLabelUneededCols(x base.EngineMigration) error {
|
||||||
// Make sure the columns exist before dropping them
|
// Make sure the columns exist before dropping them
|
||||||
type Label struct {
|
type Label struct {
|
||||||
QueryString string
|
QueryString string
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddTeamIncludesAllRepositories(x db.EngineMigration) error {
|
func AddTeamIncludesAllRepositories(x base.EngineMigration) error {
|
||||||
type Team struct {
|
type Team struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"`
|
IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
// RepoWatchMode specifies what kind of watch the user has on a repository
|
// RepoWatchMode specifies what kind of watch the user has on a repository
|
||||||
type RepoWatchMode int8
|
type RepoWatchMode int8
|
||||||
@@ -14,7 +14,7 @@ type Watch struct {
|
|||||||
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
Mode RepoWatchMode `xorm:"SMALLINT NOT NULL DEFAULT 1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddModeColumnToWatch(x db.EngineMigration) error {
|
func AddModeColumnToWatch(x base.EngineMigration) error {
|
||||||
if err := x.Sync(new(Watch)); err != nil {
|
if err := x.Sync(new(Watch)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddTemplateToRepo(x db.EngineMigration) error {
|
func AddTemplateToRepo(x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
|
||||||
TemplateID int64 `xorm:"INDEX"`
|
TemplateID int64 `xorm:"INDEX"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddCommentIDOnNotification(x db.EngineMigration) error {
|
func AddCommentIDOnNotification(x base.EngineMigration) error {
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
CommentID int64
|
CommentID int64
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddCanCreateOrgRepoColumnForTeam(x db.EngineMigration) error {
|
func AddCanCreateOrgRepoColumnForTeam(x base.EngineMigration) error {
|
||||||
type Team struct {
|
type Team struct {
|
||||||
CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`
|
CanCreateOrgRepo bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
"xorm.io/xorm/schemas"
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ChangeReviewContentToText(x db.EngineMigration) error {
|
func ChangeReviewContentToText(x base.EngineMigration) error {
|
||||||
switch x.Dialect().URI().DBType {
|
switch x.Dialect().URI().DBType {
|
||||||
case schemas.MYSQL:
|
case schemas.MYSQL:
|
||||||
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
|
_, err := x.Exec("ALTER TABLE review MODIFY COLUMN content TEXT")
|
||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddBranchProtectionCanPushAndEnableWhitelist(x db.EngineMigration) error {
|
func AddBranchProtectionCanPushAndEnableWhitelist(x base.EngineMigration) error {
|
||||||
type ProtectedBranch struct {
|
type ProtectedBranch struct {
|
||||||
CanPush bool `xorm:"NOT NULL DEFAULT false"`
|
CanPush bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
EnableApprovalsWhitelist bool `xorm:"NOT NULL DEFAULT false"`
|
EnableApprovalsWhitelist bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
@@ -132,7 +132,7 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x db.EngineMigration) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getUserRepoPermission static function based on issues_model.IsOfficialReviewer at 5d78792385
|
// getUserRepoPermission static function based on issues_model.IsOfficialReviewer at 5d78792385
|
||||||
getUserRepoPermission := func(sess db.Session, repo *Repository, user *User) (Permission, error) {
|
getUserRepoPermission := func(sess base.Session, repo *Repository, user *User) (Permission, error) {
|
||||||
var perm Permission
|
var perm Permission
|
||||||
|
|
||||||
repoOwner := new(User)
|
repoOwner := new(User)
|
||||||
@@ -305,7 +305,7 @@ func AddBranchProtectionCanPushAndEnableWhitelist(x db.EngineMigration) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// isOfficialReviewer static function based on 5d78792385
|
// isOfficialReviewer static function based on 5d78792385
|
||||||
isOfficialReviewer := func(sess db.Session, issueID int64, reviewer *User) (bool, error) {
|
isOfficialReviewer := func(sess base.Session, issueID int64, reviewer *User) (bool, error) {
|
||||||
pr := new(PullRequest)
|
pr := new(PullRequest)
|
||||||
has, err := sess.ID(issueID).Get(pr)
|
has, err := sess.ID(issueID).Get(pr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -6,7 +6,7 @@ package v1_11
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/log"
|
"gitea.dev/modules/log"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RemoveAttachmentMissedRepo(x db.EngineMigration) error {
|
func RemoveAttachmentMissedRepo(x base.EngineMigration) error {
|
||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
UUID string `xorm:"uuid"`
|
UUID string `xorm:"uuid"`
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ package v1_11
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FeatureChangeTargetBranch(x db.EngineMigration) error {
|
func FeatureChangeTargetBranch(x base.EngineMigration) error {
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
OldRef string
|
OldRef string
|
||||||
NewRef string
|
NewRef string
|
||||||
@@ -6,10 +6,10 @@ package v1_11
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SanitizeOriginalURL(x db.EngineMigration) error {
|
func SanitizeOriginalURL(x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64
|
ID int64
|
||||||
OriginalURL string `xorm:"VARCHAR(2048)"`
|
OriginalURL string `xorm:"VARCHAR(2048)"`
|
||||||
@@ -12,14 +12,14 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/container"
|
"gitea.dev/modules/container"
|
||||||
"gitea.dev/modules/log"
|
"gitea.dev/modules/log"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
"gitea.dev/modules/util"
|
"gitea.dev/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenameExistingUserAvatarName(x db.EngineMigration) error {
|
func RenameExistingUserAvatarName(x base.EngineMigration) error {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
defer sess.Close()
|
defer sess.Close()
|
||||||
|
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_11
|
package v1_11
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func ExtendTrackedTimes(x db.EngineMigration) error {
|
func ExtendTrackedTimes(x base.EngineMigration) error {
|
||||||
type TrackedTime struct {
|
type TrackedTime struct {
|
||||||
Time int64 `xorm:"NOT NULL"`
|
Time int64 `xorm:"NOT NULL"`
|
||||||
Deleted bool `xorm:"NOT NULL DEFAULT false"`
|
Deleted bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddBlockOnRejectedReviews(x db.EngineMigration) error {
|
func AddBlockOnRejectedReviews(x base.EngineMigration) error {
|
||||||
type ProtectedBranch struct {
|
type ProtectedBranch struct {
|
||||||
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
|
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddReviewCommitAndStale(x db.EngineMigration) error {
|
func AddReviewCommitAndStale(x base.EngineMigration) error {
|
||||||
type Review struct {
|
type Review struct {
|
||||||
CommitID string `xorm:"VARCHAR(40)"`
|
CommitID string `xorm:"VARCHAR(40)"`
|
||||||
Stale bool `xorm:"NOT NULL DEFAULT false"`
|
Stale bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func FixMigratedRepositoryServiceType(x db.EngineMigration) error {
|
func FixMigratedRepositoryServiceType(x base.EngineMigration) error {
|
||||||
// structs.GithubService:
|
// structs.GithubService:
|
||||||
// GithubService = 2
|
// GithubService = 2
|
||||||
_, err := x.Exec("UPDATE repository SET original_service_type = ? WHERE original_url LIKE 'https://github.com/%'", 2)
|
_, err := x.Exec("UPDATE repository SET original_service_type = ? WHERE original_url LIKE 'https://github.com/%'", 2)
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddOwnerNameOnRepository(x db.EngineMigration) error {
|
func AddOwnerNameOnRepository(x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
OwnerName string
|
OwnerName string
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddIsRestricted(x db.EngineMigration) error {
|
func AddIsRestricted(x base.EngineMigration) error {
|
||||||
// User see models/user.go
|
// User see models/user.go
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddRequireSignedCommits(x db.EngineMigration) error {
|
func AddRequireSignedCommits(x base.EngineMigration) error {
|
||||||
type ProtectedBranch struct {
|
type ProtectedBranch struct {
|
||||||
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
|
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
}
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddReactionOriginals(x db.EngineMigration) error {
|
func AddReactionOriginals(x base.EngineMigration) error {
|
||||||
type Reaction struct {
|
type Reaction struct {
|
||||||
OriginalAuthorID int64 `xorm:"INDEX NOT NULL DEFAULT(0)"`
|
OriginalAuthorID int64 `xorm:"INDEX NOT NULL DEFAULT(0)"`
|
||||||
OriginalAuthor string
|
OriginalAuthor string
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func AddUserRepoMissingColumns(x db.EngineMigration) error {
|
func AddUserRepoMissingColumns(x base.EngineMigration) error {
|
||||||
type VisibleType int
|
type VisibleType int
|
||||||
type User struct {
|
type User struct {
|
||||||
PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'pbkdf2'"`
|
PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'pbkdf2'"`
|
||||||
@@ -6,10 +6,10 @@ package v1_12
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddReviewMigrateInfo(x db.EngineMigration) error {
|
func AddReviewMigrateInfo(x base.EngineMigration) error {
|
||||||
type Review struct {
|
type Review struct {
|
||||||
OriginalAuthor string
|
OriginalAuthor string
|
||||||
OriginalAuthorID int64
|
OriginalAuthorID int64
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FixTopicRepositoryCount(x db.EngineMigration) error {
|
func FixTopicRepositoryCount(x base.EngineMigration) error {
|
||||||
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_topic`"))
|
_, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_topic`"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -6,11 +6,11 @@ package v1_12
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/timeutil"
|
"gitea.dev/modules/timeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddLanguageStats(x db.EngineMigration) error {
|
func AddLanguageStats(x base.EngineMigration) error {
|
||||||
// LanguageStat see models/repo_language_stats.go
|
// LanguageStat see models/repo_language_stats.go
|
||||||
type LanguageStat struct {
|
type LanguageStat struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
@@ -11,14 +11,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/git"
|
"gitea.dev/modules/git"
|
||||||
"gitea.dev/modules/git/gitcmd"
|
"gitea.dev/modules/git/gitcmd"
|
||||||
"gitea.dev/modules/log"
|
"gitea.dev/modules/log"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FixMergeBase(ctx context.Context, x db.EngineMigration) error {
|
func FixMergeBase(ctx context.Context, x base.EngineMigration) error {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
OwnerID int64 `xorm:"UNIQUE(s) index"`
|
OwnerID int64 `xorm:"UNIQUE(s) index"`
|
||||||
@@ -114,7 +114,7 @@ func FixMergeBase(ctx context.Context, x db.EngineMigration) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pr.MergeBase = strings.TrimSpace(pr.MergeBase)
|
pr.MergeBase = strings.TrimSpace(pr.MergeBase)
|
||||||
x.ID(pr.ID).Cols("merge_base").Update(pr)
|
_, _ = x.ID(pr.ID).Cols("merge_base").Update(pr)
|
||||||
i++
|
i++
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import "gitea.dev/models/db"
|
import "gitea.dev/modelmigration/base"
|
||||||
|
|
||||||
func PurgeUnusedDependencies(x db.EngineMigration) error {
|
func PurgeUnusedDependencies(x base.EngineMigration) error {
|
||||||
if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil {
|
if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
package v1_12
|
package v1_12
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
"gitea.dev/modules/json"
|
"gitea.dev/modules/json"
|
||||||
"gitea.dev/modules/setting"
|
"gitea.dev/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExpandWebhooks(x db.EngineMigration) error {
|
func ExpandWebhooks(x base.EngineMigration) error {
|
||||||
type HookEvents struct {
|
type HookEvents struct {
|
||||||
Create bool `json:"create"`
|
Create bool `json:"create"`
|
||||||
Delete bool `json:"delete"`
|
Delete bool `json:"delete"`
|
||||||
@@ -6,10 +6,10 @@ package v1_12
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.dev/models/db"
|
"gitea.dev/modelmigration/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddSystemWebhookColumn(x db.EngineMigration) error {
|
func AddSystemWebhookColumn(x base.EngineMigration) error {
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
IsSystemWebhook bool `xorm:"NOT NULL DEFAULT false"`
|
IsSystemWebhook bool `xorm:"NOT NULL DEFAULT false"`
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user