4ce5a36d08
gorp hates nil.
29 lines
613 B
Go
29 lines
613 B
Go
package repo
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/coopernurse/gorp"
|
|
|
|
"github.com/coreos/dex/db"
|
|
)
|
|
|
|
func initDB(dsn string) *gorp.DbMap {
|
|
c, err := db.NewConnection(db.Config{DSN: dsn})
|
|
if err != nil {
|
|
panic(fmt.Sprintf("Unable to connect to database: %v", err))
|
|
}
|
|
|
|
if err = c.DropTablesIfExists(); err != nil {
|
|
panic(fmt.Sprintf("Unable to drop database tables: %v", err))
|
|
}
|
|
|
|
if err = db.DropMigrationsTable(c); err != nil {
|
|
panic(fmt.Sprintf("Unable to drop migration table: %v", err))
|
|
}
|
|
|
|
if _, err = db.MigrateToLatest(c); err != nil {
|
|
panic(fmt.Sprintf("Unable to migrate: %v", err))
|
|
}
|
|
return c
|
|
}
|