summaryrefslogtreecommitdiff
path: root/utils/database.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/database.go')
-rw-r--r--utils/database.go24
1 files changed, 6 insertions, 18 deletions
diff --git a/utils/database.go b/utils/database.go
index b8a6941..f48af35 100644
--- a/utils/database.go
+++ b/utils/database.go
@@ -31,7 +31,7 @@ func InitDatabase(config DatabaseConfig) Database {
db := NewDatabase(config)
db.Connect()
db.Ping()
- db.Migrate(config.Debug)
+ db.Migrate(config.Migrations)
// allow graceful shutdown
var listener = make(chan os.Signal)
@@ -53,15 +53,11 @@ func NewDatabase(config DatabaseConfig) Database {
db.config = config
var username string
- if config.Debug {
- user_ptr,err := user.Current()
- if err != nil {
- log.Fatal(err)
- }
- username = user_ptr.Username
- } else {
- username = config.User
+ user_ptr,err := user.Current()
+ if err != nil {
+ log.Fatal(err)
}
+ username = user_ptr.Username
db.target = fmt.Sprintf("%s@unix(%s)/%s", username, config.Socket, config.Database)
return db
@@ -85,15 +81,7 @@ func (db *Database) Ping() {
}
}
-func (db *Database) Migrate(debug bool) {
-
- // get directory with SQL migration scripts
- var dir string
- if debug {
- dir = "./sql"
- } else {
- dir = "/usr/share/ceres/migrations/"
- }
+func (db *Database) Migrate(dir string) {
const t = databaseSchemaVersion // targeted database schema version