Added the ability to generate ERDs for tables. #4756

This commit is contained in:
Aditya Toshniwal
2022-11-09 11:36:04 +05:30
committed by GitHub
parent beb43c69dc
commit af32e3c296
13 changed files with 136 additions and 12 deletions

View File

@@ -121,7 +121,11 @@ define('pgadmin.node.table', [
applies: ['object', 'context'], callback: 'count_table_rows',
category: 'Count', priority: 2, label: gettext('Count Rows'),
enable: true,
},
},{
name: 'generate_erd', node: 'table', module: this,
applies: ['object', 'context'], callback: 'generate_erd',
category: 'erd', priority: 5, label: gettext('ERD For Table'),
}
]);
pgBrowser.Events.on(
'pgadmin:browser:node:table:updated', this.onTableUpdated, this
@@ -289,6 +293,14 @@ define('pgadmin.node.table', [
t.unload(i);
});
},
/* Generate the ERD */
generate_erd: function(args) {
let input = args || {},
t = pgBrowser.tree,
i = input.item || t.selected(),
d = i ? t.itemData(i) : undefined;
pgAdmin.Tools.ERD.showErdTool(d, i, true);
},
},
getSchema: function(treeNodeInfo, itemNodeData) {
return getNodeTableSchema(treeNodeInfo, itemNodeData, pgBrowser);

View File

@@ -13,6 +13,7 @@ SELECT ct.oid,
confrelid,
nl.nspname as fknsp,
cl.relname as fktab,
nr.oid as refnspoid,
nr.nspname as refnsp,
cr.relname as reftab,
description as comment,

View File

@@ -0,0 +1,10 @@
SELECT
co.conrelid as confrelid, co.conname, nl.oid as refnspoid
FROM pg_catalog.pg_depend dep
JOIN pg_catalog.pg_constraint co ON dep.objid=co.oid
JOIN pg_catalog.pg_class cl ON cl.oid=co.conrelid
JOIN pg_catalog.pg_namespace nl ON nl.oid=cl.relnamespace
WHERE dep.refobjid={{oid}}::OID
AND deptype = 'n'

View File

@@ -395,6 +395,22 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
status=200
)
def get_fk_ref_tables(self, tid):
"""
This function get the depending tables of the current table.
The tables depending on tid table using FK relation.
Args:
tid: Table ID
"""
sql = render_template("/".join([self.table_template_path,
'fk_ref_tables.sql']), oid=tid)
status, res = self.conn.execute_dict(sql)
if not status:
return status, res
return status, res['rows']
def get_table_statistics(self, scid, tid):
"""
Statistics

View File

@@ -98,7 +98,7 @@ define('pgadmin.node.database', [
},{
name: 'generate_erd', node: 'database', module: this,
applies: ['object', 'context'], callback: 'generate_erd',
category: 'erd', priority: 5, label: gettext('Generate ERD'),
category: 'erd', priority: 5, label: gettext('ERD For Database'),
enable: (node) => {
return node.allowConn;
}