From c263923eab77ef17fb97eabcab0ef706810d5750 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Tue, 9 Apr 2024 12:25:14 -0400 Subject: [PATCH 1/2] Explicitly set collation for character columns --- .github/pull_request_template.md | 3 ++- .../tables/20240327115617_CreateTableNanoDDMRequests.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index feb3159edb..573d3b004a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -9,10 +9,11 @@ If some of the following don't apply, delete the relevant line. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests -- [ ] If database migrations are included, checked table schema to confirm autoupdate +- [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. + - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. diff --git a/server/datastore/mysql/migrations/tables/20240327115617_CreateTableNanoDDMRequests.go b/server/datastore/mysql/migrations/tables/20240327115617_CreateTableNanoDDMRequests.go index 2aa6de300b..e5595d7842 100644 --- a/server/datastore/mysql/migrations/tables/20240327115617_CreateTableNanoDDMRequests.go +++ b/server/datastore/mysql/migrations/tables/20240327115617_CreateTableNanoDDMRequests.go @@ -14,9 +14,9 @@ func Up_20240327115617(tx *sql.Tx) error { CREATE TABLE mdm_apple_declarative_requests ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - enrollment_id VARCHAR(255) NOT NULL, + enrollment_id VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL, -- Should be one of "tokens", "declaration-items", "status", or "declaration/…/…" where the ellipses reference a declaration on the server - message_type VARCHAR(255) NOT NULL, + message_type VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL, -- json payload raw_json TEXT, PRIMARY KEY (id), From 5d4bc856b9c8de2addd9f0469ea3f897695092c3 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Tue, 9 Apr 2024 12:26:38 -0400 Subject: [PATCH 2/2] Add changes file --- changes/18142-fix-migration-issue-related-to-collation | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/18142-fix-migration-issue-related-to-collation diff --git a/changes/18142-fix-migration-issue-related-to-collation b/changes/18142-fix-migration-issue-related-to-collation new file mode 100644 index 0000000000..cf48ada6d8 --- /dev/null +++ b/changes/18142-fix-migration-issue-related-to-collation @@ -0,0 +1 @@ +* Fixed an issue with the `20240327115617_CreateTableNanoDDMRequests` database migration where it could fail if the database did not default to the `utf8mb4_unicode_ci` collation.