1) Fixed an issue where refreshing the Schema Diff tool opened in a new tab caused an error. #7499

2) Fixed an issue where the Generate Script ignored filter conditions when a parent node was selected. #7682
This commit is contained in:
Akshay Joshi 2024-08-08 13:02:38 +05:30 committed by GitHub
parent f98e3fa1fd
commit 00e2480b7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 38 additions and 42 deletions

View File

@ -24,12 +24,16 @@ New features
Housekeeping Housekeeping
************ ************
| `Issue #7776 <https://github.com/pgadmin-org/pgadmin4/issues/7776>`_ - Introduce custom React Hook useSchemaState to simplify SchemaView component.
Bug fixes Bug fixes
********* *********
| `Issue #7499 <https://github.com/pgadmin-org/pgadmin4/issues/7499>`_ - Fixed an issue where refreshing the Schema Diff tool opened in a new tab caused an error.
| `Issue #7540 <https://github.com/pgadmin-org/pgadmin4/issues/7540>`_ - Fix server heartbeat logging error after deleting the server. | `Issue #7540 <https://github.com/pgadmin-org/pgadmin4/issues/7540>`_ - Fix server heartbeat logging error after deleting the server.
| `Issue #7682 <https://github.com/pgadmin-org/pgadmin4/issues/7682>`_ - Fixed an issue where the Generate Script ignored filter conditions when a parent node was selected.
| `Issue #7683 <https://github.com/pgadmin-org/pgadmin4/issues/7683>`_ - Fixed an issue where delete object(shortcut key) affecting both text and Object Explorer items. | `Issue #7683 <https://github.com/pgadmin-org/pgadmin4/issues/7683>`_ - Fixed an issue where delete object(shortcut key) affecting both text and Object Explorer items.
| `Issue #7728 <https://github.com/pgadmin-org/pgadmin4/issues/7728>`_ - Updated the documentation for web server authentication. | `Issue #7728 <https://github.com/pgadmin-org/pgadmin4/issues/7728>`_ - Updated the documentation for web server authentication.
| `Issue #7737 <https://github.com/pgadmin-org/pgadmin4/issues/7737>`_ - Fixed an issue where the REVOKE statement in the create script was throwing an error if the role contained special characters. | `Issue #7737 <https://github.com/pgadmin-org/pgadmin4/issues/7737>`_ - Fixed an issue where the REVOKE statement in the create script was throwing an error if the role contained special characters.
| `Issue #7754 <https://github.com/pgadmin-org/pgadmin4/issues/7754>`_ - Fix an issue where the wheel package is not getting installed on the arm64-based macOS version < 14.
| `Issue #7775 <https://github.com/pgadmin-org/pgadmin4/issues/7775>`_ - Fixed an issue where the value in the find box is not updating with selected text in editor if find is already open and re-triggered.

View File

@ -191,21 +191,17 @@ def update_session_diff_transaction(trans_id, session_obj, diff_model_obj):
@blueprint.route( @blueprint.route(
'/initialize', '/initialize/<int:trans_id>',
methods=["GET"], methods=["GET"],
endpoint="initialize" endpoint="initialize"
) )
@pga_login_required @pga_login_required
def initialize(): def initialize(trans_id):
""" """
This function will initialize the schema diff and return the list This function will initialize the schema diff and return the list
of all the server's. of all the server's.
""" """
trans_id = None
try: try:
# Create a unique id for the transaction
trans_id = str(secrets.choice(range(1, 9999999)))
if 'schemaDiff' not in session: if 'schemaDiff' not in session:
schema_diff_data = dict() schema_diff_data = dict()
else: else:
@ -213,7 +209,7 @@ def initialize():
# Use pickle to store the Schema Diff Model which will be used # Use pickle to store the Schema Diff Model which will be used
# later by the diff module. # later by the diff module.
schema_diff_data[trans_id] = { schema_diff_data[str(trans_id)] = {
'diff_model_obj': pickle.dumps(SchemaDiffModel(), -1) 'diff_model_obj': pickle.dumps(SchemaDiffModel(), -1)
} }
@ -223,8 +219,7 @@ def initialize():
except Exception as e: except Exception as e:
app.logger.exception(e) app.logger.exception(e)
return make_json_response( return make_json_response()
data={'schemaDiffTransId': trans_id})
@blueprint.route('/close/<int:trans_id>', @blueprint.route('/close/<int:trans_id>',

View File

@ -13,6 +13,7 @@ import ReactDOM from 'react-dom/client';
import gettext from 'sources/gettext'; import gettext from 'sources/gettext';
import url_for from 'sources/url_for'; import url_for from 'sources/url_for';
import pgWindow from 'sources/window'; import pgWindow from 'sources/window';
import * as commonUtils from 'sources/utils';
import getApiInstance from '../../../../static/js/api_instance'; import getApiInstance from '../../../../static/js/api_instance';
import Theme from '../../../../static/js/Theme'; import Theme from '../../../../static/js/Theme';
@ -50,7 +51,7 @@ export default class SchemaDiff {
name: 'schema_diff', name: 'schema_diff',
module: self, module: self,
applies: ['tools'], applies: ['tools'],
callback: 'showSchemaDiffTool', callback: 'launchSchemaDiff',
priority: 1, priority: 1,
label: gettext('Schema Diff'), label: gettext('Schema Diff'),
enable: true, enable: true,
@ -58,26 +59,9 @@ export default class SchemaDiff {
}]); }]);
} }
showSchemaDiffTool() { launchSchemaDiff() {
let self = this; let panelTitle = gettext('Schema Diff');
const trans_id = commonUtils.getRandomInt(1, 9999999);
self.api({
url: url_for('schema_diff.initialize', null),
method: 'GET',
})
.then(function (res) {
self.trans_id = res.data.data.schemaDiffTransId;
res.data.data.panel_title = gettext('Schema Diff');
self.launchSchemaDiff(res.data.data);
})
.catch(function (error) {
pgAdmin.Browser.notifier.error(gettext(`Error in schema diff initialize ${error.response.data}`));
});
}
launchSchemaDiff(data) {
let panelTitle = data.panel_title,
trans_id = data.schemaDiffTransId;
let url_params = { let url_params = {
'trans_id': trans_id, 'trans_id': trans_id,
@ -114,5 +98,4 @@ export default class SchemaDiff {
</Theme> </Theme>
); );
} }
} }

View File

@ -153,7 +153,7 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
}; };
const generateScript = () => { const generateScript = () => {
eventBus.fireEvent(SCHEMA_DIFF_EVENT.TRIGGER_GENERATE_SCRIPT, { sid: targetData.sid, did: targetData.did, selectedIds: selectedRowIds, rows: rows }); eventBus.fireEvent(SCHEMA_DIFF_EVENT.TRIGGER_GENERATE_SCRIPT, { sid: targetData.sid, did: targetData.did, selectedIds: selectedRowIds, rows: rows, selectedFilters: selectedFilters });
}; };
return ( return (

View File

@ -56,11 +56,11 @@ function checkAndGetSchemaQuery(data, script_array) {
} }
} }
function getGenerateScriptData(rows, selectedIds, script_array) { function getGenerateScriptData(rows, selectedIds, script_array, selectedFilters) {
for (let selRowVal of rows) { for (let selRowVal of rows) {
if (selectedIds.includes(`${selRowVal.id}`)) { if (selectedIds.includes(`${selRowVal.id}`)) {
let data = selRowVal; let data = selRowVal;
if (!_.isUndefined(data.diff_ddl)) { if (!_.isUndefined(data.diff_ddl) && selectedFilters.indexOf(data.status) > -1) {
if (!(data.dependLevel in script_array)) script_array[data.dependLevel] = []; if (!(data.dependLevel in script_array)) script_array[data.dependLevel] = [];
checkAndGetSchemaQuery(data, script_array); checkAndGetSchemaQuery(data, script_array);
script_array[data.dependLevel].push(data.diff_ddl); script_array[data.dependLevel].push(data.diff_ddl);
@ -314,7 +314,7 @@ export function SchemaDiffCompare({ params }) {
setFilterOptions(filterParams); setFilterOptions(filterParams);
}; };
const triggerGenerateScript = ({ sid, did, selectedIds, rows }) => { const triggerGenerateScript = ({ sid, did, selectedIds, rows, selectedFilters }) => {
setLoaderText(gettext('Generating script...')); setLoaderText(gettext('Generating script...'));
let generatedScript, scriptHeader; let generatedScript, scriptHeader;
@ -326,7 +326,7 @@ export function SchemaDiffCompare({ params }) {
if (selectedIds.length > 0) { if (selectedIds.length > 0) {
let script_array = { 1: [], 2: [], 3: [], 4: [], 5: [] }, let script_array = { 1: [], 2: [], 3: [], 4: [], 5: [] },
script_body = ''; script_body = '';
getGenerateScriptData(rows, selectedIds, script_array); getGenerateScriptData(rows, selectedIds, script_array, selectedFilters);
generatedScript = generateFinalScript(script_array, scriptHeader, script_body); generatedScript = generateFinalScript(script_array, scriptHeader, script_body);
openQueryTool({ sid: sid, did: did, generatedScript: generatedScript, scriptHeader: scriptHeader }); openQueryTool({ sid: sid, did: did, generatedScript: generatedScript, scriptHeader: scriptHeader });

View File

@ -8,15 +8,16 @@
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
import React, { createContext, useMemo, useRef } from 'react'; import React, { createContext, useMemo, useRef, useEffect } from 'react';
import { styled } from '@mui/material/styles'; import { styled } from '@mui/material/styles';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {DividerBox} from 'rc-dock'; import {DividerBox} from 'rc-dock';
import url_for from 'sources/url_for'; import url_for from 'sources/url_for';
import pgAdmin from 'sources/pgadmin';
import gettext from 'sources/gettext';
import { Box } from '@mui/material'; import { Box } from '@mui/material';
import { Results } from './Results'; import { Results } from './Results';
import { SchemaDiffCompare } from './SchemaDiffCompare'; import { SchemaDiffCompare } from './SchemaDiffCompare';
import EventBus from '../../../../../static/js/helpers/EventBus'; import EventBus from '../../../../../static/js/helpers/EventBus';
@ -64,6 +65,15 @@ export default function SchemaDiffComponent({params}) {
registerUnload(); registerUnload();
const initializeSchemaDiff = ()=>{
api.get(url_for('schema_diff.initialize', {
'trans_id': params.transId})
)
.catch((err) => {
pgAdmin.Browser.notifier.error(gettext(`Error in schema diff initialize ${err.response.data}`));
});
};
function registerUnload() { function registerUnload() {
window.addEventListener('unload', ()=>{ window.addEventListener('unload', ()=>{
/* Using fetch with keepalive as the browser may /* Using fetch with keepalive as the browser may
@ -82,6 +92,10 @@ export default function SchemaDiffComponent({params}) {
}); });
} }
useEffect(()=>{
initializeSchemaDiff();
}, []);
return ( return (
<SchemaDiffContext.Provider value={schemaDiffContextValue}> <SchemaDiffContext.Provider value={schemaDiffContextValue}>
<SchemaDiffEventsContext.Provider value={eventBus.current}> <SchemaDiffEventsContext.Provider value={eventBus.current}>

View File

@ -132,10 +132,10 @@ class SchemaDiffTestCase(BaseSocketTestGenerator):
def runTest(self): def runTest(self):
""" This function will test the schema diff.""" """ This function will test the schema diff."""
self.assertEqual(True, self.restored_backup) self.assertEqual(True, self.restored_backup)
response = self.tester.get("schema_diff/initialize") self.trans_id = str(secrets.choice(range(1, 99999)))
init_url = 'schema_diff/initialize/{}'.format(self.trans_id)
response = self.tester.get(init_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
response_data = json.loads(response.data.decode('utf-8'))
self.trans_id = response_data['data']['schemaDiffTransId']
received = self.socket_client.get_received(self.SOCKET_NAMESPACE) received = self.socket_client.get_received(self.SOCKET_NAMESPACE)
assert received[0]['name'] == 'connected' assert received[0]['name'] == 'connected'