public inbox for [email protected]
help / color / mirror / Atom feedFrom: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM6891] Composite foreign keys in ERD
Date: Wed, 13 Oct 2021 12:34:25 +0530
Message-ID: <CAM9w-_kRp5AirByDkR29H6Z5Prvf2n_VskPxigv-0SSwy-JjbA@mail.gmail.com> (raw)
Hi Hackers,
Please review the attached patch which adds support for composite foreign
keys in ERD.
--
Thanks,
Aditya Toshniwal
pgAdmin Hacker | Software Architect | *edbpostgres.com*
<http://edbpostgres.com;
"Don't Complain about Heat, Plant a TREE"
Attachments:
[application/octet-stream] RM6891.patch (4.2K, 3-RM6891.patch)
download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js
index 2dffa5f02..2bbca0d29 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui.js
@@ -256,7 +256,8 @@ export default class ForeignKeySchema extends BaseUISchema {
}
}
- let oldindex = 'fki_'+actionObj.oldState.name;
+ let oldFk = _.get(actionObj.oldState, _.slice(actionObj.path, 0, -1));
+ let oldindex = 'fki_'+oldFk.name;
if(state.hasindex) {
return {};
} else if(!state.autoindex) {
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js
index 5d8d1d039..a8e1b8cca 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui.js
@@ -352,6 +352,15 @@ export default class TableSchema extends BaseUISchema {
delete c.inheritedfromtable;
return c;
});
+
+ /* Make autoindex as true if there is coveringindex since ERD works in create mode */
+ newData.foreign_key = (newData.foreign_key||[]).map((fk)=>{
+ fk.autoindex = false;
+ if(fk.coveringindex) {
+ fk.autoindex = true;
+ }
+ return fk;
+ });
return newData;
}
diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/nodes/TableNode.jsx b/web/pgadmin/tools/erd/static/js/erd_tool/nodes/TableNode.jsx
index db2ff3050..fb43fa768 100644
--- a/web/pgadmin/tools/erd/static/js/erd_tool/nodes/TableNode.jsx
+++ b/web/pgadmin/tools/erd/static/js/erd_tool/nodes/TableNode.jsx
@@ -65,8 +65,9 @@ export class TableNodeModel extends DefaultNodeModel {
}
cloneData(name) {
+ const SKIP_CLONE_KEYS = ['foreign_key'];
let newData = {
- ...this.getData(),
+ ..._.pickBy(this.getData(), (_v, k)=>(SKIP_CLONE_KEYS.indexOf(k) == -1)),
};
if(name) {
newData['name'] = name;
@@ -148,12 +149,16 @@ export class TableNodeWidget extends React.Component {
});
}
- generateColumn(col) {
+ generateColumn(col, tableData) {
let port = this.props.node.getPort(this.props.node.getPortName(col.attnum));
let icon = ColumnIcon;
+ let localFkCols = [];
+ (tableData.foreign_key||[]).forEach((fk)=>{
+ localFkCols.push(...fk.columns.map((c)=>c.local_column));
+ });
if(col.is_primary_key) {
icon = PrimaryKeyIcon;
- } else if(port && port.getSubtype() == 'many') {
+ } else if(localFkCols.indexOf(col.name) > -1) {
icon = ForeignKeyIcon;
}
return (
@@ -186,7 +191,7 @@ export class TableNodeWidget extends React.Component {
}
render() {
- let node_data = this.props.node.getData();
+ let tableData = this.props.node.getData();
return (
<div className={'table-node ' + (this.props.node.isSelected() ? 'selected': '') } onDoubleClick={()=>{this.props.node.fireEvent({}, 'editTable');}}>
<div className="table-toolbar">
@@ -198,14 +203,14 @@ export class TableNodeWidget extends React.Component {
</div>
<div className="d-flex table-schema-data">
<RowIcon icon={SchemaIcon}/>
- <div className="table-schema my-auto">{node_data.schema}</div>
+ <div className="table-schema my-auto">{tableData.schema}</div>
</div>
<div className="d-flex table-name-data">
<RowIcon icon={TableIcon} />
- <div className="table-name my-auto">{node_data.name}</div>
+ <div className="table-name my-auto">{tableData.name}</div>
</div>
<div className="table-cols">
- {_.map(node_data.columns, (col)=>this.generateColumn(col))}
+ {_.map(tableData.columns, (col)=>this.generateColumn(col, tableData))}
</div>
</div>
);
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [pgAdmin][RM6891] Composite foreign keys in ERD
In-Reply-To: <CAM9w-_kRp5AirByDkR29H6Z5Prvf2n_VskPxigv-0SSwy-JjbA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox