Skip to content

Commit

Permalink
Support TRUNCATE triggers on foreign tables.#6448
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshmahajan-1903 committed Aug 2, 2023
1 parent 0f86b78 commit b8274ae
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ def get_nodes(self, gid, sid, did, scid):
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):
"""
Expand All @@ -88,6 +81,15 @@ def script_load(self):
"""
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__)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ def __init__(self, *args, **kwargs):
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']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ def get_nodes(self, gid, sid, did, scid, **kwargs):
"""
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit b8274ae

Please sign in to comment.