1) Improve wording for script header while generating the script using the schema diff tool.

2) Fixed an issue where closing the query tool panel throws an error.
3) Fixed schema diff close panel issue.
This commit is contained in:
Akshay Joshi 2020-02-03 12:38:02 +05:30
parent 96b0d85189
commit 0d77bc305e
4 changed files with 67 additions and 33 deletions

View File

@ -386,15 +386,15 @@ def close(trans_id):
Args:
trans_id: unique transaction id
"""
if 'gridData' not in session:
return make_json_response(data={'status': True})
grid_data = session['gridData']
# Return from the function if transaction id not found
if str(trans_id) not in grid_data:
return make_json_response(data={'status': True})
with query_tool_close_session_lock:
if 'gridData' not in session:
return make_json_response(data={'status': True})
grid_data = session['gridData']
# Return from the function if transaction id not found
if str(trans_id) not in grid_data:
return make_json_response(data={'status': True})
try:
close_query_tool_session(trans_id)
# Remove the information of unique transaction id from the
@ -458,20 +458,20 @@ def close_query_tool_session(trans_id):
:param trans_id: Transaction id
:return:
"""
if 'gridData' in session and str(trans_id) in session['gridData']:
cmd_obj_str = session['gridData'][str(trans_id)]['command_obj']
# Use pickle.loads function to get the command object
cmd_obj = pickle.loads(cmd_obj_str)
cmd_obj_str = session['gridData'][str(trans_id)]['command_obj']
# Use pickle.loads function to get the command object
cmd_obj = pickle.loads(cmd_obj_str)
# if connection id is None then no need to release the connection
if cmd_obj.conn_id is not None:
manager = get_driver(
PG_DEFAULT_DRIVER).connection_manager(cmd_obj.sid)
if manager is not None:
conn = manager.connection(
did=cmd_obj.did, conn_id=cmd_obj.conn_id)
# if connection id is None then no need to release the connection
if cmd_obj.conn_id is not None:
manager = get_driver(
PG_DEFAULT_DRIVER).connection_manager(cmd_obj.sid)
if manager is not None:
conn = manager.connection(
did=cmd_obj.did, conn_id=cmd_obj.conn_id)
# Release the connection
if conn.connected():
conn.cancel_transaction(cmd_obj.conn_id, cmd_obj.did)
manager.release(did=cmd_obj.did, conn_id=cmd_obj.conn_id)
# Release the connection
if conn.connected():
conn.cancel_transaction(cmd_obj.conn_id, cmd_obj.did)
manager.release(did=cmd_obj.did, conn_id=cmd_obj.conn_id)

View File

@ -21,7 +21,7 @@ from flask_security import current_user, login_required
from flask_babelex import gettext
from pgadmin.utils import PgAdminModule
from pgadmin.utils.ajax import make_json_response, bad_request, \
make_response as ajax_response, not_implemented
make_response as ajax_response, not_implemented, internal_server_error
from pgadmin.model import Server
from pgadmin.tools.schema_diff.node_registry import SchemaDiffRegistry
from pgadmin.tools.schema_diff.model import SchemaDiffModel
@ -68,7 +68,8 @@ class SchemaDiffModule(PgAdminModule):
'schema_diff.connect_server',
'schema_diff.connect_database',
'schema_diff.get_server',
'schema_diff.generate_script'
'schema_diff.generate_script',
'schema_diff.close'
]
def register_preferences(self):
@ -216,6 +217,37 @@ def initialize():
data={'schemaDiffTransId': trans_id})
@blueprint.route('/close/<int:trans_id>',
methods=["DELETE"],
endpoint='close')
def close(trans_id):
"""
Remove the session details for the particular transaction id.
Args:
trans_id: unique transaction id
"""
if 'schemaDiff' not in session:
return make_json_response(data={'status': True})
schema_diff_data = session['schemaDiff']
# Return from the function if transaction id not found
if str(trans_id) not in schema_diff_data:
return make_json_response(data={'status': True})
try:
# Remove the information of unique transaction id from the
# session variable.
schema_diff_data.pop(str(trans_id), None)
session['schemaDiff'] = schema_diff_data
except Exception as e:
app.logger.error(e)
return internal_server_error(errormsg=str(e))
return make_json_response(data={'status': True})
@blueprint.route(
'/servers',
methods=["GET"],

View File

@ -24,7 +24,7 @@ define([
load: function(trans_id) {
window.onbeforeunload = function() {
$.ajax({
url: url_for('schemadiff.index') + 'close/'+trans_id,
url: url_for('schema_diff.close', {'trans_id': trans_id}),
method: 'DELETE',
});
};

View File

@ -200,7 +200,13 @@ export default class SchemaDiffUI {
sel_rows_data = [],
url_params = self.selection,
generated_script = undefined,
open_query_tool;
open_query_tool,
script_header;
script_header = gettext('-- This script was generated by a beta version of the Schema Diff utility in pgAdmin 4. \n');
script_header += gettext('-- This version does not include dependency resolution, and may require manual changes \n');
script_header += gettext('-- to the script to ensure changes are applied in the correct order.\n');
script_header += gettext('-- Please report an issue for any failure with the reproduction steps. \n');
_.each(url_params, function(key, val) {
url_params[key] = parseInt(val, 10);
@ -230,11 +236,7 @@ export default class SchemaDiffUI {
server_data['database'] = data.database;
if (_.isUndefined(generated_script)) {
generated_script = gettext('-- This script is generated by \'Schema Diff\' utility of pgAdmin 4. \n');
generated_script += gettext('-- It does not include the dependency resolution logic, hence - it may not be able to resolve some dependent database object differences. \n');
generated_script += gettext('-- Please report an issue for any failure with the reproduction steps. \n');
generated_script += 'BEGIN;' + '\n' + self.model.get('diff_ddl') + '\n' + 'END;';
generated_script = script_header + 'BEGIN;' + '\n' + self.model.get('diff_ddl') + '\n' + 'END;';
}
let preferences = pgWindow.pgAdmin.Browser.get_preferences_for_module('schema_diff');
@ -290,7 +292,7 @@ export default class SchemaDiffUI {
})
.done(function (res) {
if (res) {
generated_script = 'BEGIN;' + '\n' + res.diff_ddl + '\n' + 'END;';
generated_script = script_header + 'BEGIN;' + '\n' + res.diff_ddl + '\n' + 'END;';
}
open_query_tool();
})