mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added the ability to generate ERDs for tables. #4756
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user