Files
cloudron-box/migrations/20250618200400-fix-charset-collate.js
Girish Ramakrishnan b23699f0c1 db: change the encoding and collation
by mistake many fields are encoded at utf8 which is an alias of utf8mb3

fixes #836
2025-06-18 22:08:43 +02:00

30 lines
1.1 KiB
JavaScript

'use strict';
exports.up = async function (db) {
const tableNames = [
'userGroups', 'users', 'domains', 'tasks', 'volumes', 'apps', 'backups', 'mail',
'appAddonConfigs', 'appEnvVars', 'appMounts', 'appPasswords', 'appPortBindings', 'applinks', 'archives',
'blobs', 'dockerRegistries', 'eventlog', 'groupMembers', 'locations', 'locks', 'mailboxes',
'migrations', 'notifications', 'oidcClients', 'settings', 'tokens'
];
await db.runSql('SET foreign_key_checks = 0');
// this should already be the default
console.log('Changing database charset');
await db.runSql('ALTER DATABASE box CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin');
for (const tableName of tableNames) {
// this update all applicable columns (VARCHAR, TEXT, etc.) to use the new character set and collation and not just the table!
console.log(`Changing charset of ${tableName}`);
await db.runSql(`ALTER TABLE ${tableName} CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin`);
}
await db.runSql('SET foreign_key_checks = 1');
};
exports.down = async function (db) {
// no going back!
};