Initial creation of the '.ooni/db' folders when not yet setup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/apex/log"
|
||||
@@ -29,16 +30,29 @@ func RunMigrations(db *sqlx.DB) error {
|
||||
}
|
||||
|
||||
// Connect to the database
|
||||
func Connect(path string) (*sqlx.DB, error) {
|
||||
db, err := sqlx.Connect("sqlite3", path)
|
||||
func Connect(path string) (db *sqlx.DB, err error) {
|
||||
home, err := ooni.GetOONIHome()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
if _, e := os.Stat(filepath.Join(home, "db")); e != nil {
|
||||
err = os.MkdirAll(filepath.Join(home, "db"), 0700)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
db, err = sqlx.Connect("sqlite3", path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = RunMigrations(db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
db = nil
|
||||
}
|
||||
return db, nil
|
||||
return
|
||||
}
|
||||
|
||||
// DefaultDatabasePath for the main database
|
||||
|
||||
Reference in New Issue
Block a user