Skip to content

Case sensitive MS SQL database operations fail because of uppercase system table references #9336

@szabolcsmaj

Description

@szabolcsmaj

What are you doing?

I'm using the linux based MS SQL 2017 docker container (https://hub.docker.com/r/microsoft/mssql-server-linux/) for my MS SQL database. I set the collation for the whole database to Hungarian_CS_AS.

The following file is my first migration step:

00000000000000-set-db-collation.js:

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.sequelize.query(`alter database some_db collate Hungarian_CS_AS`)
  },

  down: (queryInterface, Sequelize) => {
  }
}

After this, a lot of very simple commands failed to execute.

What do you expect to happen?

One migration example:

20180420123144-remove-column.js

...
queryInterface.removeColumn('random_table', 'existing_column')
...

I expect it to ... remove the column.

What is actually happening?

It threw an error saying that SYS.DEFAULT_CONSTRAINTS cannot be found.

I double checked the DB to see and sys.default_constraints is there and can be queried as I wish.

What I found strange is that if I remove the collation setting, the migrations work just fine.

I eventually debugged sequelize and found that query-generator.js in the mssql dialect uses a few SYS views with uppercase letters. These will always fail if the database collation is set to case sensitive.

I prepared a pull request for it that fixes the error. I'll create it after this issue is created.

Dialect: mssql
Dialect version: Don't know where to look for that
Database version: MS SQL Server 2017 for Linux
Sequelize version: 4.31
Tested with latest release: Yes, 4.37

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