fix analyser for cockroach

This commit is contained in:
Jan Prochazka
2021-05-16 11:43:19 +02:00
parent c95677bd83
commit 3a08462018
2 changed files with 19 additions and 3 deletions

View File

@@ -162,9 +162,25 @@ const drivers = driverBases.map(driverBase => ({
async getVersion(client) { async getVersion(client) {
const { rows } = await this.query(client, 'SELECT version()'); const { rows } = await this.query(client, 'SELECT version()');
const { version } = rows[0]; const { version } = rows[0];
const isCockroach = version.toLowerCase().includes('cockroachdb');
const isRedshift = version.toLowerCase().includes('redshift');
const isPostgres = !isCockroach && !isRedshift;
const m = version.match(/([\d\.]+)/);
let versionText = null;
if (m) {
if (isCockroach) versionText = `CockroachDB ${m[1]}`;
if (isRedshift) versionText = `Redshift ${m[1]}`;
if (isPostgres) versionText = `PostgreSQL ${m[1]}`;
}
return { return {
version, version,
versionText: (version || '').replace(/\s*\(.*$/, ''), versionText,
isPostgres,
isCockroach,
isRedshift,
}; };
}, },
async readQuery(client, sql, structure) { async readQuery(client, sql, structure) {

View File

@@ -2,8 +2,8 @@ module.exports = `
select infoTables.table_schema as "schema_name", infoTables.table_name as "pure_name", select infoTables.table_schema as "schema_name", infoTables.table_name as "pure_name",
( (
select md5(string_agg( select md5(string_agg(
infoColumns.column_name || '|' || infoColumns.data_type || '|' || infoColumns.is_nullable || '|' || coalesce(infoColumns.character_maximum_length, -1) infoColumns.column_name || '|' || infoColumns.data_type || '|' || infoColumns.is_nullable::varchar(255) || '|' || coalesce(infoColumns.character_maximum_length, -1)::varchar(255)
|| '|' || coalesce(infoColumns.numeric_precision, -1), || '|' || coalesce(infoColumns.numeric_precision, -1)::varchar(255) ,
',' order by infoColumns.ordinal_position ',' order by infoColumns.ordinal_position
)) as "hash_code_columns" )) as "hash_code_columns"
from information_schema.columns infoColumns from information_schema.columns infoColumns