storj/pkg/accounting/db.go
Bill Thorp b8b0d75cc6
made accounting use migrate (#688)
* made accounting use migrate
2018-11-26 16:49:55 -05:00

29 lines
575 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package accounting
import (
"storj.io/storj/internal/migrate"
dbx "storj.io/storj/pkg/accounting/dbx"
"storj.io/storj/pkg/utils"
)
// NewDb - constructor for DB
func NewDb(databaseURL string) (*dbx.DB, error) {
dbURL, err := utils.ParseURL(databaseURL)
if err != nil {
return nil, err
}
db, err := dbx.Open(dbURL.Scheme, dbURL.Path)
if err != nil {
return nil, err
}
err = migrate.Create("accounting", db)
if err != nil {
_ = db.Close()
return nil, err
}
return db, nil
}