Added support for the truncate table with restart identity. Fixes #2538

This commit is contained in:
Aditya Toshniwal 2021-08-27 12:41:29 +05:30 committed by Akshay Joshi
parent 56e2af9efc
commit d38f520805
6 changed files with 19 additions and 6 deletions

View File

@ -74,8 +74,9 @@ following options (in alphabetical order):
+-----------------------------+--------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+
| *Trigger(s)* | Click to *Disable* or *Enable* trigger(s) for the currently selected table. Options are displayed on the flyout menu. | | *Trigger(s)* | Click to *Disable* or *Enable* trigger(s) for the currently selected table. Options are displayed on the flyout menu. |
+-----------------------------+--------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+
| *Truncate* | Click to remove all rows from a table (*Truncate*) or to remove all rows from a table and its child tables | | *Truncate* | Click to remove all rows from a table (*Truncate*), to remove all rows from a table and its child tables |
| | (*Truncate Cascade*). Options are displayed on the flyout menu. | | | (*Truncate Cascade*) or to remove all rows from a table and automatically restart sequences owned by columns |
| | (*Truncate Restart Identity*). Options are displayed on the flyout menu. |
+-----------------------------+--------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+
| *View Data* | Click to access a context menu that provides several options for viewing data (see below). | | *View Data* | Click to access a context menu that provides several options for viewing data (see below). |
+-----------------------------+--------------------------------------------------------------------------------------------------------------------------+ +-----------------------------+--------------------------------------------------------------------------------------------------------------------------+

View File

@ -9,6 +9,7 @@ This release contains a number of bug fixes and new features since the release o
New features New features
************ ************
| `Issue #2538 <https://redmine.postgresql.org/issues/2538>`_ - Added support for the truncate table with restart identity.
| `Issue #4264 <https://redmine.postgresql.org/issues/4264>`_ - Make code folding case insensitive in the code mirror. | `Issue #4264 <https://redmine.postgresql.org/issues/4264>`_ - Make code folding case insensitive in the code mirror.
| `Issue #4629 <https://redmine.postgresql.org/issues/4629>`_ - Added database and server information on the Maintenance process watcher dialog. | `Issue #4629 <https://redmine.postgresql.org/issues/4629>`_ - Added database and server information on the Maintenance process watcher dialog.
| `Issue #6495 <https://redmine.postgresql.org/issues/6495>`_ - Allow the referenced table to be the same as the local table in one to many relationship for ERD Tool. | `Issue #6495 <https://redmine.postgresql.org/issues/6495>`_ - Allow the referenced table to be the same as the local table in one to many relationship for ERD Tool.

View File

@ -89,6 +89,11 @@ define('pgadmin.node.table', [
applies: ['object', 'context'], callback: 'truncate_table_cascade', applies: ['object', 'context'], callback: 'truncate_table_cascade',
category: gettext('Truncate'), priority: 3, label: gettext('Truncate Cascade'), category: gettext('Truncate'), priority: 3, label: gettext('Truncate Cascade'),
icon: 'fa fa-eraser', enable : 'canCreate', icon: 'fa fa-eraser', enable : 'canCreate',
},{
name: 'truncate_table_identity', node: 'table', module: this,
applies: ['object', 'context'], callback: 'truncate_table_identity',
category: gettext('Truncate'), priority: 3, label: gettext('Truncate Restart Identity'),
icon: 'fa fa-eraser', enable : 'canCreate',
},{ },{
// To enable/disable all triggers for the table // To enable/disable all triggers for the table
name: 'enable_all_triggers', node: 'table', module: this, name: 'enable_all_triggers', node: 'table', module: this,
@ -159,6 +164,10 @@ define('pgadmin.node.table', [
var params = {'cascade': true }; var params = {'cascade': true };
this.callbacks.truncate.apply(this, [args, params]); this.callbacks.truncate.apply(this, [args, params]);
}, },
truncate_table_identity: function(args) {
var params = {'identity': true };
this.callbacks.truncate.apply(this, [args, params]);
},
truncate: function(args, params) { truncate: function(args, params) {
var input = args || {}, var input = args || {},
obj = this, obj = this,

View File

@ -1 +1 @@
TRUNCATE TABLE {{conn|qtIdent(data.schema, data.name)}}{% if cascade %} CASCADE{% endif %}; TRUNCATE TABLE {{conn|qtIdent(data.schema, data.name)}}{% if identity %} RESTART IDENTITY{% endif %}{% if cascade %} CASCADE{% endif %};

View File

@ -1897,13 +1897,15 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
request.data, encoding='utf-8' request.data, encoding='utf-8'
) )
# Convert str 'true' to boolean type # Convert str 'true' to boolean type
is_cascade = json.loads(data['cascade']) is_cascade = json.loads(data.get('cascade') or 'false')
is_identity = json.loads(data.get('identity') or 'false')
data = res['rows'][0] data = res['rows'][0]
sql = render_template("/".join([self.table_template_path, sql = render_template("/".join([self.table_template_path,
'truncate.sql']), 'truncate.sql']),
data=data, cascade=is_cascade) data=data, cascade=is_cascade,
identity=is_identity)
status, res = self.conn.execute_scalar(sql) status, res = self.conn.execute_scalar(sql)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)

View File

@ -163,7 +163,7 @@ class PGUtilitiesMaintenanceFeatureTest(BaseFeatureTest):
) )
else: else:
self.assertEqual( self.assertEqual(
command, vacuum_details + "\nRunning Query:\nVACUUM VERBOSE;" command, vacuum_details + "\nRunning Query:\nVACUUM VERBOSE"
" public." + self.table_name + ";") " public." + self.table_name + ";")
test_gui_helper.close_process_watcher(self) test_gui_helper.close_process_watcher(self)