Skip to content

Commit

Permalink
Create intermediate dirs for sqlite database (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
shifucun authored Oct 5, 2023
1 parent bdb0b80 commit d268ecf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ func main() {
if *useSQLite {
sqlClient, err = sqlite.CreateDB(*sqlDataPath)
if err != nil {
log.Fatalf("Can not open sqlite3 database from: %s", *sqlDataPath)
log.Fatalf("Cannot open sqlite3 database from: %s: %v", *sqlDataPath, err)
}
err := sqldb.CreateTables(sqlClient)
if err != nil {
log.Fatalf("Can not create tables %v", err)
log.Fatalf("Cannot create tables %v", err)
}
defer sqlClient.Close()
}
Expand All @@ -204,11 +204,11 @@ func main() {
} else {
sqlClient, err = cloudsql.ConnectWithConnector(*cloudSQLInstance)
if err != nil {
log.Fatalf("Can not open cloud sql database from %s: %v", *cloudSQLInstance, err)
log.Fatalf("Cannot open cloud sql database from %s: %v", *cloudSQLInstance, err)
}
err := sqldb.CreateTables(sqlClient)
if err != nil {
log.Fatalf("Can not create tables %v", err)
log.Fatalf("Cannot create tables %v", err)
}
defer sqlClient.Close()
}
Expand Down
4 changes: 4 additions & 0 deletions internal/sqldb/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
)

func CreateDB(fileDir string) (*sql.DB, error) {
// Create all intermediate directories.
if err := os.MkdirAll(fileDir, 0755); err != nil {
return nil, err
}
dbPath := filepath.Join(fileDir, "datacommons.db")
_, err := os.Stat(dbPath)
if err == nil {
Expand Down

0 comments on commit d268ecf

Please sign in to comment.