Open knixeur opened 1 year ago
@knixeur were you able to work around this?
Mmm probably not, IIRC I did a work around to prevent that and moved on
Edit: And here is the workaround :)
db.public.interceptQueries((queryText) => {
if (queryText.search(/(pg_views|pg_matviews|pg_tables|pg_enum)/g) > -1) {
return [];
}
if (
queryText.includes("DO 'BEGIN CREATE TYPE") &&
queryText.includes('AS ENUM') &&
queryText.includes(" EXCEPTION WHEN duplicate_object THEN null; END';")
) {
db.public.none(
queryText
.replace(
/DROP TYPE IF EXISTS (.+); DO 'BEGIN CREATE TYPE (.+) AS ENUM\((.+)\); EXCEPTION WHEN duplicate_object THEN null; END';/,
'DROP TYPE IF EXISTS $1; CREATE TYPE $2 AS ENUM($3)',
)
.replace(/''/g, "'"),
);
return [];
}
return null;
});
Not my proudest production but I needed to move on :)
thank you for sharing @knixeur, I needed some small modifications as mine don't have the initial DROP TYPE IF EXISTS
but then it worked smoothly:
pgMemDb.public.interceptQueries((queryText) => {
if (queryText.search(/(pg_views|pg_matviews|pg_tables|pg_enum)/g) > -1) {
return []
}
if (
queryText.includes("DO 'BEGIN CREATE TYPE") &&
queryText.includes("AS ENUM") &&
queryText.includes(" EXCEPTION WHEN duplicate_object THEN null; END';")
) {
pgMemDb.public.none(
queryText
.replace(
/DO 'BEGIN CREATE TYPE (.+) AS ENUM\((.+)\); EXCEPTION WHEN duplicate_object THEN null; END';/,
'CREATE TYPE $1 AS ENUM($2);',
)
.replace(/''/g, "'")
)
return []
}
Describe the bug
A syntax error is thrown while running a create type migration.
To Reproduce
pg-mem version
2.6.12
Others
This started happening after this PR was merged into sequelize
Relevant commit:
Thanks for pg-mem and let me know if you need more info.