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

@@ -89,6 +89,11 @@ define('pgadmin.node.table', [
applies: ['object', 'context'], callback: 'truncate_table_cascade',
category: gettext('Truncate'), priority: 3, label: gettext('Truncate Cascade'),
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
name: 'enable_all_triggers', node: 'table', module: this,
@@ -159,6 +164,10 @@ define('pgadmin.node.table', [
var params = {'cascade': true };
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) {
var input = args || {},
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'
)
# 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]
sql = render_template("/".join([self.table_template_path,
'truncate.sql']),
data=data, cascade=is_cascade)
data=data, cascade=is_cascade,
identity=is_identity)
status, res = self.conn.execute_scalar(sql)
if not status:
return internal_server_error(errormsg=res)