mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-16 03:32:20 -06:00
Add support for TRUNCATE trigger in foreign table. #6448
This commit is contained in:
parent
e8fdf04e97
commit
ce146b679c
@ -73,13 +73,6 @@ class ForeignTableModule(SchemaChildModule):
|
||||
base_template_path=ForeignTableView.BASE_TEMPLATE_PATH):
|
||||
yield self.generate_browser_collection_node(scid)
|
||||
|
||||
@property
|
||||
def node_inode(self):
|
||||
"""
|
||||
Make the node as leaf node.
|
||||
"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def script_load(self):
|
||||
"""
|
||||
@ -88,6 +81,15 @@ class ForeignTableModule(SchemaChildModule):
|
||||
"""
|
||||
return databases.DatabaseModule.node_type
|
||||
|
||||
def register(self, app, options):
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.\
|
||||
tables.triggers import blueprint as module
|
||||
self.submodules.append(module)
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
|
||||
constraints import blueprint as module
|
||||
self.submodules.append(module)
|
||||
super().register(app, options)
|
||||
|
||||
|
||||
blueprint = ForeignTableModule(__name__)
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
"""
|
||||
We will use the existing modules for creating children module under
|
||||
foreign tables.
|
||||
|
||||
Do not remove these imports as they will be automatically imported by the view
|
||||
module as its children
|
||||
"""
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.tables.columns \
|
||||
import blueprint as columns_module
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.tables.triggers \
|
||||
import blueprint as triggers_modules
|
||||
from pgadmin.browser.server_groups.servers.databases.schemas.tables.\
|
||||
constraints import blueprint as constraints_modules
|
@ -16,7 +16,8 @@ import _ from 'lodash';
|
||||
define('pgadmin.node.foreign_table', [
|
||||
'sources/gettext', 'sources/url_for', 'pgadmin.browser',
|
||||
'pgadmin.node.schema.dir/child', 'pgadmin.node.schema.dir/schema_child_tree_node',
|
||||
'pgadmin.browser.collection',
|
||||
'pgadmin.browser.collection','pgadmin.node.column',
|
||||
'pgadmin.node.constraints'
|
||||
], function(
|
||||
gettext, url_for, pgBrowser, schemaChild, schemaChildTreeNode
|
||||
) {
|
||||
|
@ -31,7 +31,9 @@ define('pgadmin.node.column', [
|
||||
|
||||
if (!pgBrowser.Nodes['column']) {
|
||||
pgBrowser.Nodes['column'] = pgBrowser.Node.extend({
|
||||
parent_type: ['table', 'view', 'mview'],
|
||||
// Foreign table is added in parent_type to support triggers on
|
||||
// foreign table where we need column information.
|
||||
parent_type: ['table', 'view', 'mview', 'foreign_table'],
|
||||
collection_type: ['coll-table', 'coll-view', 'coll-mview'],
|
||||
type: 'column',
|
||||
label: gettext('Column'),
|
||||
|
@ -55,10 +55,12 @@ class ConstraintsModule(CollectionNodeModule):
|
||||
self.max_ver = None
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def get_nodes(self, gid, sid, did, scid, tid):
|
||||
def get_nodes(self, gid, sid, did, scid, **kwargs):
|
||||
"""
|
||||
Generate the collection node
|
||||
"""
|
||||
assert ('tid' in kwargs or 'vid' in kwargs or 'foid' in kwargs)
|
||||
tid = kwargs.get('tid', kwargs.get('vid', kwargs.get('foid', None)))
|
||||
nodes = []
|
||||
for name in ConstraintRegistry.registry:
|
||||
view = (ConstraintRegistry.registry[name])['nodeview']
|
||||
|
@ -30,7 +30,7 @@ define('pgadmin.node.check_constraint', [
|
||||
dialogHelp: url_for('help.static', {'filename': 'check_dialog.html'}),
|
||||
hasSQL: true,
|
||||
hasDepends: true,
|
||||
parent_type: ['table','partition'],
|
||||
parent_type: ['table','partition','foreign_table'],
|
||||
url_jump_after_node: 'schema',
|
||||
Init: function() {
|
||||
// Avoid mulitple registration of menus
|
||||
|
@ -75,7 +75,10 @@ define('pgadmin.node.exclusion_constraint', [
|
||||
|
||||
// If it is schema then allow user to create table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
return !is_immediate_parent_table_partitioned;
|
||||
{return !is_immediate_parent_table_partitioned;}
|
||||
else if (_.indexOf(['foreign_table', 'coll-foreign_table'], d._type) > -1) {
|
||||
return false;
|
||||
}
|
||||
parents.push(d._type);
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
|
@ -110,8 +110,12 @@ define('pgadmin.node.foreign_key', [
|
||||
}
|
||||
|
||||
// If it is schema then allow user to c reate table
|
||||
if (_.indexOf(['schema'], d._type) > -1)
|
||||
if (_.indexOf(['schema'], d._type) > -1){
|
||||
return !is_immediate_parent_table_partitioned;
|
||||
}else if (_.indexOf(['foreign_table', 'coll-foreign_table'], d._type) > -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parents.push(d._type);
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
d = i ? t.itemData(i) : null;
|
||||
|
@ -86,6 +86,8 @@ define('pgadmin.node.primary_key', [
|
||||
}
|
||||
});
|
||||
return !primary_key_found;
|
||||
}else if (_.indexOf(['foreign_table', 'coll-foreign_table'], d._type) > -1) {
|
||||
return false;
|
||||
}
|
||||
parents.push(d._type);
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
|
@ -71,6 +71,8 @@ define('pgadmin.node.unique_constraint', [
|
||||
// If it is schema then allow user to c reate table
|
||||
if (_.indexOf(['schema'], d._type) > -1) {
|
||||
return !is_immediate_parent_table_partitioned;
|
||||
}else if (_.indexOf(['foreign_table', 'coll-foreign_table'], d._type) > -1) {
|
||||
return false;
|
||||
}
|
||||
parents.push(d._type);
|
||||
i = t.hasParent(i) ? t.parent(i) : null;
|
||||
|
@ -31,8 +31,8 @@ define('pgadmin.node.constraints', [
|
||||
pgAdmin.Browser.Nodes['constraints'] = pgBrowser.Node.extend({
|
||||
type: 'constraints',
|
||||
label: gettext('Constraints'),
|
||||
collection_type: 'coll-constraints',
|
||||
parent_type: ['table','partition'],
|
||||
collection_type: ['coll-constraints','coll-foreign_table'],
|
||||
parent_type: ['table','foreign_table'],
|
||||
url_jump_after_node: 'schema',
|
||||
Init: function() {
|
||||
/* Avoid mulitple registration of menus */
|
||||
|
@ -100,12 +100,13 @@ class TriggerModule(CollectionNodeModule):
|
||||
"""
|
||||
Generate the collection node
|
||||
"""
|
||||
assert ('tid' in kwargs or 'vid' in kwargs)
|
||||
assert ('tid' in kwargs or 'vid' in kwargs or 'foid' in kwargs)
|
||||
tid = kwargs.get('tid', kwargs.get('vid', kwargs.get('foid', None)))
|
||||
if self.has_nodes(sid, did, scid=scid,
|
||||
tid=kwargs.get('tid', kwargs.get('vid', None)),
|
||||
tid=tid,
|
||||
base_template_path=TriggerView.BASE_TEMPLATE_PATH):
|
||||
yield self.generate_browser_collection_node(
|
||||
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
|
||||
tid
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -35,8 +35,8 @@ define('pgadmin.node.trigger', [
|
||||
|
||||
if (!pgBrowser.Nodes['trigger']) {
|
||||
pgAdmin.Browser.Nodes['trigger'] = pgBrowser.Node.extend({
|
||||
parent_type: ['table', 'view', 'partition'],
|
||||
collection_type: ['coll-table', 'coll-view'],
|
||||
parent_type: ['table', 'view', 'partition', 'foreign_table'],
|
||||
collection_type: ['coll-table', 'coll-view','coll-foreign_table'],
|
||||
type: 'trigger',
|
||||
label: gettext('Trigger'),
|
||||
hasSQL: true,
|
||||
@ -93,7 +93,13 @@ define('pgadmin.node.trigger', [
|
||||
category: 'create', priority: 4, label: gettext('Trigger...'),
|
||||
data: {action: 'create', check: true},
|
||||
enable: 'canCreate',
|
||||
},
|
||||
},{
|
||||
name: 'create_trigger_onForeignTable', node: 'foreign_table', module: this,
|
||||
applies: ['object', 'context'], callback: 'show_obj_properties',
|
||||
category: 'create', priority: 3, label: gettext('Trigger...'),
|
||||
data: {action: 'create', check: true},
|
||||
enable: 'canCreate',
|
||||
}
|
||||
]);
|
||||
},
|
||||
callbacks: {
|
||||
|
Loading…
Reference in New Issue
Block a user