🎨 prepare to make the database name configurable
We should not hardcode the database name at different places in db.Init(). This will allow to make the database path configurable in a later change, and importantly prevent discrepancies
This commit is contained in:
parent
49281f2ca8
commit
80d565e978
7
db/db.go
7
db/db.go
|
@ -4,6 +4,7 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"git.beisel.it/florian/hostname-service/models"
|
||||
|
@ -17,16 +18,16 @@ import (
|
|||
var DB *sql.DB
|
||||
|
||||
// Initialize the database and create tables if they don't exist
|
||||
func Init() {
|
||||
func Init(db string) {
|
||||
var err error
|
||||
DB, err = sql.Open("sqlite3", "hostname-service.db")
|
||||
DB, err = sql.Open("sqlite3", db)
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening database: %v", err)
|
||||
}
|
||||
|
||||
m, err := migrate.New(
|
||||
"file://db/migrations/",
|
||||
"sqlite3://hostname-service.db",
|
||||
fmt.Sprintf("sqlite3://%s", db),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue