mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 07:46:00 +00:00
index column analysingh works for both postgres and cockroach
This commit is contained in:
@@ -66,6 +66,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
: null;
|
: null;
|
||||||
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
|
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
|
||||||
const indexes = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
const indexes = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||||
|
const indexcols = await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tables: tables.rows.map(table => {
|
tables: tables.rows.map(table => {
|
||||||
@@ -110,7 +111,14 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
.map(idx => ({
|
.map(idx => ({
|
||||||
constraintName: idx.index_name,
|
constraintName: idx.index_name,
|
||||||
isUnique: idx.is_unique,
|
isUnique: idx.is_unique,
|
||||||
columns: idx.column_names.split('|').map(columnName => ({ columnName })),
|
columns: _.compact(
|
||||||
|
idx.indkey
|
||||||
|
.split(' ')
|
||||||
|
.map(colid => indexcols.rows.find(col => col.oid == idx.oid && col.attnum == colid))
|
||||||
|
.map(col => ({
|
||||||
|
columnName: col.column_name,
|
||||||
|
}))
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const routines = require('./routines');
|
|||||||
const routineModifications = require('./routineModifications');
|
const routineModifications = require('./routineModifications');
|
||||||
const matviewColumns = require('./matviewColumns');
|
const matviewColumns = require('./matviewColumns');
|
||||||
const indexes = require('./indexes');
|
const indexes = require('./indexes');
|
||||||
|
const indexcols = require('./indexcols');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
columns,
|
columns,
|
||||||
@@ -26,4 +27,5 @@ module.exports = {
|
|||||||
matviewModifications,
|
matviewModifications,
|
||||||
matviewColumns,
|
matviewColumns,
|
||||||
indexes,
|
indexes,
|
||||||
|
indexcols,
|
||||||
};
|
};
|
||||||
|
|||||||
24
plugins/dbgate-plugin-postgres/src/backend/sql/indexcols.js
Normal file
24
plugins/dbgate-plugin-postgres/src/backend/sql/indexcols.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
module.exports = `
|
||||||
|
select
|
||||||
|
a.attname as "column_name",
|
||||||
|
a.attnum as "attnum",
|
||||||
|
a.attrelid as "oid"
|
||||||
|
from
|
||||||
|
pg_class t,
|
||||||
|
pg_class i,
|
||||||
|
pg_attribute a,
|
||||||
|
pg_index ix,
|
||||||
|
pg_namespace c
|
||||||
|
where
|
||||||
|
t.oid = ix.indrelid
|
||||||
|
and a.attnum = ANY(ix.indkey)
|
||||||
|
and a.attrelid = t.oid
|
||||||
|
and i.oid = ix.indexrelid
|
||||||
|
and t.relkind = 'r'
|
||||||
|
and ix.indisprimary = false
|
||||||
|
and t.relnamespace = c.oid
|
||||||
|
and c.nspname != 'pg_catalog'
|
||||||
|
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
|
||||||
|
order by
|
||||||
|
t.relname
|
||||||
|
`;
|
||||||
@@ -5,12 +5,8 @@ module.exports = `
|
|||||||
i.relname as "index_name",
|
i.relname as "index_name",
|
||||||
ix.indisprimary as "is_primary",
|
ix.indisprimary as "is_primary",
|
||||||
ix.indisunique as "is_unique",
|
ix.indisunique as "is_unique",
|
||||||
(
|
ix.indkey as "indkey",
|
||||||
select
|
t.oid as "oid"
|
||||||
array_to_string(array_agg((select a.attname from pg_attribute a where ord = a.attnum and a.attrelid = t.oid)), '|')
|
|
||||||
from
|
|
||||||
unnest(ix.indkey) ord
|
|
||||||
) as "column_names"
|
|
||||||
from
|
from
|
||||||
pg_class t,
|
pg_class t,
|
||||||
pg_class i,
|
pg_class i,
|
||||||
|
|||||||
Reference in New Issue
Block a user