From c9db4a0d16f90fb91c383fa097d40f313bc0c7b1 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Thu, 16 Nov 2023 16:55:26 +0530 Subject: [PATCH] Add DROP SQL for foreign keys in SQL generated by ERD when using WITH DROP option. #5770 --- docs/en_US/release_notes_7_9.rst | 2 + .../tables/constraints/foreign_key/utils.py | 15 ++++ .../servers/roles/static/js/role.ui.js | 8 -- .../server_groups/servers/static/js/server.js | 4 +- web/pgadmin/browser/static/js/node.js | 4 +- .../js/Theme/overrides/rcdock.override.js | 3 + web/pgadmin/static/js/utils.js | 32 ------- .../static/scss/_codemirror.overrides.scss | 17 +--- web/pgadmin/static/scss/_pgadmin.style.scss | 84 ------------------- web/pgadmin/tools/erd/__init__.py | 14 +++- .../static/scss/_user_management.scss | 4 - 11 files changed, 39 insertions(+), 148 deletions(-) diff --git a/docs/en_US/release_notes_7_9.rst b/docs/en_US/release_notes_7_9.rst index 3a89d57e1..3293c4131 100644 --- a/docs/en_US/release_notes_7_9.rst +++ b/docs/en_US/release_notes_7_9.rst @@ -34,6 +34,7 @@ Bug fixes ********* | `Issue #2986 `_ - Fix an issue where the scroll position of panels was not remembered on Firefox. + | `Issue #5770 `_ - Add DROP SQL for foreign keys in SQL generated by ERD when using WITH DROP option. | `Issue #5807 `_ - Fixed an issue where psql was not taking the role used to connect in server properties. | `Issue #6459 `_ - Fix the sorting of size on the statistics panel. | `Issue #6487 `_ - Fixed restoration of query tool database connection after dropping and re-creating the database with the same name. @@ -48,5 +49,6 @@ Bug fixes | `Issue #6877 `_ - Remove the max length of 255 from password exec command in server configuration dialog. | `Issue #6884 `_ - Remove gettext from empty strings in the title of the storage graph. | `Issue #6902 `_ - Fixed an issue where the change server password is not working in desktop mode. + | `Issue #6904 `_ - Fix a crash issue occurring when debugging a function with arguments when using pgAdmin with external config database. | `Issue #6920 `_ - Fix an issue in ERD tool where SQL generated is missing columns for the table. | `Issue #6934 `_ - Clear the password field in the config database on clear saved server password. diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/utils.py index 86213903f..04c059343 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/utils.py @@ -159,6 +159,21 @@ def get_parent(conn, tid, template_path=None): return schema, table +@get_template_path +def get_delete_sql(conn, fk_data, template_path=None): + """ + This function will generate sql from model data. + :param conn: Connection Object + :param data: data + :param template_path: Template Path + :return: + """ + return render_template("/".join( + [template_path, + 'delete.sql']), + data=fk_data, conn=conn).strip('\n') + + def _get_sql_for_delete_fk_constraint(data, constraint, sql, template_path, conn): """ diff --git a/web/pgadmin/browser/server_groups/servers/roles/static/js/role.ui.js b/web/pgadmin/browser/server_groups/servers/roles/static/js/role.ui.js index f4c1c9982..664bb2509 100644 --- a/web/pgadmin/browser/server_groups/servers/roles/static/js/role.ui.js +++ b/web/pgadmin/browser/server_groups/servers/roles/static/js/role.ui.js @@ -116,8 +116,6 @@ export default class RoleSchema extends BaseUISchema { { id: 'rolcanlogin', label: gettext('Can login?'), type: 'switch', - controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', - controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', group: gettext('Privileges'), disabled: obj.readOnly, }, @@ -134,8 +132,6 @@ export default class RoleSchema extends BaseUISchema { id: 'rolcreaterole', label: gettext('Create roles?'), group: gettext('Privileges'), type: 'switch', - controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', - controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', disabled: obj.readOnly, }, { @@ -160,16 +156,12 @@ export default class RoleSchema extends BaseUISchema { id: 'rolinherit', group: gettext('Privileges'), label: gettext('Inherit rights from the parent roles?'), type: 'switch', - controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', - controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', disabled: obj.readOnly, }, { id: 'rolreplication', group: gettext('Privileges'), label: gettext('Can initiate streaming replication and backups?'), type: 'switch', - controlLabelClassName: 'control-label pg-el-sm-4 pg-el-12', - controlsClassName: 'pgadmin-controls pg-el-sm-8 pg-el-12', min_version: 90100, disabled: obj.readOnly, }, diff --git a/web/pgadmin/browser/server_groups/servers/static/js/server.js b/web/pgadmin/browser/server_groups/servers/static/js/server.js index 8ce7b0904..0e7689d38 100644 --- a/web/pgadmin/browser/server_groups/servers/static/js/server.js +++ b/web/pgadmin/browser/server_groups/servers/static/js/server.js @@ -43,9 +43,9 @@ define('pgadmin.node.server', [ }, title: function(d, action) { if(action == 'create') { - return gettext('Register - %s', this.label); + return gettext('Register - %s', this._label); } - return d.label??''; + return d._label??''; }, Init: function() { /* Avoid multiple registration of same menus */ diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index d3b443313..31f34a0c4 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -90,9 +90,9 @@ define('pgadmin.browser.node', [ title: function(d, action) { if(action == 'create') { - return gettext('Create - %s', this.label); + return gettext('Create - %s', this._label); } - return d.label??''; + return d._label??''; }, hasId: true, /////// diff --git a/web/pgadmin/static/js/Theme/overrides/rcdock.override.js b/web/pgadmin/static/js/Theme/overrides/rcdock.override.js index 0a3844ef1..1bc594437 100644 --- a/web/pgadmin/static/js/Theme/overrides/rcdock.override.js +++ b/web/pgadmin/static/js/Theme/overrides/rcdock.override.js @@ -77,6 +77,9 @@ export default function rcdockOverride(theme) { color: theme.palette.text.primary, } }, + '& .dock-nav-more': { + display: 'none', + } }, '& .dock-tabpane': { backgroundColor: theme.palette.background.default, diff --git a/web/pgadmin/static/js/utils.js b/web/pgadmin/static/js/utils.js index d91361fe4..012754e88 100644 --- a/web/pgadmin/static/js/utils.js +++ b/web/pgadmin/static/js/utils.js @@ -24,38 +24,6 @@ export function parseShortcutValue(obj) { return shortcut; } -export function findAndSetFocus(container) { - if (container.length == 0) { - return; - } - setTimeout(function() { - let first_el = container - .find('button.fa-plus:first'); - - /* Adding the tabindex condition makes sure that - * when testing accessibility it works consistently across all - * browser. For eg, in safari focus() works only when element has - * tabindex="0", whereas in Chrome it works in any case - */ - - if (first_el.length == 0) { - first_el = container - .find(` - .pgadmin-controls:first .btn:not(.toggle), - .pgadmin-controls:first, - .ajs-commands:first, - .CodeMirror-scroll, - .pgadmin-wizard`) - .find('*[tabindex]:not([tabindex="-1"]),input:enabled'); - } - if(first_el.length > 0) { - first_el[0].focus(); - } else { - container[0].focus(); - } - }, 200); -} - export function getEpoch(inp_date) { let date_obj = inp_date ? inp_date : new Date(); return parseInt(date_obj.getTime()/1000); diff --git a/web/pgadmin/static/scss/_codemirror.overrides.scss b/web/pgadmin/static/scss/_codemirror.overrides.scss index ca119965d..d016a536a 100644 --- a/web/pgadmin/static/scss/_codemirror.overrides.scss +++ b/web/pgadmin/static/scss/_codemirror.overrides.scss @@ -18,21 +18,6 @@ min-height: 100% !important; } -/* - * Remove border right from "CodeMirror-gutters" - * class because its height doesn't increase - * with every new line added, instead add border - * right to ".CodeMirror-linenumber" class which - * adds a new div for every new line added - */ -.sql_field_layout .CodeMirror-gutters { - border-right: none; -} - -.sql_field_layout .CodeMirror-linenumber { - border-right: 1px solid $color-gray-lighter; -} - /* class to disable Codemirror editor */ .cm_disabled { background: $input-disabled-bg; @@ -100,6 +85,8 @@ .CodeMirror-linenumber { color: $color-fg; + font-size: 0.85em; + padding: 0; } .debugger-container .breakpoints { diff --git a/web/pgadmin/static/scss/_pgadmin.style.scss b/web/pgadmin/static/scss/_pgadmin.style.scss index 5ac6a2c89..4d295cec3 100644 --- a/web/pgadmin/static/scss/_pgadmin.style.scss +++ b/web/pgadmin/static/scss/_pgadmin.style.scss @@ -271,38 +271,6 @@ } } -.pgadmin-controls { - padding-right: 0px; - padding-left: 0px; -} - -.pgadmin-controls.SQL { - padding-right: 3px; - padding-left: 1px; - height: 100%; -} -.pgadmin-controls > textarea.form-control, -.pgadmin-controls > textarea.form-control:disabled { - min-width: 100%; - max-width: 100%; -} -.pgadmin-controls > div.checkbox, .pgadmin-controls > div.checkbox[disabled] { - height: 28px; -} - -.pgadmin-controls > .uneditable-input, .pgadmin-controls > .pgadmin-node-select, -.pgadmin-controls > input.form-control, .pgadmin-controls > select.form-control, -.pgadmin-controls > .uneditable-input:disabled, -.pgadmin-controls > .pgadmin-node-select:disabled, -.pgadmin-controls > input.form-control:disabled, -.pgadmin-controls > select.form-control:disabled { - min-height: 28px; -} - -.pgadmin-controls > span.select2 { - width: 100%; -} - fieldset.inline-fieldset { padding: 10px; border-radius: $card-border-radius; @@ -407,32 +375,6 @@ fieldset.inline-fieldset > div { } } -.pgadmin-controls input[type=checkbox]{ - margin-left: 0 !important; - margin-top: 10px !important; -} - -/* custom-control-label is used for checkbox */ -.pgadmin-controls .custom-control-label{ - margin-left: 0 !important; - margin-top: 5px !important; -} - -.pgadmin-controls.sql_field_layout { - margin: 0; - padding: 0; - overflow: hidden; - z-index: 1; -} - -.pgadmin-controls.focused, -.pgadmin-controls:focus { - border-color: $input-focus-border-color !important; - outline: 0; - -webkit-box-shadow: $input-focus-box-shadow; - box-shadow: $input-focus-box-shadow; -} - .dashboard-tab-container, .pg-panel-statistics-container, .pg-panel-dependencies-container, @@ -496,13 +438,6 @@ fieldset.inline-fieldset > div { .width_percent_99 { width: 99%; } .width_percent_100 { width: 100%; } - -.sql_field_layout { - border: $input-border-width solid $input-border-color !important; - border-radius: $input-border-radius; - padding: 0px; -} - .navtab-inline-controls { height: $title-height; @@ -894,25 +829,6 @@ table.table-empty-rows{ } } -.pgadmin-controls-radio-none { - & input[type="radio"] { - display: none; - } -} - -.backform-tab{ - & > .nav.nav-tabs { - position: absolute; - top: 0; - left: 0; - right: 0; - } - & > .tab-content { - position: absolute; - top: $title-height; - bottom: $footer-height-calc; - } -} .ajs-content { .tab-content { bottom: 0; diff --git a/web/pgadmin/tools/erd/__init__.py b/web/pgadmin/tools/erd/__init__.py index b044b1064..b1df04ff6 100644 --- a/web/pgadmin/tools/erd/__init__.py +++ b/web/pgadmin/tools/erd/__init__.py @@ -621,12 +621,24 @@ def sql(trans_id, sgid, sid, did): sql = '' tab_foreign_keys = [] all_nodes = data.get('nodes', {}) + + table_sql = '' for tab_key, tab_data in all_nodes.items(): tab_fks = tab_data.pop('foreign_key', []) tab_foreign_keys.extend(translate_foreign_keys(tab_fks, tab_data, all_nodes)) - sql += '\n\n' + helper.get_table_sql(tab_data, with_drop=with_drop) + table_sql += '\n\n' + helper.get_table_sql(tab_data, + with_drop=with_drop) + if with_drop: + for tab_fk in tab_foreign_keys: + fk_sql = fkey_utils.get_delete_sql(conn, tab_fk) + sql += '\n\n' + fk_sql + + if sql != '': + sql += '\n\n' + + sql += table_sql for tab_fk in tab_foreign_keys: fk_sql, name = fkey_utils.get_sql(conn, tab_fk, None) sql += '\n\n' + fk_sql diff --git a/web/pgadmin/tools/user_management/static/scss/_user_management.scss b/web/pgadmin/tools/user_management/static/scss/_user_management.scss index c45ea9bac..65c765b20 100644 --- a/web/pgadmin/tools/user_management/static/scss/_user_management.scss +++ b/web/pgadmin/tools/user_management/static/scss/_user_management.scss @@ -29,7 +29,3 @@ overflow: auto; border: 0 none; } - -.user_management .backform-tab { - height: calc(100% - 75px); -}