Repository navigation
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
The change in query-generator.js in commit 6d9a58e7 by @aristov caused enum to stop working when using the "PostgreSQL-compatible" CockroachDB.
The change in the commit is replacing CREATE TYPE ${enumName} AS ${values}; with DO ${this.escape(``BEGIN CREATE TYPE ${enumName} AS ${values}; EXCEPTION WHEN duplicate_object THEN null; END``)};
This fails in CockroachDB because the DO syntax is not supported. Here's a dump from the tests of the sequelize-cockroachdb project:
2) QueryInterface
createTable
enums
should work with enums (1):
at or near "do": syntax error
Error
at Query.run (node_modules/sequelize/lib/dialects/postgres/query.js:50:25)
at /app/node_modules/sequelize/lib/sequelize.js:315:28
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /app/node_modules/sequelize/lib/dialects/postgres/query-interface.js:117:76
at async PostgresQueryInterface.ensureEnums (node_modules/sequelize/lib/dialects/postgres/query-interface.js:117:20)
at async PostgresQueryInterface.createTable (node_modules/sequelize/lib/dialects/abstract/query-interface.js:85:5)
at async Context.<anonymous> (tests/create-table_test.js:118:9)
I understand that the purpose of this commit was to not fail on CREATE TYPE if the type already exists. The syntax that was used is valid in PostgreSQL DB. However, on CockroachDB which should be "PostgreSQL compatible", this syntax is not supported. They use a much simpler syntax: CREATE TYPE IF NOT EXISTS ....
I know that sequelize-cockroachdb is an independent project that is not related to you, the core Sequelize team, but maybe there's a better way to get the requested behavior of this change without breaking the support of CockroachDB.
My point here is to let you know that this change breaks something elsewhere. I think this is something you prefer to be aware of.
I also created an issue in sequelize-cockroachdb project.
Reproducible Example
See this test of sequelize-cockroachdb project.
What do you expect to happen?
Tests of the sequelize-cockroachdb project should succeed with no exception regarding the unsupported do command.
What is actually happening?
Enum tests of the sequelize-cockroachdb project are failing because of the do command. See this CI output (once GitHub Actions will run) and see the stack trace above.
Environment
- Sequelize version: 6.32.1
- Node.js version: 20.3.1
- If TypeScript related: TypeScript version:
- Database & Version: cockroachdb/cockroach:v21.2.4
- Connector library & Version: pg (node-postgres) 8.11.1
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
Activity
[-]Commit 6d9a58e7 has broke the enum support in CockroachDB[/-][+]Commit 6d9a58e7 broke the enum support in CockroachDB[/+]ephys commentedon Jun 27, 2023
That is very unfortunate. As you mentioned,
sequelize-cockroachdbis not maintained by us and the postgres dialect is designed for postgres onlyThere is a pull request to incorporate cockroachdb as its own dialect in Sequelize, which would solve this sort of problems, but it has been inactive for a little while: #15569
Postgres does not support
CREATE TYPE IF NOT EXISTS, but the CockroachDB implementation can easily extend the PostgresQueryGenerator class to replace the relevant method and make it use that syntax insteadgithub-actions commentedon Jul 12, 2023
This bug report has not been verified by maintainers yet, and has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, consider commenting with more information to help us verify it.
WikiRik commentedon Jul 19, 2023
This is something that needs to be fixed in the CockroachDB implementation, which is a separate project for v6 and there is a PR in progress for v7. Therefore I'll close this issue here