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

queryInterface.renameColumn drop unique constraint in SQLite #11243

Open
1 of 7 tasks
eugene-matvejev opened this issue Jul 29, 2019 · 4 comments
Open
1 of 7 tasks

queryInterface.renameColumn drop unique constraint in SQLite #11243

eugene-matvejev opened this issue Jul 29, 2019 · 4 comments
Labels
dialect: sqlite For issues and PRs. Things that involve SQLite (and do not involve all dialects). status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action type: bug

Comments

@eugene-matvejev
Copy link

eugene-matvejev commented Jul 29, 2019

What are you doing?

demo:
https://github.com/eugene-matvejev/node-explorer/pull/10/files

# file 1
'use strict';
module.exports = {
    up: (queryInterface, Sequelize) => {
        return queryInterface.createTable('statuses', {
            id: {
                // type: DataTypes.UUID,
                type: Sequelize.INTEGER,
                primaryKey: true,
                autoIncrement: true,
            },
            name: {
                type: Sequelize.STRING,
                unique: true,
            },
            state: {
                type: Sequelize.INTEGER,
                allowNull: false,
                defaultValue: 0,
            },
            parent: {
                type: Sequelize.INTEGER
            },
        });
    },
    down: (queryInterface, Sequelize) => {
        return queryInterface.dropTable('statuses');
    }
};


# file 2
'use strict';

module.exports = {
    up: (queryInterface, Sequelize) => {
        return queryInterface.renameColumn('statuses', 'state', 'seq');
    },
    down: (queryInterface, Sequelize) => {
        return queryInterface.renameColumn('statuses', 'seq', 'state');
    }
};

To Reproduce
1 run migration in file 1 correct output

sqlite> .schema statuses
CREATE TABLE `statuses` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255) UNIQUE, `seq` INTEGER NOT NULL DEFAULT 0, `parent` INTEGER);

2 run migration in file 2, 'UNIQUE' constrain gone from name column

sqlite> .schema statuses
CREATE TABLE `statuses` (`id` INTEGER PRIMARY KEY, `name` VARCHAR(255), `parent` INTEGER, `seq` INTEGER NOT NULL DEFAULT '0');

What do you expect to happen?

state column to be renamed to seq, other columns shouldn't be affected

What is actually happening?

'UNIQUE' constrain gone from name column

see example above

Environment

Dialect:

  • mysql
  • postgres
  • sqlite
  • mssql
  • any

Sequelize CLI [Node: 10.16.0, CLI: 5.5.0, ORM: 5.10.1]
Dialect library version: 5.10.1
Database version: 4.0.9
Sequelize version: 5.5.0
Node Version: 10.16.0
OS: MacOs
If TypeScript related: TypeScript version: n/a
Tested with latest release:

  • No
  • Yes, specify that version:
@eugene-matvejev
Copy link
Author

very bad work around who is interested: https://github.com/eugene-matvejev/node-explorer/pull/12/files

@papb
Copy link
Member

papb commented Jul 29, 2019

Can you please test this with another dialect? This is important to know whether the problem is dialect-specific or not.

You can instantiate a local postgres instance very easily:

  1. Run a local postgres
    • On windows: PostgreSQLPortable_10.4.1.zip (no need to install, just unzip and run)
      • Run the .exe and then CREATE DATABASE testdb; (don't close the .exe)
    • On linux (with docker): docker pull postgres && docker run --rm --name pg -d -p 5432:5432 postgres
      • Run docker exec -t pg psql -U postgres -c 'CREATE DATABASE testdb;'
  2. new Sequelize('postgres://postgres@localhost:5432/testdb')

@papb papb added dialect: sqlite For issues and PRs. Things that involve SQLite (and do not involve all dialects). status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action type: bug labels Jul 29, 2019
@gilmrjc
Copy link

gilmrjc commented Mar 4, 2020

I can confirm this only happens on SQLite.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 8, 2021
@WikiRik WikiRik removed the stale label Nov 15, 2021
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). status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action type: bug
Projects
None yet
Development

No branches or pull requests

4 participants