Skip to content

Commit 88a2642

Browse files
authored
Merge branch 'main' into richmahn-16558-guess-delimiter
2 parents 059ae3d + 63c0dc8 commit 88a2642

File tree

14 files changed

+31
-31
lines changed

14 files changed

+31
-31
lines changed

cmd/cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func initDBDisableConsole(disableConsole bool) error {
6565
setting.InitDBConfig()
6666

6767
setting.NewXORMLogService(disableConsole)
68-
if err := db.SetEngine(); err != nil {
68+
if err := db.InitEngine(); err != nil {
6969
return fmt.Errorf("models.SetEngine: %v", err)
7070
}
7171
return nil

cmd/doctor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func runRecreateTable(ctx *cli.Context) error {
9696
setting.Cfg.Section("log").Key("XORM").SetValue(",")
9797

9898
setting.NewXORMLogService(!ctx.Bool("debug"))
99-
if err := db.SetEngine(); err != nil {
99+
if err := db.InitEngine(); err != nil {
100100
fmt.Println(err)
101101
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
102102
return nil
@@ -114,7 +114,7 @@ func runRecreateTable(ctx *cli.Context) error {
114114
}
115115
recreateTables := migrations.RecreateTables(beans...)
116116

117-
return db.NewEngine(context.Background(), func(x *xorm.Engine) error {
117+
return db.InitEngineWithMigration(context.Background(), func(x *xorm.Engine) error {
118118
if err := migrations.EnsureUpToDate(x); err != nil {
119119
return err
120120
}

cmd/dump.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func runDump(ctx *cli.Context) error {
173173
}
174174
setting.NewServices() // cannot access session settings otherwise
175175

176-
err := db.SetEngine()
176+
err := db.InitEngine()
177177
if err != nil {
178178
return err
179179
}

cmd/migrate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func runMigrate(ctx *cli.Context) error {
3535
log.Info("Configuration file: %s", setting.CustomConf)
3636
setting.InitDBConfig()
3737

38-
if err := db.NewEngine(context.Background(), migrations.Migrate); err != nil {
38+
if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
3939
log.Fatal("Failed to initialize ORM engine: %v", err)
4040
return err
4141
}

cmd/migrate_storage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func runMigrateStorage(ctx *cli.Context) error {
118118
log.Info("Configuration file: %s", setting.CustomConf)
119119
setting.InitDBConfig()
120120

121-
if err := db.NewEngine(context.Background(), migrations.Migrate); err != nil {
121+
if err := db.InitEngineWithMigration(context.Background(), migrations.Migrate); err != nil {
122122
log.Fatal("Failed to initialize ORM engine: %v", err)
123123
return err
124124
}

contrib/pr/checkout.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func runPR() {
9595
setting.Database.LogSQL = true
9696
//x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared")
9797

98-
db.NewEngine(context.Background(), func(_ *xorm.Engine) error {
98+
db.InitEngineWithMigration(context.Background(), func(_ *xorm.Engine) error {
9999
return nil
100100
})
101101
db.HasEngine = true

integrations/migration-test/migration_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -256,21 +256,21 @@ func doMigrationTest(t *testing.T, version string) {
256256

257257
setting.NewXORMLogService(false)
258258

259-
err := db.NewEngine(context.Background(), wrappedMigrate)
259+
err := db.InitEngineWithMigration(context.Background(), wrappedMigrate)
260260
assert.NoError(t, err)
261261
currentEngine.Close()
262262

263263
beans, _ := db.NamesToBean()
264264

265-
err = db.NewEngine(context.Background(), func(x *xorm.Engine) error {
265+
err = db.InitEngineWithMigration(context.Background(), func(x *xorm.Engine) error {
266266
currentEngine = x
267267
return migrations.RecreateTables(beans...)(x)
268268
})
269269
assert.NoError(t, err)
270270
currentEngine.Close()
271271

272272
// We do this a second time to ensure that there is not a problem with retained indices
273-
err = db.NewEngine(context.Background(), func(x *xorm.Engine) error {
273+
err = db.InitEngineWithMigration(context.Background(), func(x *xorm.Engine) error {
274274
currentEngine = x
275275
return migrations.RecreateTables(beans...)(x)
276276
})

models/db/engine.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ func init() {
9595
}
9696
}
9797

98-
// GetNewEngine returns a new xorm engine from the configuration
99-
func GetNewEngine() (*xorm.Engine, error) {
98+
// NewEngine returns a new xorm engine from the configuration
99+
func NewEngine() (*xorm.Engine, error) {
100100
connStr, err := setting.DBConnStr()
101101
if err != nil {
102102
return nil, err
@@ -128,11 +128,11 @@ func syncTables() error {
128128
return x.StoreEngine("InnoDB").Sync2(tables...)
129129
}
130130

131-
// NewInstallTestEngine creates a new xorm.Engine for testing during install
131+
// InitInstallEngineWithMigration creates a new xorm.Engine for testing during install
132132
//
133133
// This function will cause the basic database schema to be created
134-
func NewInstallTestEngine(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error) {
135-
x, err = GetNewEngine()
134+
func InitInstallEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error) {
135+
x, err = NewEngine()
136136
if err != nil {
137137
return fmt.Errorf("failed to connect to database: %w", err)
138138
}
@@ -160,9 +160,9 @@ func NewInstallTestEngine(ctx context.Context, migrateFunc func(*xorm.Engine) er
160160
return syncTables()
161161
}
162162

163-
// SetEngine sets the xorm.Engine
164-
func SetEngine() (err error) {
165-
x, err = GetNewEngine()
163+
// InitEngine sets the xorm.Engine
164+
func InitEngine() (err error) {
165+
x, err = NewEngine()
166166
if err != nil {
167167
return fmt.Errorf("Failed to connect to database: %v", err)
168168
}
@@ -178,13 +178,13 @@ func SetEngine() (err error) {
178178
return nil
179179
}
180180

181-
// NewEngine initializes a new xorm.Engine
181+
// InitEngineWithMigration initializes a new xorm.Engine
182182
// This function must never call .Sync2() if the provided migration function fails.
183183
// When called from the "doctor" command, the migration function is a version check
184184
// that prevents the doctor from fixing anything in the database if the migration level
185185
// is different from the expected value.
186-
func NewEngine(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error) {
187-
if err = SetEngine(); err != nil {
186+
func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error) {
187+
if err = InitEngine(); err != nil {
188188
return err
189189
}
190190

models/migrations/migrations_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func removeAllWithRetry(dir string) error {
8484
return err
8585
}
8686

87-
// SetEngine sets the xorm.Engine
88-
func SetEngine() (*xorm.Engine, error) {
89-
x, err := db.GetNewEngine()
87+
// newEngine sets the xorm.Engine
88+
func newEngine() (*xorm.Engine, error) {
89+
x, err := db.NewEngine()
9090
if err != nil {
9191
return x, fmt.Errorf("Failed to connect to database: %v", err)
9292
}
@@ -212,7 +212,7 @@ func prepareTestEnv(t *testing.T, skip int, syncModels ...interface{}) (*xorm.En
212212
return nil, deferFn
213213
}
214214

215-
x, err := SetEngine()
215+
x, err := newEngine()
216216
assert.NoError(t, err)
217217
if x != nil {
218218
oldDefer := deferFn

modules/doctor/dbconsistency.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func genericOrphanCheck(name, subject, refobject, joincond string) consistencyCh
7474

7575
func checkDBConsistency(logger log.Logger, autofix bool) error {
7676
// make sure DB version is uptodate
77-
if err := db.NewEngine(context.Background(), migrations.EnsureUpToDate); err != nil {
77+
if err := db.InitEngineWithMigration(context.Background(), migrations.EnsureUpToDate); err != nil {
7878
logger.Critical("Model version on the database does not match the current Gitea version. Model consistency will not be checked until the database is upgraded")
7979
return err
8080
}

modules/doctor/dbversion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
)
1414

1515
func checkDBVersion(logger log.Logger, autofix bool) error {
16-
if err := db.NewEngine(context.Background(), migrations.EnsureUpToDate); err != nil {
16+
if err := db.InitEngineWithMigration(context.Background(), migrations.EnsureUpToDate); err != nil {
1717
if !autofix {
1818
logger.Critical("Error: %v during ensure up to date", err)
1919
return err
2020
}
2121
logger.Warn("Got Error: %v during ensure up to date", err)
2222
logger.Warn("Attempting to migrate to the latest DB version to fix this.")
2323

24-
err = db.NewEngine(context.Background(), migrations.Migrate)
24+
err = db.InitEngineWithMigration(context.Background(), migrations.Migrate)
2525
if err != nil {
2626
logger.Critical("Error: %v during migration", err)
2727
}

modules/doctor/doctor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func initDBDisableConsole(disableConsole bool) error {
4747
setting.InitDBConfig()
4848

4949
setting.NewXORMLogService(disableConsole)
50-
if err := db.SetEngine(); err != nil {
50+
if err := db.InitEngine(); err != nil {
5151
return fmt.Errorf("models.SetEngine: %v", err)
5252
}
5353
return nil

routers/common/db.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func InitDBEngine(ctx context.Context) (err error) {
2525
default:
2626
}
2727
log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.Database.DBConnectRetries)
28-
if err = db.NewEngine(ctx, migrations.Migrate); err == nil {
28+
if err = db.InitEngineWithMigration(ctx, migrations.Migrate); err == nil {
2929
break
3030
} else if i == setting.Database.DBConnectRetries-1 {
3131
return err

routers/install/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func SubmitInstall(ctx *context.Context) {
209209
}
210210

211211
// Set test engine.
212-
if err = db.NewInstallTestEngine(ctx, migrations.Migrate); err != nil {
212+
if err = db.InitInstallEngineWithMigration(ctx, migrations.Migrate); err != nil {
213213
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
214214
ctx.Data["Err_DbType"] = true
215215
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://docs.gitea.io/en-us/install-from-binary/"), tplInstall, &form)

0 commit comments

Comments
 (0)