Skip to content

PostgreSQL INTERVAL column generates invalid default value in model definition #680

@pfortuna

Description

@pfortuna

When generating models from a PostgreSQL database that includes a column of type INTERVAL, the generated Sequelize model contains invalid code — both in the type and in the defaultValue fields.

Example:

CREATE TABLE some_table (
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL,
    waittime INTERVAL DEFAULT INTERVAL '60 seconds',
);

The last column will result in:

        waittime: {
            type: DataTypes.INTEGER,
            allowNull: true,
            defaultValue: 00:01:00
        }

Where 00:01:00 should be '60 seconds' instead.
It throws a syntax error and you have to correct it by hand.

These are the parameters i'm using:

sequelize-auto \
  -h "$DB_HOST" \
  -d "$POSTGRES_DB" \
  -u "$POSTGRES_USER" \
  -x "$POSTGRES_PASSWORD" \
  -p "$DB_PORT" \
  --dialect postgres \
  --directory /models \
  --noInit \
  --additional /usr/src/app/additional.json

additional.json

{
    "timestamps": true,
    "underscored": true,
    "createdAt": "created_at",
    "updatedAt": "updated_at"
}

Is this a known bug or limitation?
Any workaround?

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