mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added support for the truncate table with restart identity. Fixes #2538
This commit is contained in:
committed by
Akshay Joshi
parent
56e2af9efc
commit
d38f520805
@@ -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,
|
||||
|
||||
@@ -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 %};
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user