Issue with UDT when not in the default schema
Closed this issue · 4 comments
Schemalint started to break for us today. See stacktrace below :
$ npx schemalint@0.2.4
npx: installed 197 in 6.707s
schema-lint
Connecting to testingdb on localhost
error: select *, udt_name::regtype as regtype from "information_schema"."columns" where "table_schema" = $1 and "table_name" = $2 - type "custom_type" does not exist
at Connection.parseE (/Users/nathan.zender/.npm/_npx/36885/lib/node_modules/schemalint/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/Users/nathan.zender/.npm/_npx/36885/lib/node_modules/schemalint/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/Users/nathan.zender/.npm/_npx/36885/lib/node_modules/schemalint/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:223:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:181:23) {
name: 'error',
length: 97,
severity: 'ERROR',
code: '42704',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_type.c',
line: '814',
routine: 'parseTypeString'
}
I believe the issue has to do with the fact that we have a UDT that is not on the default schema. Here is a sql script that should help reproduce the issue.
CREATE database testingdb;
--\connect testingdb;
CREATE schema testing;
CREATE TYPE testing.CUSTOM_TYPE as ENUM ('BY_USER', 'BY_CENTER', 'BY_POLICY');
CREATE TABLE IF NOT EXISTS testing.table_using_custom_type (
id SERIAL,
name TEXT NOT NULL,
cust_type testing.CUSTOM_TYPE,
PRIMARY KEY (id),
CONSTRAINT type_safety UNIQUE (id, cust_type)
) with (OIDS = FALSE) TABLESPACE pg_default;
As well as a schemalint.js config file that should be setup like we are.
module.exports = {
connection: {
host: 'localhost',
user: 'postgres',
password: 'p0stgr3s',
database: 'testingdb',
charset: 'utf8',
port: 5432
},
plugins:[],
rules: {
'name-casing': ['error', 'snake'],
'prefer-jsonb-to-json': ['error'],
'prefer-text-to-varchar': ['error'],
},
schemas: [
{
name: 'testing',
}
]
};
From digging around a bit I believe the query needs to be tweaked a little to also append the udt_schema like seen in this issue here.
typeorm/typeorm#1997
and the corresponding PR to fix it
typeorm/typeorm#2746
Thank you and sorry about that! I will look into this later today.
no worries...i have a PR almost ready to fix it so hopefully you can look at that later today :)
@kristiandupont #5 should fix this. Also added some tests and created an issue #6 to start to run those in CI. Let me know if you have any thoughts or issues with that PR.
#5 has been merged and i have validated the fix.