diff --git a/cmd/backfill-index/main.go b/cmd/backfill-index/main.go index aa05e47ab..efb85ea3c 100644 --- a/cmd/backfill-index/main.go +++ b/cmd/backfill-index/main.go @@ -69,7 +69,14 @@ import ( ) const ( - mysqlWriteStmt = "INSERT IGNORE INTO EntryIndex (EntryKey, EntryUUID) VALUES (:key, :uuid)" + mysqlWriteStmt = "INSERT IGNORE INTO EntryIndex (EntryKey, EntryUUID) VALUES (:key, :uuid)" + mysqlCreateTableStmt = `CREATE TABLE IF NOT EXISTS EntryIndex ( + PK BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + EntryKey varchar(512) NOT NULL, + EntryUUID char(80) NOT NULL, + PRIMARY KEY(PK), + UNIQUE(EntryKey, EntryUUID) + )` ) type provider int @@ -190,6 +197,9 @@ func getIndexClient(backend provider) (indexClient, error) { if err = dbClient.Ping(); err != nil { return nil, err } + if _, err = dbClient.Exec(mysqlCreateTableStmt); err != nil { + return nil, err + } return &mysqlClient{client: dbClient}, nil default: return nil, fmt.Errorf("could not create client for unexpected provider")