mirror of https://github.com/gogs/gogs.git
database: set `Handle` direcetly during initialization (#7699)
parent
dd49412edd
commit
8d2386b4db
|
@ -128,6 +128,7 @@ func NewConnection(w logger.Writer) (*gorm.DB, error) {
|
|||
TwoFactors = &twoFactorsStore{DB: db}
|
||||
Users = NewUsersStore(db)
|
||||
|
||||
Handle = &DB{db: db}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
|
@ -148,11 +149,6 @@ type DB struct {
|
|||
// single-thread process).
|
||||
var Handle *DB
|
||||
|
||||
// SetHandle updates the global database handle with the given connection.
|
||||
func SetHandle(db *gorm.DB) {
|
||||
Handle = &DB{db: db}
|
||||
}
|
||||
|
||||
func (db *DB) AccessTokens() *AccessTokensStore {
|
||||
return newAccessTokensStore(db.db)
|
||||
}
|
||||
|
|
|
@ -181,21 +181,21 @@ func SetEngine() (*gorm.DB, error) {
|
|||
return NewConnection(gormLogger)
|
||||
}
|
||||
|
||||
func NewEngine() (*gorm.DB, error) {
|
||||
func NewEngine() error {
|
||||
db, err := SetEngine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if err = migrations.Migrate(db); err != nil {
|
||||
return nil, fmt.Errorf("migrate: %v", err)
|
||||
return fmt.Errorf("migrate: %v", err)
|
||||
}
|
||||
|
||||
if err = x.StoreEngine("InnoDB").Sync2(legacyTables...); err != nil {
|
||||
return nil, errors.Wrap(err, "sync tables")
|
||||
return errors.Wrap(err, "sync tables")
|
||||
}
|
||||
|
||||
return db, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
type Statistic struct {
|
||||
|
|
|
@ -71,11 +71,10 @@ func GlobalInit(customConf string) error {
|
|||
if conf.Security.InstallLock {
|
||||
highlight.NewContext()
|
||||
markup.NewSanitizer()
|
||||
db, err := database.NewEngine()
|
||||
err := database.NewEngine()
|
||||
if err != nil {
|
||||
log.Fatal("Failed to initialize ORM engine: %v", err)
|
||||
}
|
||||
database.SetHandle(db)
|
||||
database.HasEngine = true
|
||||
|
||||
database.LoadRepoConfig()
|
||||
|
|
Loading…
Reference in New Issue