diff --git a/docs/en_US/images/move_objects_general.png b/docs/en_US/images/move_objects_general.png deleted file mode 100644 index d4b29e75..00000000 Binary files a/docs/en_US/images/move_objects_general.png and /dev/null differ diff --git a/docs/en_US/images/move_objects_sql.png b/docs/en_US/images/move_objects_sql.png deleted file mode 100644 index 31cf7ff8..00000000 Binary files a/docs/en_US/images/move_objects_sql.png and /dev/null differ diff --git a/docs/en_US/managing_cluster_objects.rst b/docs/en_US/managing_cluster_objects.rst index c0111c1d..f18c063a 100644 --- a/docs/en_US/managing_cluster_objects.rst +++ b/docs/en_US/managing_cluster_objects.rst @@ -15,7 +15,6 @@ database, right-click on the *Databases* node, and select *Create Database...* :maxdepth: 1 database_dialog - move_objects resource_group_dialog role_dialog tablespace_dialog diff --git a/docs/en_US/move_objects.rst b/docs/en_US/move_objects.rst deleted file mode 100644 index 239c9e16..00000000 --- a/docs/en_US/move_objects.rst +++ /dev/null @@ -1,65 +0,0 @@ -.. _move_objects: - -**************************** -`Move Objects Dialog`:index: -**************************** - -Use the *Move Objects* dialog to move database objects from one tablespace to -another tablespace. - -The *Move Objects* dialog organizes the movement of database objects with the -*General* tab; the *SQL* tab displays the SQL code generated by dialog -selections. - -.. image:: images/move_objects_general.png - :alt: Move objects dialog general tab - :align: center - -Use the fields in the *General* tab to identify the items that will be moved and -the tablespace to which they will be moved: - -* Use the *New tablespace* drop-down listbox to select a pre-existing - tablespace to which the object will be moved. (To create a tablespace, use the - *Tablespace* dialog; access the dialog by right clicking *Tablespaces* in the - *pgAdmin* tree control and selecting *Create Tablespace...* from the - context-menu.) -* Use the *Object type* drop-down listbox to select from the following: - - * Select *All* to move all tables, indexes, and materialized views from the - current tablespace (currently selected in the *pgAdmin* tree control) to - the new tablespace. - * Select *Tables* to move tables from the current tablespace to the new - tablespace. - * Select *Indexes* to move indexes from the current tablespace to the new - tablespace. - * Select *Materialized views* to move materialized views from the current - tablespace to the new tablespace. - -* Use the *Object owner* drop-down listbox to select the role that owns the - objects selected in the *Object type* field. This field is optional. - -Click the *SQL* tab to continue. - -Your entries in the *Move Objects* dialog generate a SQL command (see an example -below). Use the *SQL* tab for review; revisit the *General* tab to modify the -SQL command. - -Example -******* - -The following is an example of the sql command generated by user selections in -the *Move Objects* dialog: - -.. image:: images/move_objects_sql.png - :alt: Move Objects dialog sql tab - :align: center - -The example shown demonstrates moving materialized views owned by Alice from -tablespace *tbspace_01* to *tbspace_02*. - -* Click the *Help* button (?) to access online help. -* Click the *OK* button to save work. -* Click the *Cancel* button to exit without saving work. - - - diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py index b32bed15..554f7090 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py @@ -832,76 +832,5 @@ class TablespaceView(PGChildNodeView): return dependents - @check_precondition - def move_objects(self, gid, sid, tsid): - """ - This function moves objects from current tablespace to another - - Args: - gid: Server Group ID - sid: Server ID - tsid: Tablespace ID - """ - data = json.loads(request.form['data'], encoding='utf-8') - - try: - SQL = render_template("/".join( - [self.template_path, 'move_objects.sql']), - data=data, conn=self.conn - ) - status, res = self.conn.execute_scalar(SQL.strip('\n')) - if not status: - return internal_server_error(errormsg=res) - - return make_json_response( - success=1, - info="Tablespace updated", - data={ - 'id': tsid, - 'sid': sid, - 'gid': gid - } - ) - except Exception as e: - current_app.logger.exception(e) - return internal_server_error(errormsg=str(e)) - - @check_precondition - def move_objects_sql(self, gid, sid, tsid): - """ - This function returns sql for Move Objects.. dialog - - Args: - gid: Server Group ID - sid: Server ID - tsid: Tablespace ID - """ - required_args = ['old_tblspc', 'tblspc', 'obj_type'] - - data = dict() - for k, v in request.args.items(): - try: - data[k] = json.loads(v, encoding='utf-8') - except ValueError as ve: - current_app.logger.exception(ve) - data[k] = v - - for arg in required_args: - if arg not in data: - return make_json_response( - data=gettext("-- definition incomplete"), - status=200 - ) - - sql = render_template("/".join( - [self.template_path, 'move_objects.sql']), - data=data, conn=self.conn - ) - - return make_json_response( - data=sql.strip('\n'), - status=200 - ) - TablespaceView.register_node_view(blueprint) diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/static/js/tablespace.js b/web/pgadmin/browser/server_groups/servers/tablespaces/static/js/tablespace.js index a2276cb9..d1603382 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/static/js/tablespace.js +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/static/js/tablespace.js @@ -11,15 +11,13 @@ import { getNodeListByName } from '../../../../../static/js/node_ajax'; import { getNodePrivilegeRoleSchema } from '../../../static/js/privilege.ui'; import { getNodeVariableSchema } from '../../../static/js/variable.ui'; import TablespaceSchema from './tablespace.ui'; -import Notify from '../../../../../../static/js/helpers/Notifier'; define('pgadmin.node.tablespace', [ 'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'backbone', - 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.alertifyjs', - 'pgadmin.backform', 'pgadmin.browser.collection', 'pgadmin.browser.node.ui', + 'sources/pgadmin', 'pgadmin.browser', 'pgadmin.browser.collection', 'pgadmin.browser.node.ui', 'pgadmin.browser.server.privilege', ], function( - gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser, Alertify, Backform + gettext, url_for, $, _, Backbone, pgAdmin, pgBrowser ) { if (!pgBrowser.Nodes['coll-tablespace']) { @@ -74,13 +72,6 @@ define('pgadmin.node.tablespace', [ category: 'create', priority: 4, label: gettext('Tablespace...'), icon: 'wcTabIcon icon-tablespace', data: {action: 'create'}, enable: 'can_create_tablespace', - },{ - name: 'move_tablespace', node: 'tablespace', module: this, - applies: ['object', 'context'], callback: 'move_objects', - category: 'move_tablespace', priority: 5, - label: gettext('Move objects to...'), - icon: 'fa fa-exchange-alt', data: {action: 'create'}, - enable: 'can_move_objects', }, ]); }, @@ -90,239 +81,7 @@ define('pgadmin.node.tablespace', [ return server.connected && server.user.is_superuser; }, - can_move_objects: function(node, item) { - var treeData = pgBrowser.tree.getTreeNodeHierarchy(item), - server = treeData['server']; - // Only supported PG9.4 and above version - return server.connected && - server.user.is_superuser && - server.version >= 90400; - }, callbacks: { - /* Move objects from one tablespace to another */ - move_objects: function(args){ - var input = args || {}, - obj = this, - t = pgBrowser.tree, - i = input.item || t.selected(), - d = i ? t.itemData(i) : undefined, - url = obj.generate_url(i, 'move_objects', d, true), - msql_url = obj.generate_url(i, 'move_objects_sql', d, true); - - if (!d) - return false; - - // Object model - var objModel = Backbone.Model.extend({ - idAttribute: 'id', - defaults: { - new_tblspc: undefined, - obj_type: 'all', - user: undefined, - }, - initialize: function(attrs, otherArgs) { - this.selected_ts = otherArgs.selected_ts; - Backbone.Model.prototype.initialize.apply(this, [attrs, otherArgs]); - }, - schema: [{ - id: 'tblspc', label: gettext('New tablespace'), - type: 'text', disabled: false, control: 'node-list-by-name', - node: 'tablespace', select2: {allowClear: false}, - filter: function(o) { - return o && (o.label != this.model.selected_ts); - }, - },{ - id: 'obj_type', label: gettext('Object type'), - type: 'text', disabled: false, control: 'select2', - select2: { allowClear: false, width: '100%' }, - options: [ - {label: gettext('All'), value: 'all'}, - {label: gettext('Tables'), value: 'tables'}, - {label: gettext('Indexes'), value: 'indexes'}, - {label: gettext('Materialized views'), value: 'materialized_views'}, - ], - },{ - id: 'user', label: gettext('Object owner'), - type: 'text', disabled: false, control: 'node-list-by-name', - node: 'role', select2: {allowClear: false}, - },{ - id: 'sqltab', label: gettext('SQL'), group: gettext('SQL'), - type: 'text', disabled: false, control: Backform.SqlTabControl.extend({ - initialize: function() { - // Initialize parent class - Backform.SqlTabControl.prototype.initialize.apply(this, arguments); - }, - onTabChange: function(sql_tab_obj) { - // Fetch the information only if the SQL tab is visible at the moment. - if (this.dialog && sql_tab_obj.shown == this.tabIndex) { - var self = this, - sql_tab_args = self.model.toJSON(); - // Add existing tablespace - sql_tab_args.old_tblspc = this.model.selected_ts; - - // Fetches modified SQL - $.ajax({ - url: msql_url, - type: 'GET', - cache: false, - data: sql_tab_args, - dataType: 'json', - contentType: 'application/json', - }).done(function(res) { - self.sqlCtrl.clearHistory(); - self.sqlCtrl.setValue(res.data); - self.sqlCtrl.refresh(); - }).fail(function() { - self.model.trigger('pgadmin-view:msql:error'); - }).always(function() { - self.model.trigger('pgadmin-view:msql:fetched'); - }); - } - }, - }), - }], - validate: function() { - return null; - }, - }); - - if(!Alertify.move_objects_dlg) { - Alertify.dialog('move_objects_dlg' ,function factory() { - return { - main: function() { - var title = gettext('Move objects to another tablespace'); - this.set('title', title); - }, - build: function() { - Alertify.pgDialogBuild.apply(this); - }, - setup:function() { - return { - buttons: [{ - text: '', key: 112, - className: 'btn btn-primary-icon pull-left fa fa-question pg-alertify-icon-button', - attrs:{name:'dialog_help', type:'button', label: gettext('Users'), - url: url_for('help.static', {'filename': 'move_objects.html'})}, - },{ - text: gettext('Cancel'), key: 27, className: 'btn btn-secondary fa fa-lg fa-times pg-alertify-button', - },{ - text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-lg fa-save pg-alertify-button', - }], - // Set options for dialog - options: { - //disable both padding and overflow control. - padding : !1, - overflow: !1, - modal: false, - resizable: true, - maximizable: true, - pinnable: false, - closableByDimmer: false, - }, - }; - }, - hooks: { - // Triggered when the dialog is closed - onclose: function() { - if (this.view) { - // clear our backform model/view - this.view.remove({data: true, internal: true, silent: true}); - } - }, - }, - prepare: function() { - var self = this, - $container = $('
'); - //Disbale Okay button - this.__internal.buttons[2].element.disabled = true; - // Find current/selected node - var tree = pgBrowser.tree, - _i = tree.selected(), - _d = _i && _i.length == 1 ? tree.itemData(_i) : undefined, - node = _d && pgBrowser.Nodes[_d._type]; - - if (!_d) - return; - // Create treeInfo - var treeInfo = pgAdmin.tree.getTreeNodeHierarchy.apply(node, [_i]); - // Instance of backbone model - var newModel = new objModel({}, {node_info: treeInfo, selected_ts: _d.label}), - fields = Backform.generateViewSchema( - treeInfo, newModel, 'create', node, - treeInfo.server, true - ); - - var view = this.view = new Backform.Dialog({ - el: $container, model: newModel, schema: fields, - }); - // Add our class to alertify - $(this.elements.body.childNodes[0]).addClass( - 'alertify_tools_dialog_properties obj_properties' - ); - // Render dialog - view.render(); - - this.elements.content.appendChild($container.get(0)); - - // Listen to model & if filename is provided then enable Backup button - this.view.model.on('change', function() { - if (!_.isUndefined(this.get('tblspc')) && this.get('tblspc') !== '') { - this.errorModel.clear(); - self.__internal.buttons[2].element.disabled = false; - } else { - self.__internal.buttons[2].element.disabled = true; - this.errorModel.set('tblspc', gettext('Please select tablespace.')); - } - }); - }, - // Callback functions when click on the buttons of the Alertify dialogs - callback: function(e) { - if (e.button.element.name == 'dialog_help') { - e.cancel = true; - pgBrowser.showHelp(e.button.element.name, e.button.element.getAttribute('url'), - null, null); - return; - } - if (e.button.text === gettext('OK')) { - var self = this, - btn_args = this.view.model.toJSON(); - btn_args.old_tblspc = d.label; - e.cancel = true; - Notify.confirm( - gettext('Move objects...'), - gettext( - 'Are you sure you wish to move the objects from %s to %s?', - btn_args.old_tblspc, btn_args.tblspc - ), - function() { - $.ajax({ - url: url, - method:'PUT', - data:{'data': JSON.stringify(btn_args) }, - }) - .done(function(res) { - if (res.success) { - Notify.success(res.info); - self.close(); - } else { - Notify.error(res.errormsg); - } - }) - .fail(function(xhr, status, error) { - Notify.pgRespErrorNotify(xhr, error); - }); - }, - function() { - // Do nothing as user cancel the operation - } - ); - } - }, - }; - }); - } - Alertify.move_objects_dlg(true).resizeTo(pgBrowser.stdW.md,pgBrowser.stdH.md); - }, }, getSchema: function(treeNodeInfo, itemNodeData) { diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/move_objects.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/move_objects.sql deleted file mode 100644 index 9ad088e8..00000000 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/move_objects.sql +++ /dev/null @@ -1,21 +0,0 @@ -{% if data.obj_type and data.tblspc and data.old_tblspc %} - -{% if data.obj_type == 'all' or data.obj_type == 'tables' %} -ALTER TABLE ALL IN TABLESPACE {{ conn|qtIdent(data.old_tblspc) }} -{% if data.user %} OWNED BY {{ conn|qtIdent(data.user) }}{% endif %} - SET TABLESPACE {{ conn|qtIdent(data.tblspc) }}; -{% endif %} - -{% if data.obj_type == 'all' or data.obj_type == 'indexes' %} -ALTER INDEX ALL IN TABLESPACE {{ conn|qtIdent(data.old_tblspc) }} -{% if data.user %} OWNED BY {{ conn|qtIdent(data.user) }}{% endif %} - SET TABLESPACE {{ conn|qtIdent(data.tblspc) }}; -{% endif %} - -{% if data.obj_type == 'all' or data.obj_type == 'materialized_views' %} -ALTER MATERIALIZED VIEW ALL IN TABLESPACE {{ conn|qtIdent(data.old_tblspc) }} -{% if data.user %} OWNED BY {{ conn|qtIdent(data.user) }}{% endif %} - SET TABLESPACE {{ conn|qtIdent(data.tblspc) }}; -{% endif %} - -{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/default/move_objects.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/default/move_objects.sql deleted file mode 100644 index 09228514..00000000 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/default/move_objects.sql +++ /dev/null @@ -1,21 +0,0 @@ -{% if data.obj_type and data.tblspc and data.old_tblspc %} - -{% if data.obj_type == 'all' or data.obj_type == 'tables' %} -ALTER TABLE ALL IN TABLESPACE {{ conn|qtIdent(data.old_tblspc) }} -{% if data.user %} OWNED BY {{ conn|qtIdent(data.user) }}{% endif %} - SET TABLESPACE {{ conn|qtIdent(data.tblspc) }}; -{% endif %} - -{% if data.obj_type == 'all' or data.obj_type == 'indexes' %} -ALTER INDEX ALL IN TABLESPACE {{ conn|qtIdent(data.old_tblspc) }} -{% if data.user %} OWNED BY {{ conn|qtIdent(data.user) }}{% endif %} - SET TABLESPACE {{ conn|qtIdent(data.tblspc) }}; -{% endif %} - -{% if data.obj_type == 'all' or data.obj_type == 'materialized_views' %} -ALTER MATERIALIZED VIEW ALL IN TABLESPACE {{ conn|qtIdent(data.old_tblspc) }} -{% if data.user %} OWNED BY {{ conn|qtIdent(data.user) }}{% endif %} - SET TABLESPACE {{ conn|qtIdent(data.tblspc) }}; -{% endif %} - -{% endif %} \ No newline at end of file