Added support to detach partitions using concurrently and finalize. #6369

This commit is contained in:
Akshay Joshi 2023-06-29 10:33:39 +05:30 committed by GitHub
parent dcca55a200
commit 0687c52fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 4 deletions

View File

@ -11,6 +11,7 @@ notes for it.
.. toctree::
:maxdepth: 1
release_notes_7_5
release_notes_7_4
release_notes_7_3
release_notes_7_2

View File

@ -0,0 +1,31 @@
***********
Version 7.5
***********
Release date: 2023-07-27
This release contains a number of bug fixes and new features since the release of pgAdmin 4 v7.4.
Supported Database Servers
**************************
**PostgreSQL**: 11, 12, 13, 14 and 15
**EDB Advanced Server**: 11, 12, 13, 14 and 15
Bundled PostgreSQL Utilities
****************************
**psql**, **pg_dump**, **pg_dumpall**, **pg_restore**: 15.3
New features
************
| `Issue #6369 <https://github.com/pgadmin-org/pgadmin4/issues/6369>`_ - Added support to detach partitions using concurrently and finalize.
Housekeeping
************
Bug fixes
*********

View File

@ -542,6 +542,11 @@ class PartitionsView(BaseTableView, DataTypeReader, SchemaDiffObjectCompare):
tid: Table ID
ptid: Partition Table ID
"""
data = request.form if request.form else json.loads(
request.data
)
mode = data.get('mode')
# Fetch schema name
status, parent_schema = self.conn.execute_scalar(
render_template(
@ -595,6 +600,7 @@ class PartitionsView(BaseTableView, DataTypeReader, SchemaDiffObjectCompare):
temp_data['partitioned_table_name'] = partitioned_table_name
temp_data['schema'] = partition_schema
temp_data['name'] = partition_name
temp_data['mode'] = mode
SQL = render_template(
"/".join([self.partition_template_path, 'detach.sql']),

View File

@ -96,7 +96,17 @@ function(
},{
name: 'detach_partition', node: 'partition', module: this,
applies: ['object', 'context'], callback: 'detach_partition',
priority: 2, label: gettext('Detach Partition'),
category: gettext('Detach Partition'), priority: 2, label: gettext('Detach'),
},{
name: 'detach_partition_concurrently', node: 'partition', module: this,
applies: ['object', 'context'], callback: 'detach_partition_concurrently',
category: gettext('Detach Partition'), priority: 2, label: gettext('Concurrently'),
enable: 'canDetach'
},{
name: 'detach_partition_finalize', node: 'partition', module: this,
applies: ['object', 'context'], callback: 'detach_partition_finalize',
category: gettext('Detach Partition'), priority: 2, label: gettext('Finalize'),
enable: 'canDetach'
},{
name: 'count_table_rows', node: 'partition', module: pgBrowser.Nodes['table'],
applies: ['object', 'context'], callback: 'count_table_rows',
@ -236,7 +246,7 @@ function(
function() {/*This is intentional (SonarQube)*/}
);
},
detach_partition: function(args) {
detach: function(args, params) {
let input = args || {},
obj = this,
t = pgBrowser.tree,
@ -246,11 +256,19 @@ function(
if (!d)
return false;
let title = gettext('Detach Partition');
if (params['mode'] === 'concurrently') {
title = gettext('Detach Partition Concurrently');
} else if (params['mode'] === 'finalize') {
title = gettext('Detach Partition Finalize');
}
Notify.confirm(
gettext('Detach Partition'),
title,
gettext('Are you sure you want to detach the partition %s?', d._label),
function () {
getApiInstance().put(obj.generate_url(i, 'detach' , d, true))
getApiInstance().put(obj.generate_url(i, 'detach' , d, true), params)
.then(({data: res})=>{
if (res.success == 1) {
Notify.success(res.info);
@ -274,6 +292,18 @@ function(
function() {/*This is intentional (SonarQube)*/}
);
},
detach_partition: function(args) {
let params = {'mode': 'detach' };
this.callbacks.detach.apply(this, [args, params]);
},
detach_partition_concurrently: function(args) {
let params = {'mode': 'concurrently' };
this.callbacks.detach.apply(this, [args, params]);
},
detach_partition_finalize: function(args) {
let params = {'mode': 'finalize' };
this.callbacks.detach.apply(this, [args, params]);
},
},
getSchema: function(treeNodeInfo, itemNodeData) {
return getNodePartitionTableSchema(treeNodeInfo, itemNodeData, pgBrowser);
@ -293,6 +323,12 @@ function(
return (itemData.tigger_count > 0 && itemData.has_enable_triggers > 0);
}
},
canDetach: function(itemData, item) {
let treeData = pgBrowser.tree.getTreeNodeHierarchy(item),
server = treeData['server'];
return (server && server.version >= 140000);
},
});
}

View File

@ -1 +1,7 @@
{% if data.mode is defined and data.mode == 'concurrently' %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}} DETACH PARTITION {{conn|qtIdent(data.schema, data.name)}} CONCURRENTLY;
{% elif data.mode is defined and data.mode == 'finalize' %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}} DETACH PARTITION {{conn|qtIdent(data.schema, data.name)}} FINALIZE;
{% else %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}} DETACH PARTITION {{conn|qtIdent(data.schema, data.name)}};
{% endif %}

View File

@ -1 +1,7 @@
{% if data.mode is defined and data.mode == 'concurrently' %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}} DETACH PARTITION {{conn|qtIdent(data.schema, data.name)}} CONCURRENTLY;
{% elif data.mode is defined and data.mode == 'finalize' %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}} DETACH PARTITION {{conn|qtIdent(data.schema, data.name)}} FINALIZE;
{% else %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}} DETACH PARTITION {{conn|qtIdent(data.schema, data.name)}};
{% endif %}