Skip to content

Sequelize.ENUM does not support the substring COMMENT #9149

Closed

Description

@p-salmon

What are you doing?

I am creating a table with a column of type ENUM with a string containing the substring COMMENT.

const sequelize = new Sequelize();
sequelize.define('table', { column: Sequelize.ENUM(['COMMENT']) });
sequelize.sync({ force: true });

What do you expect to happen?

I want the sync to create a table named "table" with the column "column" with a type "enum_table_column" with the value "COMMENT".

What is actually happening?

The sync errors while creating the table. This error occurs for any string containing the substring COMMENT. It seems that Sequelize is interpreting the keyword COMMENT as the SQL COMMENT operator.

CREATE TABLE IF NOT EXISTS "contacts" ("id" SERIAL , "col" ENUM(', "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id")); COMMENT');

Dialect: postgres
Dialect version: 9.6.6
Sequelize version: 4.32.7
Tested with latest release: No

Activity

  1. hisorange commented on Mar 7, 2018

    @hisorange

    Define it like this:

    const sequelize = new Sequelize();
    sequelize.define('table', { column: Sequelize.ENUM('COMMENT', 'VALUE2') });
    sequelize.sync({ force: true });
    

    Based on this source

  2. p-salmon commented on Mar 7, 2018

    @p-salmon
    Author

    @hisorange Thank you for your response, unfortunately we have the same result using Sequelize.ENUM('COMMENT'), as well as Sequelize.ENUM('COMMENT', 'OTHER_VALUE').
    We've also tried using Sequelize.literal or Sequelize.cast, nothing do!

  3. hisorange commented on Mar 8, 2018

    @hisorange

    @poupouch Sorry! I was tired when found the issue and didn't read it well, ofc it will not solve your issue. But gona look into it, got curious now :D

  4. added
    type: bug
    on Apr 7, 2018
  5. dspigarelli commented on Jun 20, 2018

    @dspigarelli

    I believe the issue is this .indexOf('COMMENT') is too broad and catching non-comment strings:

    const i = attributes[attr].indexOf('COMMENT');
    if (i !== -1) {
    // Move comment to a separate query
    comments += '; ' + attributes[attr].substring(i);
    attributes[attr] = attributes[attr].substring(0, i);
    }

  6. mirkojotic commented on Jul 6, 2018

    @mirkojotic
    Contributor

    @poupouch
    I've tried to recreate this issue but I couldn't. This is the query that gets executed:

    DROP TYPE IF EXISTS "public"."enum_tables_column"; CREATE TYPE "public"."enum_tables_column" AS ENUM('COMMENT');
    
    CREATE TABLE IF NOT EXISTS "tables" ("id"   SERIAL , "column" "public"."enum_tables_column", "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
    

    Which makes sense because Postgres handles ENUM differently and in a separate query.

    I've used code you've provided
    Sequelize: latest
    Postgres: 10.4
    @sushantdhiman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions