mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure that the 'CREATE SCHEMA' statement should be present in the generated script if the schema is not present in the target database. Fixes #5816
This commit is contained in:
parent
ed1bd74301
commit
a7d40e238e
@ -41,4 +41,5 @@ Bug fixes
|
|||||||
| `Issue #5779 <https://redmine.postgresql.org/issues/5779>`_ - Remove illegal argument from trigger function in trigger DDL statement.
|
| `Issue #5779 <https://redmine.postgresql.org/issues/5779>`_ - Remove illegal argument from trigger function in trigger DDL statement.
|
||||||
| `Issue #5794 <https://redmine.postgresql.org/issues/5794>`_ - Fixed excessive CPU usage by stopping the indefinite growth of the graph dataset.
|
| `Issue #5794 <https://redmine.postgresql.org/issues/5794>`_ - Fixed excessive CPU usage by stopping the indefinite growth of the graph dataset.
|
||||||
| `Issue #5815 <https://redmine.postgresql.org/issues/5815>`_ - Fixed an issue where clicking on the 'Generate script' button shows a forever spinner due to pop up blocker.
|
| `Issue #5815 <https://redmine.postgresql.org/issues/5815>`_ - Fixed an issue where clicking on the 'Generate script' button shows a forever spinner due to pop up blocker.
|
||||||
|
| `Issue #5816 <https://redmine.postgresql.org/issues/5816>`_ - Ensure that the 'CREATE SCHEMA' statement should be present in the generated script if the schema is not present in the target database.
|
||||||
| `Issue #5820 <https://redmine.postgresql.org/issues/5820>`_ - Fixed an issue while refreshing Resource Group.
|
| `Issue #5820 <https://redmine.postgresql.org/issues/5820>`_ - Fixed an issue while refreshing Resource Group.
|
@ -53,6 +53,7 @@ class SchemaDiffTableCompare(SchemaDiffObjectCompare):
|
|||||||
|
|
||||||
group_name = kwargs.get('group_name')
|
group_name = kwargs.get('group_name')
|
||||||
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
||||||
|
source_schema_name = kwargs.get('source_schema_name', None)
|
||||||
source_tables = {}
|
source_tables = {}
|
||||||
target_tables = {}
|
target_tables = {}
|
||||||
|
|
||||||
@ -76,7 +77,8 @@ class SchemaDiffTableCompare(SchemaDiffObjectCompare):
|
|||||||
node_label=self.blueprint.collection_label,
|
node_label=self.blueprint.collection_label,
|
||||||
group_name=group_name,
|
group_name=group_name,
|
||||||
ignore_whitespaces=ignore_whitespaces,
|
ignore_whitespaces=ignore_whitespaces,
|
||||||
ignore_keys=self.keys_to_ignore)
|
ignore_keys=self.keys_to_ignore,
|
||||||
|
source_schema_name=source_schema_name)
|
||||||
|
|
||||||
def ddl_compare(self, **kwargs):
|
def ddl_compare(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -464,8 +464,10 @@ def compare(trans_id, source_sid, source_did, target_sid, target_did):
|
|||||||
schema_result['target_only']) + len(
|
schema_result['target_only']) + len(
|
||||||
schema_result['in_both_database'])
|
schema_result['in_both_database'])
|
||||||
|
|
||||||
node_percent = round(100 / (total_schema * len(
|
node_percent = 0
|
||||||
SchemaDiffRegistry.get_registered_nodes())))
|
if total_schema > 0:
|
||||||
|
node_percent = round(100 / (total_schema * len(
|
||||||
|
SchemaDiffRegistry.get_registered_nodes())))
|
||||||
total_percent = 0
|
total_percent = 0
|
||||||
|
|
||||||
# Compare Database objects
|
# Compare Database objects
|
||||||
@ -494,7 +496,8 @@ def compare(trans_id, source_sid, source_did, target_sid, target_did):
|
|||||||
diff_model_obj=diff_model_obj,
|
diff_model_obj=diff_model_obj,
|
||||||
total_percent=total_percent,
|
total_percent=total_percent,
|
||||||
node_percent=node_percent,
|
node_percent=node_percent,
|
||||||
ignore_whitespaces=ignore_whitespaces)
|
ignore_whitespaces=ignore_whitespaces,
|
||||||
|
is_schema_source_only=True)
|
||||||
|
|
||||||
comparison_result = \
|
comparison_result = \
|
||||||
comparison_result + comparison_schema_result
|
comparison_result + comparison_schema_result
|
||||||
@ -741,6 +744,12 @@ def compare_schema_objects(**kwargs):
|
|||||||
total_percent = kwargs.get('total_percent')
|
total_percent = kwargs.get('total_percent')
|
||||||
node_percent = kwargs.get('node_percent')
|
node_percent = kwargs.get('node_percent')
|
||||||
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
||||||
|
is_schema_source_only = kwargs.get('is_schema_source_only', False)
|
||||||
|
source_schema_name = None
|
||||||
|
if is_schema_source_only:
|
||||||
|
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||||
|
source_schema_name = driver.qtIdent(None, schema_name)
|
||||||
|
|
||||||
comparison_result = []
|
comparison_result = []
|
||||||
|
|
||||||
all_registered_nodes = SchemaDiffRegistry.get_registered_nodes()
|
all_registered_nodes = SchemaDiffRegistry.get_registered_nodes()
|
||||||
@ -762,7 +771,8 @@ def compare_schema_objects(**kwargs):
|
|||||||
target_did=target_did,
|
target_did=target_did,
|
||||||
target_scid=target_scid,
|
target_scid=target_scid,
|
||||||
group_name=gettext(schema_name),
|
group_name=gettext(schema_name),
|
||||||
ignore_whitespaces=ignore_whitespaces)
|
ignore_whitespaces=ignore_whitespaces,
|
||||||
|
source_schema_name=source_schema_name)
|
||||||
|
|
||||||
if res is not None:
|
if res is not None:
|
||||||
comparison_result = comparison_result + res
|
comparison_result = comparison_result + res
|
||||||
|
@ -61,6 +61,7 @@ class SchemaDiffObjectCompare:
|
|||||||
|
|
||||||
group_name = kwargs.get('group_name')
|
group_name = kwargs.get('group_name')
|
||||||
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
||||||
|
source_schema_name = kwargs.get('source_schema_name', None)
|
||||||
source = {}
|
source = {}
|
||||||
target = {}
|
target = {}
|
||||||
|
|
||||||
@ -91,7 +92,8 @@ class SchemaDiffObjectCompare:
|
|||||||
node_label=self.blueprint.collection_label,
|
node_label=self.blueprint.collection_label,
|
||||||
group_name=group_name,
|
group_name=group_name,
|
||||||
ignore_whitespaces=ignore_whitespaces,
|
ignore_whitespaces=ignore_whitespaces,
|
||||||
ignore_keys=self.keys_to_ignore)
|
ignore_keys=self.keys_to_ignore,
|
||||||
|
source_schema_name=source_schema_name)
|
||||||
|
|
||||||
def ddl_compare(self, **kwargs):
|
def ddl_compare(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -20,19 +20,21 @@ list_keys_array = ['name', 'colname', 'argid', 'token', 'option', 'conname',
|
|||||||
'fsrvoption', 'umoption']
|
'fsrvoption', 'umoption']
|
||||||
|
|
||||||
|
|
||||||
def _get_source_list(added, source_dict, node, source_params, view_object,
|
def _get_source_list(**kwargs):
|
||||||
node_label, group_name):
|
|
||||||
"""
|
"""
|
||||||
Get only source list.
|
Get only source list.
|
||||||
:param added: added dict list.
|
:param kwargs
|
||||||
:param source_dict: source dict.
|
|
||||||
:param node: node type.
|
|
||||||
:param source_params: source parameters.
|
|
||||||
:param view_object: view object for get sql.
|
|
||||||
:param node_label: node label.
|
|
||||||
:param group_name: group name
|
|
||||||
:return: list of source dict.
|
:return: list of source dict.
|
||||||
"""
|
"""
|
||||||
|
added = kwargs.get('added')
|
||||||
|
source_dict = kwargs.get('source_dict')
|
||||||
|
node = kwargs.get('node')
|
||||||
|
source_params = kwargs.get('source_params')
|
||||||
|
view_object = kwargs.get('view_object')
|
||||||
|
node_label = kwargs.get('node_label')
|
||||||
|
group_name = kwargs.get('group_name')
|
||||||
|
source_schema_name = kwargs.get('source_schema_name')
|
||||||
|
|
||||||
global count
|
global count
|
||||||
source_only = []
|
source_only = []
|
||||||
for item in added:
|
for item in added:
|
||||||
@ -77,7 +79,8 @@ def _get_source_list(added, source_dict, node, source_params, view_object,
|
|||||||
'target_ddl': '',
|
'target_ddl': '',
|
||||||
'diff_ddl': diff_ddl,
|
'diff_ddl': diff_ddl,
|
||||||
'group_name': group_name,
|
'group_name': group_name,
|
||||||
'dependencies': source_dependencies
|
'dependencies': source_dependencies,
|
||||||
|
'source_schema_name': source_schema_name
|
||||||
})
|
})
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
@ -220,9 +223,8 @@ def _get_identical_and_different_list(intersect_keys, source_dict, target_dict,
|
|||||||
target_params = kwargs['target_params']
|
target_params = kwargs['target_params']
|
||||||
group_name = kwargs['group_name']
|
group_name = kwargs['group_name']
|
||||||
for key in intersect_keys:
|
for key in intersect_keys:
|
||||||
source_object_id, target_object_id = get_source_target_oid(source_dict,
|
source_object_id, target_object_id = \
|
||||||
target_dict,
|
get_source_target_oid(source_dict, target_dict, key)
|
||||||
key)
|
|
||||||
|
|
||||||
# Recursively Compare the two dictionary
|
# Recursively Compare the two dictionary
|
||||||
if are_dictionaries_identical(dict1[key], dict2[key],
|
if are_dictionaries_identical(dict1[key], dict2[key],
|
||||||
@ -337,6 +339,7 @@ def compare_dictionaries(**kwargs):
|
|||||||
node_label = kwargs.get('node_label')
|
node_label = kwargs.get('node_label')
|
||||||
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
ignore_whitespaces = kwargs.get('ignore_whitespaces')
|
||||||
ignore_keys = kwargs.get('ignore_keys', None)
|
ignore_keys = kwargs.get('ignore_keys', None)
|
||||||
|
source_schema_name = kwargs.get('source_schema_name')
|
||||||
|
|
||||||
dict1 = copy.deepcopy(source_dict)
|
dict1 = copy.deepcopy(source_dict)
|
||||||
dict2 = copy.deepcopy(target_dict)
|
dict2 = copy.deepcopy(target_dict)
|
||||||
@ -352,8 +355,13 @@ def compare_dictionaries(**kwargs):
|
|||||||
# Keys that are available in source and missing in target.
|
# Keys that are available in source and missing in target.
|
||||||
|
|
||||||
added = dict1_keys - dict2_keys
|
added = dict1_keys - dict2_keys
|
||||||
source_only = _get_source_list(added, source_dict, node, source_params,
|
|
||||||
view_object, node_label, group_name)
|
source_only = _get_source_list(added=added, source_dict=source_dict,
|
||||||
|
node=node, source_params=source_params,
|
||||||
|
view_object=view_object,
|
||||||
|
node_label=node_label,
|
||||||
|
group_name=group_name,
|
||||||
|
source_schema_name=source_schema_name)
|
||||||
|
|
||||||
target_only = []
|
target_only = []
|
||||||
# Keys that are available in target and missing in source.
|
# Keys that are available in target and missing in source.
|
||||||
|
@ -260,6 +260,15 @@ export default class SchemaDiffUI {
|
|||||||
let data = self.grid.getData().getItem(sel_rows[row]);
|
let data = self.grid.getData().getItem(sel_rows[row]);
|
||||||
if(!_.isUndefined(data.diff_ddl)) {
|
if(!_.isUndefined(data.diff_ddl)) {
|
||||||
if (!(data.dependLevel in script_array)) script_array[data.dependLevel] = [];
|
if (!(data.dependLevel in script_array)) script_array[data.dependLevel] = [];
|
||||||
|
// Check whether the selected object belongs to source only schema
|
||||||
|
// if yes then we will have to add create schema statement before
|
||||||
|
// creating any other object.
|
||||||
|
if (!_.isUndefined(data.source_schema_name) && !_.isNull(data.source_schema_name)) {
|
||||||
|
let schema_query = '\nCREATE SCHEMA IF NOT EXISTS ' + data.source_schema_name + ';\n';
|
||||||
|
if (script_array[data.dependLevel].indexOf(schema_query) == -1) {
|
||||||
|
script_array[data.dependLevel].push(schema_query);
|
||||||
|
}
|
||||||
|
}
|
||||||
script_array[data.dependLevel].push(data.diff_ddl);
|
script_array[data.dependLevel].push(data.diff_ddl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
import {getTreeNodeHierarchyFromIdentifier} from 'sources/tree/pgadmin_tree_node';
|
import {launchDataGrid} from 'tools/datagrid/static/js/show_query_tool';
|
||||||
import {showQueryTool} from 'tools/datagrid/static/js/show_query_tool';
|
|
||||||
|
|
||||||
define('tools.querytool', [
|
define('tools.querytool', [
|
||||||
'sources/gettext', 'sources/url_for', 'jquery', 'jquery.ui',
|
'sources/gettext', 'sources/url_for', 'jquery', 'jquery.ui',
|
||||||
@ -2071,34 +2070,6 @@ define('tools.querytool', [
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var set_tree_node = function() {
|
|
||||||
|
|
||||||
let browser = pgWindow.default.pgAdmin.Browser;
|
|
||||||
let tree = browser.tree;
|
|
||||||
|
|
||||||
var t = tree,
|
|
||||||
i = t.selected(),
|
|
||||||
d = i && i.length == 1 ? t.itemData(i) : undefined;
|
|
||||||
|
|
||||||
if(!d)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const parentData = getTreeNodeHierarchyFromIdentifier.call(pgWindow.default.pgAdmin.Browser, i);
|
|
||||||
|
|
||||||
if(!parentData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let conn_param = parentData.database || parentData.server;
|
|
||||||
|
|
||||||
var selected_tree_node = { t, i, d };
|
|
||||||
|
|
||||||
if(!pgWindow.default.pgAdmin.selected_tree_map)
|
|
||||||
pgWindow.default.pgAdmin.selected_tree_map = new Map();
|
|
||||||
|
|
||||||
pgWindow.default.pgAdmin.selected_tree_map.set(conn_param._id.toString(), selected_tree_node);
|
|
||||||
};
|
|
||||||
|
|
||||||
_.extend(
|
_.extend(
|
||||||
SqlEditorController.prototype,
|
SqlEditorController.prototype,
|
||||||
Backbone.Events,
|
Backbone.Events,
|
||||||
@ -2111,7 +2082,6 @@ define('tools.querytool', [
|
|||||||
|
|
||||||
//call to check whether user have closed the parent window and trying to refresh, if yes return error.
|
//call to check whether user have closed the parent window and trying to refresh, if yes return error.
|
||||||
is_main_window_alive();
|
is_main_window_alive();
|
||||||
set_tree_node();
|
|
||||||
|
|
||||||
// Disable animation first
|
// Disable animation first
|
||||||
modifyAnimation.modifyAlertifyAnimation();
|
modifyAnimation.modifyAlertifyAnimation();
|
||||||
@ -4318,16 +4288,27 @@ define('tools.querytool', [
|
|||||||
_show_query_tool: function() {
|
_show_query_tool: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var tree_node = pgWindow.default.pgAdmin.selected_tree_map.get(self.url_params.did || self.url_params.sid);
|
|
||||||
if(self.preferences.new_browser_tab) {
|
if(self.preferences.new_browser_tab) {
|
||||||
is_main_window_alive();
|
is_main_window_alive();
|
||||||
}
|
}
|
||||||
this._open_query_tool(tree_node);
|
this._open_query_tool(self);
|
||||||
},
|
},
|
||||||
|
|
||||||
_open_query_tool: function(tree_node) {
|
_open_query_tool: function(that) {
|
||||||
|
|
||||||
const transId = pgadminUtils.getRandomInt(1, 9999999);
|
const transId = pgadminUtils.getRandomInt(1, 9999999);
|
||||||
showQueryTool(pgWindow.default.pgAdmin.DataGrid, pgWindow.default.pgAdmin.Browser, alertify, '', tree_node.i, transId);
|
|
||||||
|
let url_endpoint = url_for('datagrid.panel', {
|
||||||
|
'trans_id': transId,
|
||||||
|
});
|
||||||
|
|
||||||
|
url_endpoint += `?is_query_tool=${that.url_params.is_query_tool}`
|
||||||
|
+`&sgid=${that.url_params.sgid}`
|
||||||
|
+`&sid=${that.url_params.sid}`
|
||||||
|
+`&server_type=${that.url_params.server_type}`
|
||||||
|
+`&did=${that.url_params.did}`;
|
||||||
|
|
||||||
|
launchDataGrid(pgWindow.default.pgAdmin.DataGrid, transId, url_endpoint, that.url_params.title, '', alertify);
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user