Skip to content

Commit

Permalink
1) Fixed an issue where refreshing the Schema Diff tool opened in a n…
Browse files Browse the repository at this point in the history
…ew tab caused an error. pgadmin-org#7499

2) Fixed an issue where the Generate Script ignored filter conditions when a parent node was selected. pgadmin-org#7682

Fixed API Test Case.
  • Loading branch information
akshay-joshi committed Aug 8, 2024
1 parent f98e3fa commit f2a8909
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 42 deletions.
6 changes: 5 additions & 1 deletion docs/en_US/release_notes_8_11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ New features
Housekeeping
************

| `Issue #7776 <https://github.com/pgadmin-org/pgadmin4/issues/7776>`_ - Introduce custom React Hook useSchemaState to simplify SchemaView component.
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 #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 #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 #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.
13 changes: 4 additions & 9 deletions web/pgadmin/tools/schema_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,25 @@ def update_session_diff_transaction(trans_id, session_obj, diff_model_obj):


@blueprint.route(
'/initialize',
'/initialize/<int:trans_id>',
methods=["GET"],
endpoint="initialize"
)
@pga_login_required
def initialize():
def initialize(trans_id):
"""
This function will initialize the schema diff and return the list
of all the server's.
"""
trans_id = None
try:
# Create a unique id for the transaction
trans_id = str(secrets.choice(range(1, 9999999)))

if 'schemaDiff' not in session:
schema_diff_data = dict()
else:
schema_diff_data = session['schemaDiff']

# Use pickle to store the Schema Diff Model which will be used
# later by the diff module.
schema_diff_data[trans_id] = {
schema_diff_data[str(trans_id)] = {
'diff_model_obj': pickle.dumps(SchemaDiffModel(), -1)
}

Expand All @@ -223,8 +219,7 @@ def initialize():
except Exception as e:
app.logger.exception(e)

return make_json_response(
data={'schemaDiffTransId': trans_id})
return make_json_response()


@blueprint.route('/close/<int:trans_id>',
Expand Down
27 changes: 5 additions & 22 deletions web/pgadmin/tools/schema_diff/static/js/SchemaDiffModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ReactDOM from 'react-dom/client';
import gettext from 'sources/gettext';
import url_for from 'sources/url_for';
import pgWindow from 'sources/window';
import * as commonUtils from 'sources/utils';

import getApiInstance from '../../../../static/js/api_instance';
import Theme from '../../../../static/js/Theme';
Expand Down Expand Up @@ -50,34 +51,17 @@ export default class SchemaDiff {
name: 'schema_diff',
module: self,
applies: ['tools'],
callback: 'showSchemaDiffTool',
callback: 'launchSchemaDiff',
priority: 1,
label: gettext('Schema Diff'),
enable: true,
below: true,
}]);
}

showSchemaDiffTool() {
let self = this;

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;
launchSchemaDiff() {
let panelTitle = gettext('Schema Diff');
const trans_id = commonUtils.getRandomInt(1, 9999999);

let url_params = {
'trans_id': trans_id,
Expand Down Expand Up @@ -114,5 +98,4 @@ export default class SchemaDiff {
</Theme>
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
};

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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (selectedIds.includes(`${selRowVal.id}`)) {
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] = [];
checkAndGetSchemaQuery(data, script_array);
script_array[data.dependLevel].push(data.diff_ddl);
Expand Down Expand Up @@ -314,7 +314,7 @@ export function SchemaDiffCompare({ params }) {
setFilterOptions(filterParams);
};

const triggerGenerateScript = ({ sid, did, selectedIds, rows }) => {
const triggerGenerateScript = ({ sid, did, selectedIds, rows, selectedFilters }) => {
setLoaderText(gettext('Generating script...'));
let generatedScript, scriptHeader;

Expand All @@ -326,7 +326,7 @@ export function SchemaDiffCompare({ params }) {
if (selectedIds.length > 0) {
let script_array = { 1: [], 2: [], 3: [], 4: [], 5: [] },
script_body = '';
getGenerateScriptData(rows, selectedIds, script_array);
getGenerateScriptData(rows, selectedIds, script_array, selectedFilters);

generatedScript = generateFinalScript(script_array, scriptHeader, script_body);
openQueryTool({ sid: sid, did: did, generatedScript: generatedScript, scriptHeader: scriptHeader });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 PropTypes from 'prop-types';
import {DividerBox} from 'rc-dock';

import url_for from 'sources/url_for';
import pgAdmin from 'sources/pgadmin';
import gettext from 'sources/gettext';

import { Box } from '@mui/material';

import { Results } from './Results';
import { SchemaDiffCompare } from './SchemaDiffCompare';
import EventBus from '../../../../../static/js/helpers/EventBus';
Expand Down Expand Up @@ -64,6 +65,15 @@ export default function SchemaDiffComponent({params}) {

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() {
window.addEventListener('unload', ()=>{
/* Using fetch with keepalive as the browser may
Expand All @@ -82,6 +92,10 @@ export default function SchemaDiffComponent({params}) {
});
}

useEffect(()=>{
initializeSchemaDiff();
}, []);

return (
<SchemaDiffContext.Provider value={schemaDiffContextValue}>
<SchemaDiffEventsContext.Provider value={eventBus.current}>
Expand Down
6 changes: 3 additions & 3 deletions web/pgadmin/tools/schema_diff/tests/test_schema_diff_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def compare(self):
def runTest(self):
""" This function will test the schema diff."""
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)
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)
assert received[0]['name'] == 'connected'
Expand Down

0 comments on commit f2a8909

Please sign in to comment.