fix: mysql notification target table creation (#14350)

Add a generated hash column as the primary key for the key name as 
MySQL does not allow indexes on long VARCHAR columns.
This commit is contained in:
Aditya Manthramurthy 2022-02-18 12:13:49 -08:00 committed by GitHub
parent b23b19e5c3
commit bc110d8055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,13 +38,16 @@ import (
const (
mysqlTableExists = `SELECT 1 FROM %s;`
// Some MySQL has a 3072 byte limit on key sizes.
mysqlCreateNamespaceTable = `CREATE TABLE %s (key_name VARCHAR(3072), value JSON, PRIMARY KEY (key_name))
CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;`
mysqlCreateNamespaceTable = `CREATE TABLE %s (
key_name VARCHAR(3072) NOT NULL,
key_hash CHAR(64) GENERATED ALWAYS AS (SHA2(key_name, 256)) STORED NOT NULL PRIMARY KEY,
value JSON)
CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin ROW_FORMAT = Dynamic;`
mysqlCreateAccessTable = `CREATE TABLE %s (event_time DATETIME NOT NULL, event_data JSON)
ROW_FORMAT = Dynamic;`
mysqlUpdateRow = `INSERT INTO %s (key_name, value) VALUES (?, ?) ON DUPLICATE KEY UPDATE value=VALUES(value);`
mysqlDeleteRow = `DELETE FROM %s WHERE key_name = ?;`
mysqlDeleteRow = `DELETE FROM %s WHERE key_hash = SHA2(?, 256);`
mysqlInsertRow = `INSERT INTO %s (event_time, event_data) VALUES (?, ?);`
)