From 7587ffa4c8718ce9c06645da3c9e683ff4b49e58 Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Fri, 6 Oct 2023 14:57:49 -0400 Subject: [PATCH] [keyserver] Modify filename column in MariaDB uploads table to utf8 Summary: Instead of just updating the filename column, I updated the default to `utf8_mb4` (the "real" utf8 encoding in MariaDB). That way if we create a future column, it will default to utf8. I think added explicit annotations to keep the other columns the same, to avoid any weird effects. Test Plan: 1. I tested that the migration works in my local environment 2. I tested that the `setup-db.js` query works by copy-pasting it into a MariaDB console in my local environment (with a different name for the table) 3. I then ran `SHOW FULL COLUMNS FROM` on both the migration result and the `setup-db.js` result to confirm they were the same: https://gist.github.com/Ashoat/0494344fa432995cf0219aed25fcb321 4. Finally, I confirmed that my repro (drag-n-drop a screenshot on macOS before it saves to desktop) no longer repro'd Reviewers: atul, bartek Reviewed By: atul, bartek Subscribers: tomek, wyilio Differential Revision: https://phab.comm.dev/D9403 --- keyserver/src/database/migration-config.js | 18 ++++++++++++++++++ keyserver/src/database/setup-db.js | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/keyserver/src/database/migration-config.js b/keyserver/src/database/migration-config.js index 1ff14c9592..effeaddf7b 100644 --- a/keyserver/src/database/migration-config.js +++ b/keyserver/src/database/migration-config.js @@ -539,6 +539,24 @@ const migrations: $ReadOnlyMap Promise> = new Map([ ); }, ], + [ + 45, + () => + dbQuery( + SQL` + ALTER TABLE uploads + CHARSET utf8mb4 COLLATE utf8mb4_bin, + MODIFY COLUMN type varchar(255) + CHARSET latin1 COLLATE latin1_swedish_ci NOT NULL, + MODIFY COLUMN filename varchar(255) + CHARSET utf8mb4 COLLATE utf8mb4_bin NOT NULL, + MODIFY COLUMN mime varchar(255) + CHARSET latin1 COLLATE latin1_swedish_ci NOT NULL, + MODIFY COLUMN secret varchar(255) + CHARSET latin1 COLLATE latin1_swedish_ci NOT NULL; + `, + ), + ], ]); const newDatabaseVersion: number = Math.max(...migrations.keys()); diff --git a/keyserver/src/database/setup-db.js b/keyserver/src/database/setup-db.js index 760e5172ca..dddb40da0d 100644 --- a/keyserver/src/database/setup-db.js +++ b/keyserver/src/database/setup-db.js @@ -183,14 +183,14 @@ async function createTables() { thread bigint(20) DEFAULT NULL, uploader varchar(255) CHARSET latin1 COLLATE latin1_bin NOT NULL, container bigint(20) DEFAULT NULL, - type varchar(255) NOT NULL, + type varchar(255) CHARSET latin1 COLLATE latin1_swedish_ci NOT NULL, filename varchar(255) NOT NULL, - mime varchar(255) NOT NULL, + mime varchar(255) CHARSET latin1 COLLATE latin1_swedish_ci NOT NULL, content longblob NOT NULL, - secret varchar(255) NOT NULL, + secret varchar(255) CHARSET latin1 COLLATE latin1_swedish_ci NOT NULL, creation_time bigint(20) NOT NULL, extra json DEFAULT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; CREATE TABLE users ( id varchar(255) CHARSET latin1 COLLATE latin1_bin NOT NULL,