mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
🐛 Add Migration for MySQL to certify that we're using the correct collation (#1905)
* Migration for MySQL to certify that we're using the correct collation
* Update migration to check for collation existence before running
* ⚡ Fix format
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
f8fcf0c165
commit
4dbf64b1a4
|
@ -0,0 +1,44 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
import config = require('../../../../config');
|
||||||
|
|
||||||
|
export class CertifyCorrectCollation1623936588000 implements MigrationInterface {
|
||||||
|
name = 'CertifyCorrectCollation1623936588000';
|
||||||
|
|
||||||
|
async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
const tablePrefix = config.get('database.tablePrefix');
|
||||||
|
const databaseType = config.get('database.type');
|
||||||
|
|
||||||
|
if (databaseType === 'mariadb') {
|
||||||
|
// This applies to MySQL only.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkCollationExistence = await queryRunner.query(`show collation where collation like 'utf8mb4_0900_ai_ci';`);
|
||||||
|
let collation = 'utf8mb4_general_ci';
|
||||||
|
if (checkCollationExistence.length > 0) {
|
||||||
|
collation = 'utf8mb4_0900_ai_ci';
|
||||||
|
}
|
||||||
|
|
||||||
|
const databaseName = config.get(`database.mysqldb.database`);
|
||||||
|
|
||||||
|
await queryRunner.query(`ALTER DATABASE \`${databaseName}\` CHARACTER SET utf8mb4 COLLATE ${collation};`);
|
||||||
|
|
||||||
|
for (const tableName of [
|
||||||
|
'credentials_entity',
|
||||||
|
'execution_entity',
|
||||||
|
'tag_entity',
|
||||||
|
'webhook_entity',
|
||||||
|
'workflow_entity',
|
||||||
|
'workflows_tags',
|
||||||
|
]) {
|
||||||
|
await queryRunner.query(`ALTER TABLE ${tablePrefix}${tableName} CONVERT TO CHARACTER SET utf8mb4 COLLATE ${collation};`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
// There is nothing to undo in this case as we already expect default collation to be utf8mb4
|
||||||
|
// This migration exists simply to enforce that n8n will work with
|
||||||
|
// older mysql versions
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import { ChangeDataSize1615306975123 } from './1615306975123-ChangeDataSize';
|
||||||
import { ChangeCredentialDataSize1620729500000 } from './1620729500000-ChangeCredentialDataSize';
|
import { ChangeCredentialDataSize1620729500000 } from './1620729500000-ChangeCredentialDataSize';
|
||||||
import { CreateTagEntity1617268711084 } from './1617268711084-CreateTagEntity';
|
import { CreateTagEntity1617268711084 } from './1617268711084-CreateTagEntity';
|
||||||
import { UniqueWorkflowNames1620826335440 } from './1620826335440-UniqueWorkflowNames';
|
import { UniqueWorkflowNames1620826335440 } from './1620826335440-UniqueWorkflowNames';
|
||||||
|
import { CertifyCorrectCollation1623936588000 } from './1623936588000-CertifyCorrectCollation';
|
||||||
|
|
||||||
export const mysqlMigrations = [
|
export const mysqlMigrations = [
|
||||||
InitialMigration1588157391238,
|
InitialMigration1588157391238,
|
||||||
|
@ -18,4 +19,5 @@ export const mysqlMigrations = [
|
||||||
ChangeCredentialDataSize1620729500000,
|
ChangeCredentialDataSize1620729500000,
|
||||||
CreateTagEntity1617268711084,
|
CreateTagEntity1617268711084,
|
||||||
UniqueWorkflowNames1620826335440,
|
UniqueWorkflowNames1620826335440,
|
||||||
|
CertifyCorrectCollation1623936588000,
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue