storj/private/dbutil/split.go
Jeff Wendling 48da8baab5 storj-sim: work with cockroach:// urls for satellite databases
for storj-sim to work, we need to avoid schemas in cockroach urls
so we have storj-sim create namespaced databases instead of schemas
and we have the migrate command create the database in the same way
that it would create a schema for postgres. then it works!

a follow up commit will move the creation of the database/schemas
into storj-sim's setup step so that we can avoid doing these icky
creations during normal migration calls. it will also make the
pointerdb have an explicit call to migrate instead of just doing
it every time it's opened.

Change-Id: If69ef5cb96b6866b0438c761bd445afb3597ae5f
2019-12-09 23:44:00 +00:00

31 lines
872 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package dbutil
import (
"fmt"
"strings"
)
// SplitConnStr returns the driver and DSN portions of a URL, along with the db implementation.
func SplitConnStr(s string) (driver string, source string, implementation Implementation, err error) {
// consider https://github.com/xo/dburl if this ends up lacking
parts := strings.SplitN(s, "://", 2)
if len(parts) != 2 {
return "", "", Unknown, fmt.Errorf("could not parse DB URL %s", s)
}
driver = parts[0]
source = parts[1]
implementation = ImplementationForScheme(parts[0])
if driver == "postgres" {
source = s // postgres wants full URLS for its DSN
}
if driver == "cockroach" {
driver = "postgres" // cockroach's driver is actually postgres
source = "postgres://" + source
}
return driver, source, implementation, nil
}