question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

queryInterface.removeColumn doesn't drop enum type (Postgres)

See original GitHub issue

What are you doing?

I have the a migration that removes a column with an ENUM type. Reverting the migration fails because Sequelize didn’t drop the enum type, and reversion fails when it tries to recreate the already-existing type.

Maybe this is intended behavior, but I would think that removeColumn should always clean up everything that addColumn or sync created.

// @flow

import type SequelizeClass, {QueryInterface} from 'sequelize'

const Channels = 'Channels'

module.exports = {
  async up(queryInterface: QueryInterface, Sequelize: Class<SequelizeClass>): Promise<void> {
    await queryInterface.removeColumn(Channels, 'mode')
  },
  async down(queryInterface: QueryInterface, Sequelize: Class<SequelizeClass>): Promise<void> {
    await queryInterface.addColumn(Channels, 'mode', {
      type: Sequelize.ENUM('ANALOG_INPUT', 'DIGITAL_INPUT', 'DIGITAL_OUTPUT', 'DISABLED'),
      allowNull: false,
      defaultValue: 'DISABLED',
    })
  },
}

What do you expect to happen?

The down method succeeds after up has been performed

What is actually happening?

down results in the following error:

SequelizeDatabaseError: type "enum_Channels_mode" already exists

Dialect: postgres Dialect version: 6.4.2 Database version: 10 Sequelize version: 4.29.2 Tested with latest release: Yes (If yes, specify that version)

Note : Your issue may be ignored OR closed by maintainers if it’s not tested against latest version OR does not follow issue template.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jedwards1211commented, Jan 11, 2018

@sushantdhiman did you guys assume that Postgres can’t handle that properly? Looks like it can: https://www.postgresql.org/docs/8.2/static/sql-droptype.html

DROP TYPE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

RESTRICT Refuse to drop the type if any objects depend on it. This is the default.

0reactions
sushantdhimancommented, Jan 20, 2018

Actually this is a duplicate of long standing issue https://github.com/sequelize/sequelize/issues/2554

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sequelize removeColumn method doesn't remove enum types
module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.addColumn('Results', 'mid_term_type', Sequelize.ENUM(['first' ...
Read more >
Remove enums in Sequelize / Postgres down migrations
If you are adding a new enum in your migrations, you may want to manually drop the type in your down() migration. This...
Read more >
Sequelize removeColumn method doesn't remove enum types ...
Coding example for the question Sequelize removeColumn method doesn't remove enum types-postgresql.
Read more >
PostgresQueryInterface - Sequelize
Since postgres has a special case for enums, we should drop the related enum type within the table and attribute. public.
Read more >
Dealing with Enum Type in PostgreSQL - DEV Community ‍ ‍
Enum type is best solution to describe state data. ... Other than that, PostgreSQL doesn't support changing or deleting specific enum value.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found