Commit c6d3868b authored by ale's avatar ale
Browse files

Add defaults to metadb config, explicitly fail on unsupported sql drivers

parent 8aff8b75
...@@ -43,8 +43,11 @@ func loadMetadbConfig(path string) (*metadbConfig, error) { ...@@ -43,8 +43,11 @@ func loadMetadbConfig(path string) (*metadbConfig, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var config metadbConfig config := metadbConfig{
config.MaxAgeDays = 180 Driver: "sqlite3",
DBURI: "/var/lib/tabacco-metadb/meta.db",
MaxAgeDays: 180,
}
err = yaml.Unmarshal(data, &config) err = yaml.Unmarshal(data, &config)
return &config, err return &config, err
} }
......
...@@ -19,16 +19,19 @@ import ( ...@@ -19,16 +19,19 @@ import (
) )
func openDB(dbDriver, dbURI string) (*sql.DB, error) { func openDB(dbDriver, dbURI string) (*sql.DB, error) {
if dbDriver == "sqlite3" && !strings.Contains(dbURI, "?") { if dbDriver != "sqlite3" {
return nil, fmt.Errorf("only the sqlite3 sql driver is supported")
}
if !strings.Contains(dbURI, "?") {
dbURI += "?_busy_timeout=10000&_journal=WAL&_mutex=full" dbURI += "?_busy_timeout=10000&_journal=WAL&_mutex=full"
} }
db, err := sql.Open(dbDriver, dbURI) db, err := sql.Open("sqlite3", dbURI)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err = runDatabaseMigrations(db, dbDriver); err != nil { if err = runDatabaseMigrations(db); err != nil {
db.Close() // nolint db.Close() // nolint
return nil, err return nil, err
} }
...@@ -48,7 +51,7 @@ func (l migrateLogger) Printf(format string, v ...interface{}) { ...@@ -48,7 +51,7 @@ func (l migrateLogger) Printf(format string, v ...interface{}) {
func (l migrateLogger) Verbose() bool { return true } func (l migrateLogger) Verbose() bool { return true }
func runDatabaseMigrations(db *sql.DB, dbDriver string) error { func runDatabaseMigrations(db *sql.DB) error {
si, err := bindata.WithInstance(bindata.Resource( si, err := bindata.WithInstance(bindata.Resource(
migrations.AssetNames(), migrations.AssetNames(),
func(name string) ([]byte, error) { func(name string) ([]byte, error) {
...@@ -66,7 +69,7 @@ func runDatabaseMigrations(db *sql.DB, dbDriver string) error { ...@@ -66,7 +69,7 @@ func runDatabaseMigrations(db *sql.DB, dbDriver string) error {
return err return err
} }
m, err := migrate.NewWithInstance("bindata", si, dbDriver, di) m, err := migrate.NewWithInstance("bindata", si, "sqlite3", di)
if err != nil { if err != nil {
return err return err
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment