Skip to content

Commit f7f3a99

Browse files
committed
Fix bug on admin subcommand
1 parent d6f4820 commit f7f3a99

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

cmd/cmd.go

Lines changed: 1 addition & 1 deletion
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.InitEngine(); err != nil {
68+
if err := db.InitEngine(context.Background()); err != nil {
6969
return fmt.Errorf("models.SetEngine: %v", err)
7070
}
7171
return nil

cmd/doctor.go

Lines changed: 1 addition & 1 deletion
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.InitEngine(); err != nil {
99+
if err := db.InitEngine(context.Background()); 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

cmd/dump.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package cmd
77

88
import (
9+
"context"
910
"fmt"
1011
"os"
1112
"path"
@@ -173,7 +174,7 @@ func runDump(ctx *cli.Context) error {
173174
}
174175
setting.NewServices() // cannot access session settings otherwise
175176

176-
err := db.InitEngine()
177+
err := db.InitEngine(context.Background())
177178
if err != nil {
178179
return err
179180
}

models/db/engine.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ func InitInstallEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.
141141
x.SetLogger(NewXORMLogger(!setting.IsProd))
142142
x.ShowSQL(!setting.IsProd)
143143

144+
DefaultContext = &Context{
145+
Context: ctx,
146+
e: x,
147+
}
144148
x.SetDefaultContext(ctx)
145149

146150
if err = x.Ping(); err != nil {
@@ -161,7 +165,7 @@ func InitInstallEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.
161165
}
162166

163167
// InitEngine sets the xorm.Engine
164-
func InitEngine() (err error) {
168+
func InitEngine(ctx context.Context) (err error) {
165169
x, err = NewEngine()
166170
if err != nil {
167171
return fmt.Errorf("Failed to connect to database: %v", err)
@@ -175,6 +179,12 @@ func InitEngine() (err error) {
175179
x.SetMaxOpenConns(setting.Database.MaxOpenConns)
176180
x.SetMaxIdleConns(setting.Database.MaxIdleConns)
177181
x.SetConnMaxLifetime(setting.Database.ConnMaxLifetime)
182+
183+
DefaultContext = &Context{
184+
Context: ctx,
185+
e: x,
186+
}
187+
x.SetDefaultContext(ctx)
178188
return nil
179189
}
180190

@@ -184,17 +194,10 @@ func InitEngine() (err error) {
184194
// that prevents the doctor from fixing anything in the database if the migration level
185195
// is different from the expected value.
186196
func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine) error) (err error) {
187-
if err = InitEngine(); err != nil {
197+
if err = InitEngine(ctx); err != nil {
188198
return err
189199
}
190200

191-
DefaultContext = &Context{
192-
Context: ctx,
193-
e: x,
194-
}
195-
196-
x.SetDefaultContext(ctx)
197-
198201
if err = x.Ping(); err != nil {
199202
return err
200203
}

modules/doctor/doctor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package doctor
66

77
import (
8+
"context"
89
"fmt"
910
"sort"
1011
"strings"
@@ -47,7 +48,7 @@ func initDBDisableConsole(disableConsole bool) error {
4748
setting.InitDBConfig()
4849

4950
setting.NewXORMLogService(disableConsole)
50-
if err := db.InitEngine(); err != nil {
51+
if err := db.InitEngine(context.Background()); err != nil {
5152
return fmt.Errorf("models.SetEngine: %v", err)
5253
}
5354
return nil

0 commit comments

Comments
 (0)