Skip to content

Commit

Permalink
Provide charset and collate options only for dialects supporting them (
Browse files Browse the repository at this point in the history
…#624)

Fixes #612 

Fixes #623
  • Loading branch information
QuentinFarizon authored Nov 3, 2023
1 parent e502214 commit 6c43202
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/storage/sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export type SequelizeType = {
isDefined(modelName: string): boolean;
model(modelName: string): any;
define(modelName: string, columns: {}, options: {}): {};
dialect?: {
name?: string;
};
};

const DIALECTS_WITH_CHARSET_AND_COLLATE = new Set(['mysql', 'mariadb', 'snowflake']);

type ModelClassType = ModelClass & (new (values?: object, options?: any) => ModelTempInterface);

type _SequelizeStorageConstructorOptions = {
Expand Down Expand Up @@ -127,6 +132,9 @@ export class SequelizeStorage implements UmzugStorage {
return this.sequelize.model(this.modelName);
}

const dialectName = this.sequelize.dialect?.name;
const hasCharsetAndCollate = dialectName && DIALECTS_WITH_CHARSET_AND_COLLATE.has(dialectName);

return this.sequelize.define(
this.modelName,
{
Expand All @@ -142,8 +150,8 @@ export class SequelizeStorage implements UmzugStorage {
tableName: this.tableName,
schema: this.schema,
timestamps: this.timestamps,
charset: 'utf8',
collate: 'utf8_unicode_ci',
charset: hasCharsetAndCollate ? 'utf8' : null,
collate: hasCharsetAndCollate ? 'utf8_unicode_ci' : null,
}
) as ModelClassType;
}
Expand Down

0 comments on commit 6c43202

Please sign in to comment.