postgres fix on finding indexes when multiple constraints
This commit is contained in:
parent
f7e7cdd649
commit
7ebc0450b6
@ -31,13 +31,13 @@ export abstract class AbstractDriver {
|
||||
v => v.EntityName == relations[0].relatedTable
|
||||
)[0];
|
||||
relatedTable1.Columns = relatedTable1.Columns.filter(
|
||||
v => v.name != entity.EntityName
|
||||
v => v.name.toLowerCase() != entity.EntityName.toLowerCase()
|
||||
);
|
||||
let relatedTable2 = dbModel.entities.filter(
|
||||
v => v.EntityName == relations[1].relatedTable
|
||||
)[0];
|
||||
relatedTable2.Columns = relatedTable2.Columns.filter(
|
||||
v => v.name != entity.EntityName
|
||||
v => v.name.toLowerCase() != entity.EntityName.toLowerCase()
|
||||
);
|
||||
dbModel.entities = dbModel.entities.filter(ent => {
|
||||
return ent.EntityName != entity.EntityName;
|
||||
|
@ -214,33 +214,31 @@ export class PostgresDriver extends AbstractDriver {
|
||||
is_unique: number;
|
||||
is_primary_key: number; //, is_descending_key: number//, is_included_column: number
|
||||
}[] = (await this.Connection.query(`SELECT
|
||||
c.relname AS tablename,
|
||||
i.relname as indexname,
|
||||
f.attname AS columnname,
|
||||
CASE
|
||||
WHEN ix.indisunique = true THEN '1'
|
||||
ELSE '0'
|
||||
END AS is_unique,
|
||||
CASE
|
||||
WHEN p.contype = 'p' THEN '1'
|
||||
ELSE '0'
|
||||
END AS is_primary_key
|
||||
FROM pg_attribute f
|
||||
JOIN pg_class c ON c.oid = f.attrelid
|
||||
JOIN pg_type t ON t.oid = f.atttypid
|
||||
LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
|
||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
|
||||
LEFT JOIN pg_class AS g ON p.confrelid = g.oid
|
||||
LEFT JOIN pg_index AS ix ON f.attnum = ANY(ix.indkey) and c.oid = f.attrelid and c.oid = ix.indrelid
|
||||
LEFT JOIN pg_class AS i ON ix.indexrelid = i.oid
|
||||
c.relname AS tablename,
|
||||
i.relname as indexname,
|
||||
f.attname AS columnname,
|
||||
CASE
|
||||
WHEN ix.indisunique = true THEN '1'
|
||||
ELSE '0'
|
||||
END AS is_unique,
|
||||
CASE
|
||||
WHEN ix.indisprimary='true' THEN '1'
|
||||
ELSE '0'
|
||||
END AS is_primary_key
|
||||
FROM pg_attribute f
|
||||
JOIN pg_class c ON c.oid = f.attrelid
|
||||
JOIN pg_type t ON t.oid = f.atttypid
|
||||
LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
|
||||
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
LEFT JOIN pg_index AS ix ON f.attnum = ANY(ix.indkey) and c.oid = f.attrelid and c.oid = ix.indrelid
|
||||
LEFT JOIN pg_class AS i ON ix.indexrelid = i.oid
|
||||
|
||||
WHERE c.relkind = 'r'::char
|
||||
AND n.nspname in (${schema})
|
||||
--AND c.relname = 'nodes' -- Replace with table name, or Comment this for get all tables
|
||||
AND f.attnum > 0
|
||||
AND i.oid<>0
|
||||
ORDER BY c.relname,f.attname;`)).rows;
|
||||
WHERE c.relkind = 'r'::char
|
||||
AND n.nspname in (${schema})
|
||||
--AND c.relname = 'nodes' -- Replace with table name, or Comment this for get all tables
|
||||
AND f.attnum > 0
|
||||
AND i.oid<>0
|
||||
ORDER BY c.relname,f.attname;`)).rows;
|
||||
entities.forEach(ent => {
|
||||
response
|
||||
.filter(filterVal => {
|
||||
|
Loading…
Reference in New Issue
Block a user