public inbox for [email protected]
help / color / mirror / Atom feedFrom: Aditya Toshniwal <[email protected]>
To: Akshay Joshi <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin][RM6891] Composite foreign keys in ERD
Date: Wed, 13 Oct 2021 13:52:30 +0530
Message-ID: <CAM9w-_mdmX4PHva+-4rhVH6Km4UUw5G6n4shGBKhX7xV1cweOQ@mail.gmail.com> (raw)
In-Reply-To: <CANxoLDfFFt1XcKWA62cYEExkHZHQzu5ymuDUwZhJQtZrVGV5Sg@mail.gmail.com>
References: <CAM9w-_kRp5AirByDkR29H6Z5Prvf2n_VskPxigv-0SSwy-JjbA@mail.gmail.com>
<CANxoLDfFFt1XcKWA62cYEExkHZHQzu5ymuDUwZhJQtZrVGV5Sg@mail.gmail.com>
Hi,
Attached is the updated patch.
On Wed, Oct 13, 2021 at 12:53 PM Akshay Joshi <[email protected]>
wrote:
> Hi Aditya
>
> Jasmine test cases are failing after applying the patch. Can you please
> fix and resend it.
>
> On Wed, Oct 13, 2021 at 12:35 PM Aditya Toshniwal <
> [email protected]> wrote:
>
>> 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"
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>
--
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_v2.patch (5.1K, 3-RM6891_v2.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..4aae23bdb 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,13 @@ export default class ForeignKeySchema extends BaseUISchema {
}
}
- let oldindex = 'fki_'+actionObj.oldState.name;
+ let oldindex;
+ if(obj.inTable) {
+ let oldFk = _.get(actionObj.oldState, _.slice(actionObj.path, 0, -1));
+ oldindex = 'fki_'+oldFk.name;
+ } else {
+ oldindex = 'fki_'+actionObj.oldState.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>
);
diff --git a/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js b/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js
index 7b7288eaa..d841bb3d2 100644
--- a/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js
+++ b/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js
@@ -170,9 +170,13 @@ describe('ForeignKeySchema', ()=>{
it('depChange', ()=>{
let state = {columns: [{local_column: 'id'}]};
- let actionObj = {oldState:{name: 'fkname'}};
+ let actionObj = {
+ path: ['name'],
+ oldState: {
+ name: 'fkname',
+ }
+ };
- schemaObj.nodeInfo = {foreign_key: {}};
state.autoindex = true;
state.name = 'fkname';
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
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], [email protected]
Subject: Re: [pgAdmin][RM6891] Composite foreign keys in ERD
In-Reply-To: <CAM9w-_mdmX4PHva+-4rhVH6Km4UUw5G6n4shGBKhX7xV1cweOQ@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