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

removeConstraint always removes first constraint in sqlite #10380

Open
kebien6020 opened this issue Jan 23, 2019 · 0 comments
Open

removeConstraint always removes first constraint in sqlite #10380

kebien6020 opened this issue Jan 23, 2019 · 0 comments
Labels
dialect: sqlite For issues and PRs. Things that involve SQLite (and do not involve all dialects). type: bug

Comments

@kebien6020
Copy link

What are you doing?

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.removeConstraint('Clients', 'Clients_name_unique')
  },
  // ...
};

What do you expect to happen?

To go from this:

CREATE TABLE `Clients` (
  `id` INTEGER PRIMARY KEY,
  `name` VARCHAR(255) NOT NULL,
  CONSTRAINT `Clients_name_noempty` CHECK (`name` != ''),
  CONSTRAINT `Clients_name_unique` UNIQUE (`name`));

to this:

CREATE TABLE `Clients` (
  `id` INTEGER PRIMARY KEY,
  `name` VARCHAR(255) NOT NULL,
  CONSTRAINT `Clients_name_noempty` CHECK (`name` != ''));

What is actually happening?

Table ends up like this:

CREATE TABLE `Clients` (
  `id` INTEGER PRIMARY KEY,
  `name` VARCHAR(255) NOT NULL,
  CONSTRAINT `Clients_name_unique` UNIQUE (`name`));

Dialect: sqlite
Dialect version: sqlite3 - 4.0.4
Database version: SQLite 3.x database
Sequelize version: 4.42.0
Tested with latest release: Yes 4.42.0

Additional notes

Here in the code, showConstraints() returns the full sql of the table including all the constraints, even if the constraint name is passed.

They are then correctly parsed and returned as an array (all of them).

But the code here seems to assume that the constraints are filtered by constraint name and constraints[0] contains the first constraint matching the constraint name, when in fact all of them are returned in the order they appear in the CREATE TABLE sql.

@sushantdhiman sushantdhiman added type: bug dialect: sqlite For issues and PRs. Things that involve SQLite (and do not involve all dialects). investigate labels Jan 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect: sqlite For issues and PRs. Things that involve SQLite (and do not involve all dialects). type: bug
Projects
None yet
Development

No branches or pull requests

4 participants