npm ci
npm run success # successful case
npm run fail # failed caseI am not sure is this problem with sequelize-typescript or sequelize, so please correct me.
Syntax error when trying to add enum column with comment that ends with bracket ")".
Other type (tested with DataType.TEXT) works as expected, without problems.
- sequelize: 6.37.1
- sequelize-typescript: 2.1.6
- typescript: 5.3.3
- pg: 8.11.3
- bug report
- feature request
For example (code in below section) sequelize creates this SQL (prettified):
DO
'BEGIN
CREATE TYPE "public"."enum_Model_status" AS ENUM(''active'', ''pending'', ''available'', ''inactive'', ''suspended'');
EXCEPTION WHEN duplicate_object THEN null;
END';
ALTER TABLE "public"."Model" ADD COLUMN "status" "public"."enum_Model_status"'; <--- Here is unnecessary single quote
And at the end you can see syntax error with unnecessary one single quote, between status" and ;
Error: unterminated quoted string at or near "';"
- Successfully creates column with comment with brackets
- Initialize sequelize, add one model
- Using queryInterface add
enumcolumn with any comment that ends with symbol) - You will get syntax error like mentioned above.
Link to small reproducable repo: https://github.com/Mauzzz0/sequelize-comment-brackets-error
With two files: case_fail.ts, case_success.ts
export enum StatusEnum {
active = 'active',
pending = 'pending',
available = 'available',
inactive = 'inactive',
suspended = 'suspended',
}
const qi = sequelize.getQueryInterface();Failed example:
await qi.addColumn(ModelEntity.tableName, 'status',
{
type: DataType.ENUM,
allowNull: false,
values: Object.values(StatusEnum),
defaultValue: StatusEnum.available,
comment: 'Comment ends with brackets)',
}, { transaction });Successfull example:
await qi.addColumn(ModelEntity.tableName, 'status',
{
type: DataType.ENUM,
allowNull: false,
values: Object.values(StatusEnum),
defaultValue: StatusEnum.available,
comment: 'Normal comment',
}, { transaction });