Skip to content

Incorrect charset collate ordering #40

@confuser

Description

@confuser

According to MySQL documentation, COLLATE must appear after CHARACTER SET https://dev.mysql.com/doc/refman/8.0/en/charset-table.html

Currently this module has it the other way around. This means when attempting to specify a collation and character set like so:

await db.createTable('test_table', {
    columns: {
      id: { type: 'int', notNull: true, primaryKey: true, autoIncrement: true },
    },
    charset: 'utf8mb4',
    collate: 'utf8mb4_unicode_ci'
  })

The following SQL is generated:

CREATE TABLE  `test_table` (`id` INTEGER  PRIMARY KEY AUTO_INCREMENT NOT NULL) COLLATE 'utf8mb4_unicode_ci' CHARACTER SET utf8mb4

This results in the correct utf8mb4 character set, but with a collation set to the default schema utf8mb4_general_ci not utf8mb4_unicode_ci

Correct SQL generated:

CREATE TABLE  `test_table` (`id` INTEGER  PRIMARY KEY AUTO_INCREMENT NOT NULL) CHARACTER SET utf8mb4 COLLATE 'utf8mb4_unicode_ci'

@wzrdtales would you be open to a PR to resolve this? Looks like spec.collate and spec.charset need swapping in _applyTableOptions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions