From ac5c2fd0451b679166dacdf4c5ecaa105ec90618 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 6 Aug 2014 17:21:42 -0700 Subject: [PATCH] sorted/mysql: create the db too if it doesn't exist. Change-Id: I566d49052057848e9d4af0f01243a89db367e20a --- pkg/sorted/mysql/dbschema.go | 5 +++-- pkg/sorted/mysql/mysqlkv.go | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/sorted/mysql/dbschema.go b/pkg/sorted/mysql/dbschema.go index ac52e125a..4aa51a7f7 100644 --- a/pkg/sorted/mysql/dbschema.go +++ b/pkg/sorted/mysql/dbschema.go @@ -28,12 +28,13 @@ func SchemaVersion() int { // which is purely about bytes. func SQLCreateTables() []string { return []string{ - `CREATE TABLE IF NOT EXISTS /*DB*/rows ( + `CREATE DATABASE IF NOT EXISTS /*DB*/`, + `CREATE TABLE IF NOT EXISTS /*DB*/.rows ( k VARCHAR(255) NOT NULL PRIMARY KEY, v VARCHAR(255)) DEFAULT CHARACTER SET binary`, - `CREATE TABLE IF NOT EXISTS /*DB*/meta ( + `CREATE TABLE IF NOT EXISTS /*DB*/.meta ( metakey VARCHAR(255) NOT NULL PRIMARY KEY, value VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET binary`, diff --git a/pkg/sorted/mysql/mysqlkv.go b/pkg/sorted/mysql/mysqlkv.go index 9a00f72f0..7c66e7f13 100644 --- a/pkg/sorted/mysql/mysqlkv.go +++ b/pkg/sorted/mysql/mysqlkv.go @@ -47,6 +47,10 @@ func newKeyValueFromJSONConfig(cfg jsonconfig.Obj) (sorted.KeyValue, error) { } var err error if host != "" { + host, err = maybeRemapCloudSQL(host) + if err != nil { + return nil, err + } if !strings.Contains(host, ":") { host += ":3306" } @@ -65,7 +69,7 @@ func newKeyValueFromJSONConfig(cfg jsonconfig.Obj) (sorted.KeyValue, error) { } for _, tableSQL := range SQLCreateTables() { - tableSQL = strings.Replace(tableSQL, "/*DB*/", database+".", -1) + tableSQL = strings.Replace(tableSQL, "/*DB*/", database, -1) if _, err := db.Exec(tableSQL); err != nil { return nil, fmt.Errorf("error creating table with %q: %v", tableSQL, err) }