@ -95,8 +95,8 @@ func init() {
}
}
}
}
// Get NewEngine returns a new xorm engine from the configuration
// NewEngine returns a new xorm engine from the configuration
func Get NewEngine( ) ( * xorm . Engine , error ) {
func NewEngine ( ) ( * xorm . Engine , error ) {
connStr , err := setting . DBConnStr ( )
connStr , err := setting . DBConnStr ( )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -128,11 +128,11 @@ func syncTables() error {
return x . StoreEngine ( "InnoDB" ) . Sync2 ( tables ... )
return x . StoreEngine ( "InnoDB" ) . Sync2 ( tables ... )
}
}
// NewInstallTestEngine creates a new xorm.Engine for testing during install
// InitInstallEngineWithMigration creates a new xorm.Engine for testing during install
//
//
// This function will cause the basic database schema to be created
// This function will cause the basic database schema to be created
func NewInstallTestEngine ( ctx context . Context , migrateFunc func ( * xorm . Engine ) error ) ( err error ) {
func InitInstallEngineWithMigration ( ctx context . Context , migrateFunc func ( * xorm . Engine ) error ) ( err error ) {
x , err = Get NewEngine( )
x , err = NewEngine ( )
if err != nil {
if err != nil {
return fmt . Errorf ( "failed to connect to database: %w" , err )
return fmt . Errorf ( "failed to connect to database: %w" , err )
}
}
@ -160,9 +160,9 @@ func NewInstallTestEngine(ctx context.Context, migrateFunc func(*xorm.Engine) er
return syncTables ( )
return syncTables ( )
}
}
// Se tEngine sets the xorm.Engine
// Ini tEngine sets the xorm.Engine
func Se tEngine( ) ( err error ) {
func Ini tEngine( ) ( err error ) {
x , err = Get NewEngine( )
x , err = NewEngine ( )
if err != nil {
if err != nil {
return fmt . Errorf ( "Failed to connect to database: %v" , err )
return fmt . Errorf ( "Failed to connect to database: %v" , err )
}
}
@ -178,13 +178,13 @@ func SetEngine() (err error) {
return nil
return nil
}
}
// NewEngine initializes a new xorm.Engine
// InitEngineWithMigration initializes a new xorm.Engine
// This function must never call .Sync2() if the provided migration function fails.
// This function must never call .Sync2() if the provided migration function fails.
// When called from the "doctor" command, the migration function is a version check
// When called from the "doctor" command, the migration function is a version check
// that prevents the doctor from fixing anything in the database if the migration level
// that prevents the doctor from fixing anything in the database if the migration level
// is different from the expected value.
// is different from the expected value.
func NewEngine ( ctx context . Context , migrateFunc func ( * xorm . Engine ) error ) ( err error ) {
func InitEngineWithMigration ( ctx context . Context , migrateFunc func ( * xorm . Engine ) error ) ( err error ) {
if err = Se tEngine( ) ; err != nil {
if err = Ini tEngine( ) ; err != nil {
return err
return err
}
}