Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide charset and collate options only for dialects supporting them #624

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading