-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add table default encodings/charsets to all migrations missing them, …
…retrofit existing DB schema (#26670) For #25353. This both fixes new installs going forward (in which case the final migration is a no-op) and cleans up existing installs that have the wrong collations (in the new migration). # 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] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [x] Manual QA for all new/changed functionality
- Loading branch information
Showing
22 changed files
with
128 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Set collation and character set explicitly on database tables that were missing explicit values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
server/datastore/mysql/migrations/tables/20250127162751_AddUnifiedQueueTable_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tables | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jmoiron/sqlx" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Test is for collation fix; uniQ migration didn't have a test before | ||
func TestUp_20250127162751(t *testing.T) { | ||
db := applyUpToPrev(t) | ||
execNoErr(t, db, "SET FOREIGN_KEY_CHECKS = 0") | ||
execNoErr(t, db, "DROP TABLE mdm_apple_bootstrap_packages") | ||
execNoErr(t, db, "CREATE TABLE mdm_apple_bootstrap_packages (team_id int(10) unsigned NOT NULL PRIMARY KEY, name varchar(255)) CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci") | ||
execNoErr(t, db, "INSERT INTO mdm_apple_bootstrap_packages (team_id, name) VALUES (1, 'Care Package')") | ||
execNoErr(t, db, "DROP TABLE host_mdm_apple_bootstrap_packages") | ||
execNoErr(t, db, "CREATE TABLE host_mdm_apple_bootstrap_packages (host_uuid VARCHAR(127) NOT NULL PRIMARY KEY) CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci") | ||
execNoErr(t, db, "INSERT INTO host_mdm_apple_bootstrap_packages (host_uuid) VALUES ('a123b123')") | ||
execNoErr(t, db, "SET FOREIGN_KEY_CHECKS = 1") | ||
|
||
// force a query with an error | ||
var c int | ||
err := sqlx.Get(db, &c, "SELECT COUNT(*) FROM host_mdm_apple_bootstrap_packages hmabp JOIN hosts h WHERE h.uuid = hmabp.host_uuid") | ||
require.ErrorContains(t, err, "Error 1267") | ||
|
||
applyNext(t, db) | ||
|
||
err = sqlx.Get(db, &c, "SELECT COUNT(*) FROM host_mdm_apple_bootstrap_packages hmabp JOIN hosts h WHERE h.uuid = hmabp.host_uuid") | ||
require.NoError(t, err) | ||
|
||
// verify that there are no tables with the wrong collation | ||
var names []string | ||
err = sqlx.Select(db, &names, ` | ||
SELECT table_name | ||
FROM information_schema.TABLES | ||
WHERE table_collation != "utf8mb4_unicode_ci" AND table_schema = (SELECT database())`) | ||
require.NoError(t, err) | ||
require.Empty(t, names) | ||
|
||
// verify that the collation was maintained for certain columns | ||
var columns []string | ||
err = sqlx.Select(db, &columns, ` | ||
SELECT column_name | ||
FROM information_schema.COLUMNS | ||
WHERE collation_name != "utf8mb4_unicode_ci" AND table_schema = (SELECT database())`) | ||
require.NoError(t, err) | ||
require.Equal(t, []string{"secret", "node_key", "orbit_node_key", "name_bin"}, columns) | ||
} |