You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Syntax error when trying to add enum column with comment that ends with bracket ")". Unterminated quoted string. #17118
I 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.
Versions
sequelize: 6.37.1
sequelize-typescript: 2.1.6
typescript: 5.3.3
pg: 8.11.3
Issue type
bug report
feature request
Actual behavior
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 "';"
Expected behavior
Successfully creates column with comment with brackets
Steps to reproduce
Initialize sequelize, add one model
Using queryInterface add enum column with any comment that ends with symbol )
The issue is that the enum is passed there including the comment. It will now take the last closing bracket and replace the part in between with the enum name. It should stop before it encounters a comment.
It is also present in the v7-alphas, so it would be better to fix it there first and backport it to v6.
Activity
WikiRik commentedon Feb 23, 2024
This is an issue with sequelize itself (and not sequelize-typescript where it was first opened). In v6 this is the line that causes the issue;
sequelize/src/dialects/postgres/query-generator.js
Line 848 in 505467b
The issue is that the enum is passed there including the comment. It will now take the last closing bracket and replace the part in between with the enum name. It should stop before it encounters a comment.
It is also present in the v7-alphas, so it would be better to fix it there first and backport it to v6.
WikiRik commentedon Feb 23, 2024
Looking into it more it seems that
createTableQueryhas a workaround for this;sequelize/src/dialects/postgres/query-generator.js
Lines 82 to 94 in 505467b
Something similar could be done for
addColumnQueryandchangeColumnQueryfix(postgres): keep column comments out of addColumn type definitions
fix(postgres): keep column comments out of addColumn type definitions