Change from adding the parameter to enforcing it
This commit is contained in:
parent
e7a48127e6
commit
9bd9ed08da
|
|
@ -31,14 +31,12 @@ var dialectMap = map[string]interface{}{
|
|||
// It automatically maps the tables for the primary parts of Boulder around the
|
||||
// Storage Authority. This may require some further work when we use a disjoint
|
||||
// schema, like that for `certificate-authority-data.go`.
|
||||
func NewDbMap(driver string, nameIn string) (*gorp.DbMap, error) {
|
||||
func NewDbMap(driver string, name string) (*gorp.DbMap, error) {
|
||||
logger := blog.GetAuditLogger()
|
||||
|
||||
// We require this parameter, so add it if not present
|
||||
name := nameIn
|
||||
parseTime := "?parseTime=true"
|
||||
if !strings.HasSuffix(name, parseTime) {
|
||||
name = name + parseTime
|
||||
// We require this parameter for MySQL, so fail now if it is not present
|
||||
if driver == "mysql" && !strings.Contains(name, "parseTime=true") {
|
||||
return nil, fmt.Errorf("Database name must have parseTime=true")
|
||||
}
|
||||
|
||||
db, err := sql.Open(driver, name)
|
||||
|
|
|
|||
|
|
@ -30,3 +30,8 @@ func TestForgottenDialect(t *testing.T) {
|
|||
_, err := NewDbMap("sqlite3", ":memory:")
|
||||
test.AssertError(t, err, "Shouldn't have found the dialect")
|
||||
}
|
||||
|
||||
func TestParseTimeRequired(t *testing.T) {
|
||||
_, err := NewDbMap("mysql", "invalid")
|
||||
test.AssertError(t, err, "DB name must have parseTime=true")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue