public inbox for [email protected]help / color / mirror / Atom feed
[pgAdmin][RM6891] Composite foreign keys in ERD 6+ messages / 2 participants [nested] [flat]
* [pgAdmin][RM6891] Composite foreign keys in ERD @ 2021-10-13 07:04 Aditya Toshniwal <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Aditya Toshniwal @ 2021-10-13 07:04 UTC (permalink / raw) To: pgadmin-hackers 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> ); ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [pgAdmin][RM6891] Composite foreign keys in ERD @ 2021-10-13 07:23 Akshay Joshi <[email protected]> parent: Aditya Toshniwal <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Akshay Joshi @ 2021-10-13 07:23 UTC (permalink / raw) To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers 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* ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [pgAdmin][RM6891] Composite foreign keys in ERD @ 2021-10-13 08:22 Aditya Toshniwal <[email protected]> parent: Akshay Joshi <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Aditya Toshniwal @ 2021-10-13 08:22 UTC (permalink / raw) To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers 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({ ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [pgAdmin][RM6891] Composite foreign keys in ERD @ 2021-10-13 08:59 Akshay Joshi <[email protected]> parent: Aditya Toshniwal <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Akshay Joshi @ 2021-10-13 08:59 UTC (permalink / raw) To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers Thanks, the patch applied. On Wed, Oct 13, 2021 at 1:53 PM Aditya Toshniwal < [email protected]> wrote: > 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" > -- *Thanks & Regards* *Akshay Joshi* *pgAdmin Hacker | Principal Software Architect* *EDB Postgres <http://edbpostgres.com>* *Mobile: +91 976-788-8246* ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [pgAdmin][RM6891] Composite foreign keys in ERD @ 2021-10-15 10:49 Aditya Toshniwal <[email protected]> parent: Akshay Joshi <[email protected]> 0 siblings, 1 reply; 6+ messages in thread From: Aditya Toshniwal @ 2021-10-15 10:49 UTC (permalink / raw) To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers Hi, The patch fixes the issue where all FKs are removed if one of the multiple FKs on the same column is removed. Please review. On Wed, Oct 13, 2021 at 2:30 PM Akshay Joshi <[email protected]> wrote: > Thanks, the patch applied. > > On Wed, Oct 13, 2021 at 1:53 PM Aditya Toshniwal < > [email protected]> wrote: > >> 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" >> > > > -- > *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.dropfk.patch (853B, 3-RM6891.dropfk.patch) download | inline diff: diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js index 60dbf4e34..39a60fa46 100644 --- a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js +++ b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js @@ -341,8 +341,8 @@ export default class ERDCore { tableData.foreign_key?.forEach((theFkRow)=>{ let theFk = theFkRow.columns[0]; let attnum = _.find(tableNode.getColumns(), (col)=>col.name==theFk.local_column).attnum; - /* Skip all those whose attnum matches to the link */ - if(linkData.local_column_attnum != attnum) { + /* Skip all those whose attnum and table matches to the link */ + if(linkData.local_column_attnum != attnum || linkData.referenced_table_uid != theFk.references) { newForeingKeys.push(theFkRow); } }); ^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: [pgAdmin][RM6891] Composite foreign keys in ERD @ 2021-10-16 07:29 Akshay Joshi <[email protected]> parent: Aditya Toshniwal <[email protected]> 0 siblings, 0 replies; 6+ messages in thread From: Akshay Joshi @ 2021-10-16 07:29 UTC (permalink / raw) To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers Thanks, the patch applied. On Fri, Oct 15, 2021 at 4:20 PM Aditya Toshniwal < [email protected]> wrote: > Hi, > > The patch fixes the issue where all FKs are removed if one of the multiple > FKs on the same column is removed. > Please review. > > On Wed, Oct 13, 2021 at 2:30 PM Akshay Joshi < > [email protected]> wrote: > >> Thanks, the patch applied. >> >> On Wed, Oct 13, 2021 at 1:53 PM Aditya Toshniwal < >> [email protected]> wrote: >> >>> 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" >>> >> >> >> -- >> *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" > -- *Thanks & Regards* *Akshay Joshi* *pgAdmin Hacker | Principal Software Architect* *EDB Postgres <http://edbpostgres.com>* *Mobile: +91 976-788-8246* ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2021-10-16 07:29 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-10-13 07:04 [pgAdmin][RM6891] Composite foreign keys in ERD Aditya Toshniwal <[email protected]> 2021-10-13 07:23 ` Akshay Joshi <[email protected]> 2021-10-13 08:22 ` Aditya Toshniwal <[email protected]> 2021-10-13 08:59 ` Akshay Joshi <[email protected]> 2021-10-15 10:49 ` Aditya Toshniwal <[email protected]> 2021-10-16 07:29 ` Akshay Joshi <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox