Skip to content

Commit

Permalink
Run CREATE statement in backfill script (#2109)
Browse files Browse the repository at this point in the history
For the case where we want to start populating a new MySQL instance but
the Rekor server storage provider is not actually switched to MySQL yet,
ensure the table is created before trying to copy the data.

Signed-off-by: Colleen Murphy <[email protected]>
  • Loading branch information
cmurphy authored May 8, 2024
1 parent 7f43202 commit 891581e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/backfill-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 891581e

Please sign in to comment.