From b216219c443e94176e797c647c031604af5ea722 Mon Sep 17 00:00:00 2001 From: Sarah Gillespie <73313222+gillespi314@users.noreply.github.com> Date: Thu, 12 Jun 2025 17:13:58 -0500 Subject: [PATCH] Fix DB migration bug when adding MDM enroll tables (#29963) --- changes/28860-fix-migration | 3 +++ .../20250502222222_AddMdmEnrollTables.go | 6 +++--- .../20250502222222_AddMdmEnrollTables_test.go | 18 +++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 changes/28860-fix-migration diff --git a/changes/28860-fix-migration b/changes/28860-fix-migration new file mode 100644 index 0000000000..0c37096c24 --- /dev/null +++ b/changes/28860-fix-migration @@ -0,0 +1,3 @@ +- Fixed an issue in the database migrations released in 4.68.0 where Apple devices with UDID values + longer than 36 characters would cause a failure in the migration process; the `host_uuid` column + for tables added by that migration has been increased to accommodate these longer UDID values. diff --git a/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go b/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go index e58dbdd3b9..eb870bdcc5 100644 --- a/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go +++ b/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables.go @@ -26,7 +26,7 @@ func Up_20250502222222(tx *sql.Tx) error { createStmt := ` CREATE TABLE IF NOT EXISTS legacy_host_mdm_enroll_refs ( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - host_uuid VARCHAR(36) NOT NULL, + host_uuid VARCHAR(255) NOT NULL, enroll_ref VARCHAR(36) NOT NULL, INDEX idx_legacy_enroll_refs_host_uuid (host_uuid) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci; @@ -38,7 +38,7 @@ CREATE TABLE IF NOT EXISTS legacy_host_mdm_enroll_refs ( createStmt += ` CREATE TABLE IF NOT EXISTS legacy_host_mdm_idp_accounts ( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - host_uuid VARCHAR(36) NOT NULL, + host_uuid VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, account_uuid VARCHAR(36) NULL, host_id INT UNSIGNED NULL, @@ -55,7 +55,7 @@ CREATE TABLE IF NOT EXISTS legacy_host_mdm_idp_accounts ( createStmt += ` CREATE TABLE IF NOT EXISTS host_mdm_idp_accounts ( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - host_uuid VARCHAR(36) NOT NULL, + host_uuid VARCHAR(255) NOT NULL, account_uuid VARCHAR(36) NOT NULL DEFAULT '', created_at DATETIME (6) NOT NULL DEFAULT NOW(6), updated_at DATETIME (6) NOT NULL DEFAULT NOW(6) ON UPDATE NOW(6), diff --git a/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables_test.go b/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables_test.go index e1cbd1add6..ff804c349b 100644 --- a/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables_test.go +++ b/server/datastore/mysql/migrations/tables/20250502222222_AddMdmEnrollTables_test.go @@ -62,7 +62,7 @@ func TestUp_20250502222222(t *testing.T) { fmt.Sprintf("serial-%d", id), fmt.Sprintf("osquery-host-id-%d", id), fmt.Sprintf("node-key-%d", id), - fmt.Sprintf("host-uuid-%d", id), + fmt.Sprintf("host-uuid-extra-looooooooooooooooooooooooooooooong-%d", id), platform, )) } @@ -115,7 +115,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with unmatched url ref but mdm account email match", hostID: 1, - hostUUID: "host-uuid-1", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-1", hostMDM: hostMDM{ HostID: 1, FleetEnrollRef: "nobody-uuid", @@ -131,7 +131,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with unmatched url ref but multiple mdm account email matches", hostID: 2, - hostUUID: "host-uuid-2", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-2", hostMDM: hostMDM{ HostID: 2, FleetEnrollRef: "nobody-uuid", @@ -150,7 +150,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with legacy match and multiple mdm account email matches", hostID: 3, - hostUUID: "host-uuid-3", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-3", hostMDM: hostMDM{ HostID: 3, FleetEnrollRef: "bob-uuid", @@ -169,7 +169,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with legacy match and no mdm account email matches", hostID: 4, - hostUUID: "host-uuid-4", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-4", hostMDM: hostMDM{ HostID: 4, FleetEnrollRef: "bob-uuid", @@ -184,7 +184,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with no legacy match and no mdm account email matches", hostID: 5, - hostUUID: "host-uuid-5", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-5", hostMDM: hostMDM{ HostID: 5, FleetEnrollRef: "nobody-uuid", @@ -199,7 +199,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with no legacy match and no mdm account emails", hostID: 6, - hostUUID: "host-uuid-6", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-6", hostMDM: hostMDM{ HostID: 6, FleetEnrollRef: "nobody-uuid", @@ -212,7 +212,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with legacy match and no emails", hostID: 7, - hostUUID: "host-uuid-7", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-7", hostMDM: hostMDM{ HostID: 7, FleetEnrollRef: "bob-uuid", @@ -225,7 +225,7 @@ func TestUp_20250502222222(t *testing.T) { { name: "host with no legacy match and only google emails", hostID: 8, - hostUUID: "host-uuid-8", + hostUUID: "host-uuid-extra-looooooooooooooooooooooooooooooong-8", hostMDM: hostMDM{ HostID: 8, FleetEnrollRef: "nobody-uuid",