diff options
Diffstat (limited to 'database.go')
-rw-r--r-- | database.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/database.go b/database.go index 20ec5a6..d19572a 100644 --- a/database.go +++ b/database.go @@ -21,17 +21,16 @@ const databaseSchemaVersion int = 2 // this defines the needed version for the // executable type Database struct { - config DatabaseConfig target string Backend *sql.DB } -func InitDatabase(config DatabaseConfig) Database { +func InitDatabase() Database { - db := NewDatabase(config) + db := NewDatabase() db.Connect() db.Ping() - db.Migrate(config.Migrations) + db.Migrate() // allow graceful shutdown var listener = make(chan os.Signal) @@ -47,18 +46,18 @@ func InitDatabase(config DatabaseConfig) Database { return db } -func NewDatabase(config DatabaseConfig) Database { +func NewDatabase() Database { db := Database{} - db.config = config var username string 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) + db.target = fmt.Sprintf("%s@unix(%s)/%s", username, config.Database.Socket, + config.Database.Database) return db } @@ -81,7 +80,7 @@ func (db *Database) Ping() { } } -func (db *Database) Migrate(dir string) { +func (db *Database) Migrate() { const t = databaseSchemaVersion // targeted database schema version @@ -101,7 +100,8 @@ func (db *Database) Migrate(dir string) { // execute migration log.Printf("Starting database schema migration to version %d.\n", v+1) - path := filepath.Join(dir, fmt.Sprintf("%04d_migration.sql", v+1)) + path := filepath.Join(config.Database.Migrations, + fmt.Sprintf("%04d_migration.sql", v+1)) RunSql(path) log.Printf("Finished database schema migration to version %d.\n", v+1) } |