Skip to content

Commit

Permalink
[keyserver] Modify filename column in MariaDB uploads table to utf8
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ashoat committed Oct 6, 2023
1 parent fa2517d commit 7587ffa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 18 additions & 0 deletions keyserver/src/database/migration-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,24 @@ const migrations: $ReadOnlyMap<number, () => Promise<mixed>> = 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());

Expand Down
8 changes: 4 additions & 4 deletions keyserver/src/database/setup-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7587ffa

Please sign in to comment.