mirror of https://github.com/perkeep/perkeep.git
sorted/mysql: create the db too if it doesn't exist.
Change-Id: I566d49052057848e9d4af0f01243a89db367e20a
This commit is contained in:
parent
b6cff26139
commit
ac5c2fd045
|
@ -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`,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue