fleet/server/datastore/mysql/migrations/tables/20230202224725_CreateHostDiskEncryptionKeysTable.go
Jahziel Villasana-Espinoza 9d2b07f76f
add a test that checks collation on new migrations (#29309)
> closes #26403

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
2025-05-29 17:00:30 -04:00

33 lines
1.1 KiB
Go

package tables
import (
"database/sql"
)
func init() {
MigrationClient.AddMigration(Up_20230202224725, Down_20230202224725)
}
func Up_20230202224725(tx *sql.Tx) error {
// `decryptable` can be NULL to signal that we have fetched the key but
// we don't know yet if we can decrypt it or not, the related index is
// to aid querying for this scenario by taking adventage of MySQL's IS
// NULL optimization:
// https://dev.mysql.com/doc/refman/5.7/en/is-null-optimization.html
_, err := tx.Exec(`
CREATE TABLE IF NOT EXISTS host_disk_encryption_keys (
host_id int(10) UNSIGNED NOT NULL,
base64_encrypted text NOT NULL,
decryptable tinyint(1) DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (host_id),
KEY idx_host_disk_encryption_keys_decryptable (decryptable)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`)
return err
}
func Down_20230202224725(tx *sql.Tx) error {
return nil
}