Skip to content

Commit

Permalink
don't ignore errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Aug 19, 2024
1 parent 9063398 commit 32febc2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions storage/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ func (e *engine) initSQLDatabase() error {
}
// SQL migration files use env variables for substitutions.
// TEXT SQL data type is really DB-specific, so we set a default here and override it for a specific database type (MS SQL).
_ = os.Setenv("TEXT_TYPE", "TEXT")
err = os.Setenv("TEXT_TYPE", "TEXT")
if err != nil {
return err
}
defer os.Unsetenv("TEXT_TYPE")
switch dbType {
case "sqlite":
Expand All @@ -227,20 +230,32 @@ func (e *engine) initSQLDatabase() error {
}
dialect = goose.DialectSQLite3
case "mysql":
e.sqlDB, _ = gorm.Open(mysql.New(mysql.Config{
e.sqlDB, err = gorm.Open(mysql.New(mysql.Config{
Conn: db,
}), gormConfig)
if err != nil {
return err
}
dialect = goose.DialectMySQL
case "postgres":
e.sqlDB, _ = gorm.Open(postgres.New(postgres.Config{
e.sqlDB, err = gorm.Open(postgres.New(postgres.Config{
Conn: db,
}), gormConfig)
if err != nil {
return err
}
dialect = goose.DialectPostgres
case "sqlserver":
_ = os.Setenv("TEXT_TYPE", "VARCHAR(MAX)")
e.sqlDB, _ = gorm.Open(sqlserver.New(sqlserver.Config{
err = os.Setenv("TEXT_TYPE", "VARCHAR(MAX)")
if err != nil {
return err
}
e.sqlDB, err = gorm.Open(sqlserver.New(sqlserver.Config{
Conn: db,
}), gormConfig)
if err != nil {
return err
}
dialect = goose.DialectMSSQL
default:
return errors.New("unsupported SQL database")
Expand Down

0 comments on commit 32febc2

Please sign in to comment.