2015-08-18 05:57:27 +05:30
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2015-08-20 04:10:59 +05:30
|
|
|
if err = db.DropMigrationsTable(c); err != nil {
|
|
|
|
panic(fmt.Sprintf("Unable to drop migration table: %v", err))
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
2015-08-20 04:10:59 +05:30
|
|
|
|
|
|
|
db.MigrateToLatest(c)
|
2015-08-18 05:57:27 +05:30
|
|
|
return c
|
|
|
|
}
|