Add an option to hide/show empty object collection nodes. #5048

pull/6305/head
Aditya Toshniwal 2023-05-22 14:55:01 +05:30 committed by GitHub
parent c9013a39b8
commit cedfd12f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
85 changed files with 630 additions and 128 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 193 KiB

View File

@ -59,6 +59,8 @@ Use the fields on the *Display* panel to specify general display preferences:
| *Full* | This will disable resizing, docking/undocking of the panels |
+---------------------+-------------------------------------------------------------------+
* When the *Show empty object collections?* switch is turned off, then all object
collections which are empty will be hidden from browser tree.
* When the *Show system objects?* switch is set to *True*, the client will
display system objects such as system schemas (for example, *pg_temp*) or
system columns (for example, *xmin* or *ctid*) in the tree control.

View File

@ -16,6 +16,9 @@ from pgadmin.browser.utils import PGChildModule
from pgadmin.utils import PgAdminModule
from pgadmin.utils.preferences import Preferences
from pgadmin.utils.constants import PGADMIN_NODE
from pgadmin.utils.driver import get_driver
from config import PG_DEFAULT_DRIVER
from pgadmin.browser.utils import PGChildNodeView
class CollectionNodeModule(PgAdminModule, PGChildModule, metaclass=ABCMeta):
@ -94,6 +97,42 @@ class CollectionNodeModule(PgAdminModule, PGChildModule, metaclass=ABCMeta):
return obj
def has_nodes(self, sid, did, scid=None, tid=None, vid=None,
base_template_path=''):
if self.pref_show_empty_coll_nodes.get():
return True
try:
driver = get_driver(PG_DEFAULT_DRIVER)
manager = driver.connection_manager(sid)
conn = manager.connection(did=did)
if '{1}' in base_template_path:
template_base_path = base_template_path.format(
manager.server_type, manager.version)
else:
template_base_path = base_template_path.format(manager.version)
last_system_oid = 0 if self.show_system_objects else \
PGChildNodeView._DATABASE_LAST_SYSTEM_OID
sql = render_template(
"/".join([template_base_path, PGChildNodeView._COUNT_SQL]),
did=did,
scid=scid,
tid=tid,
vid=vid,
datlastsysoid=last_system_oid,
showsysobj=self.show_system_objects,
conn=conn
)
status, res = conn.execute_dict(sql)
return int(res['rows'][0]['count']) > 0 if status \
else True
except Exception as _:
return True
@property
def node_type(self):
return '%s' % (self._NODE_TYPE)
@ -239,3 +278,6 @@ class CollectionNodeModule(PgAdminModule, PGChildModule, metaclass=ABCMeta):
self.collection_label, 'node', self.SHOW_ON_BROWSER,
category_label=gettext('Nodes')
)
self.pref_show_empty_coll_nodes = self.browser_preference.preference(
'show_empty_coll_nodes'
)

View File

@ -29,6 +29,16 @@ def register_browser_preferences(self):
category_label=PREF_LABEL_DISPLAY
)
self.show_empty_coll_nodes = self.preference.register(
'display', 'show_empty_coll_nodes',
gettext("Show empty object collections?"), 'boolean', True,
category_label=PREF_LABEL_DISPLAY,
help_str=gettext(
'If turned off, then all object collections which are empty '
'will be hidden from browser tree'
)
)
self.show_user_defined_templates = self.preference.register(
'display', 'show_user_defined_templates',
gettext("Show template databases?"), 'boolean', False,

View File

@ -60,7 +60,9 @@ class CastModule(CollectionNodeModule):
:param sid: server id
:param did: database id
"""
yield self.generate_browser_collection_node(did)
if self.has_nodes(sid, did,
base_template_path=CastView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(did)
@property
def node_inode(self):
@ -148,6 +150,7 @@ class CastView(PGChildNodeView, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'casts/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -208,7 +211,8 @@ class CastView(PGChildNodeView, SchemaDiffObjectCompare):
).connection_manager(kwargs['sid'])
self.conn = self.manager.connection(did=kwargs['did'])
# Set template path for the SQL scripts
self.template_path = 'casts/sql/#{0}#'.format(self.manager.version)
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
self.datistemplate = False
if (

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_cast ca
WHERE 1=1
{# Check for Show system object #}
{% if (not showsysobj) and datlastsysoid %}
AND ca.oid > {{datlastsysoid}}::OID
{% endif %}

View File

@ -65,7 +65,10 @@ class EventTriggerModule(CollectionNodeModule):
"""
Generate the event_trigger node
"""
yield self.generate_browser_collection_node(sid)
if self.has_nodes(
sid, did,
base_template_path=EventTriggerView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(sid)
@property
def node_inode(self):
@ -149,6 +152,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_icon = "icon-%s" % blueprint.node_type
BASE_TEMPLATE_PATH = 'event_triggers/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -194,7 +198,7 @@ class EventTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
PG_DEFAULT_DRIVER
).connection_manager(kwargs['sid'])
self.conn = self.manager.connection(did=kwargs['did'])
self.template_path = 'event_triggers/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
self.datistemplate = False

View File

@ -0,0 +1,2 @@
SELECT COUNT(*)
FROM pg_catalog.pg_event_trigger e

View File

@ -48,7 +48,9 @@ class ExtensionModule(CollectionNodeModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(did)
if self.has_nodes(sid, did,
base_template_path=ExtensionView.EXT_TEMPLATE_PATH):
yield self.generate_browser_collection_node(did)
@property
def node_inode(self):

View File

@ -0,0 +1,3 @@
SELECT COUNT(*)
FROM pg_catalog.pg_extension x
WHERE 1=1

View File

@ -75,7 +75,10 @@ class ForeignDataWrapperModule(CollectionNodeModule):
sid: Server ID
did: Database Id
"""
yield self.generate_browser_collection_node(did)
if self.has_nodes(
sid, did,
base_template_path=ForeignDataWrapperView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(did)
@property
def script_load(self):
@ -179,6 +182,7 @@ class ForeignDataWrapperView(PGChildNodeView, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'foreign_data_wrappers/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -235,7 +239,7 @@ class ForeignDataWrapperView(PGChildNodeView, SchemaDiffObjectCompare):
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = 'foreign_data_wrappers/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version
)

View File

@ -0,0 +1,2 @@
SELECT COUNT(*)
FROM pg_catalog.pg_foreign_data_wrapper fdw

View File

@ -74,7 +74,10 @@ class LanguageModule(CollectionNodeModule):
sid: Server ID
did: Database Id
"""
yield self.generate_browser_collection_node(did)
if self.has_nodes(
sid, did,
base_template_path=LanguageView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(did)
@property
def node_inode(self):
@ -175,6 +178,7 @@ class LanguageView(PGChildNodeView, SchemaDiffObjectCompare):
_NOT_FOUND_LANG_INFORMATION = \
gettext("Could not find the language information.")
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = "languages/sql/#{0}#"
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -241,7 +245,7 @@ class LanguageView(PGChildNodeView, SchemaDiffObjectCompare):
# Set the template path for the SQL scripts
self.template_path = (
"languages/sql/#{0}#".format(self.manager.version)
self.BASE_TEMPLATE_PATH.format(self.manager.version)
)
return f(*args, **kwargs)

View File

@ -73,7 +73,10 @@ class PublicationModule(CollectionNodeModule):
sid: Server ID
did: Database Id
"""
yield self.generate_browser_collection_node(did)
if self.has_nodes(
sid, did,
base_template_path=PublicationView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(did)
@property
def node_inode(self):
@ -167,6 +170,7 @@ class PublicationView(PGChildNodeView, SchemaDiffObjectCompare):
_NOT_FOUND_PUB_INFORMATION = \
gettext("Could not find the publication information.")
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = "publications/sql/#{0}#"
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -223,7 +227,7 @@ class PublicationView(PGChildNodeView, SchemaDiffObjectCompare):
self.conn = self.manager.connection(did=kwargs['did'])
# Set the template path for the SQL scripts
self.template_path = (
"publications/sql/#{0}#".format(self.manager.version)
self.BASE_TEMPLATE_PATH.format(self.manager.version)
)
return f(*args, **kwargs)

View File

@ -0,0 +1,2 @@
SELECT COUNT(*)
FROM pg_catalog.pg_publication c

View File

@ -67,7 +67,9 @@ class AggregateModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=AggregateView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -118,6 +120,7 @@ class AggregateView(PGChildNodeView):
node_type = blueprint.node_type
node_label = "Aggregate"
BASE_TEMPLATE_PATH = 'aggregates/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -165,10 +168,8 @@ class AggregateView(PGChildNodeView):
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = compile_template_path(
'aggregates/sql/',
self.manager.version
)
self.template_path = \
self.BASE_TEMPLATE_PATH.format(self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,4 @@
SELECT COUNT(*)
FROM pg_catalog.pg_aggregate ag
LEFT OUTER JOIN pg_catalog.pg_proc pr ON pr.oid = ag.aggfnoid
WHERE pronamespace = {{scid}}::oid;

View File

@ -70,7 +70,9 @@ class CollationModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=CollationView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -148,6 +150,7 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Collation"
BASE_TEMPLATE_PATH = 'collations/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -202,10 +205,8 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = compile_template_path(
'collations/sql/',
self.manager.version
)
self.template_path = \
self.BASE_TEMPLATE_PATH.format(self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,5 @@
SELECT COUNT(*)
FROM pg_catalog.pg_collation c
{% if scid %}
WHERE c.collnamespace = {{scid}}::oid
{% endif %}

View File

@ -61,7 +61,9 @@ class DomainModule(SchemaChildModule):
"""
Generate the domain collection node.
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=DomainView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -151,6 +153,7 @@ class DomainView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Domain"
BASE_TEMPLATE_PATH = 'domains/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -301,10 +304,8 @@ class DomainView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
kwargs['did']]['datistemplate']
# we will set template path for sql scripts
self.template_path = compile_template_path(
'domains/sql/',
self.manager.version
)
self.template_path = \
self.BASE_TEMPLATE_PATH.format(self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,9 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_type d
JOIN
pg_catalog.pg_type b ON b.oid = d.typbasetype
JOIN
pg_catalog.pg_namespace bn ON bn.oid=d.typnamespace
WHERE
d.typnamespace = {{scid}}::oid

View File

@ -68,7 +68,10 @@ class ForeignTableModule(SchemaChildModule):
"""
Generate the Foreign Table collection node.
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(
sid, did, scid,
base_template_path=ForeignTableView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -178,6 +181,7 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
node_type = blueprint.node_type
node_label = "Foreign Table"
BASE_TEMPLATE_PATH = 'foreign_tables/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -390,10 +394,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
# Set template path for sql scripts depending
# on the server version.
self.template_path = compile_template_path(
'foreign_tables/sql/',
self.manager.version
)
self.template_path = \
self.BASE_TEMPLATE_PATH.format(self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_class c
JOIN
pg_catalog.pg_foreign_table ft ON c.oid=ft.ftrelid
WHERE
c.relnamespace = {{scid}}::oid

View File

@ -68,7 +68,10 @@ class FtsConfigurationModule(SchemaChildModule):
:param did: database id
:param scid: schema id
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(
sid, did, scid,
base_template_path=FtsConfigurationView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -169,6 +172,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'fts_configurations/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -236,7 +240,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = 'fts_configurations/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_ts_config cfg
WHERE
{% if scid %}
cfg.cfgnamespace = {{scid}}::OID
{% endif %}

View File

@ -66,7 +66,10 @@ class FtsDictionaryModule(SchemaChildModule):
:param did: database id
:param scid: schema id
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(
sid, did, scid,
base_template_path=FtsDictionaryView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -161,6 +164,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'fts_dictionaries/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -225,7 +229,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = 'fts_dictionaries/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_ts_dict dict
WHERE
{% if scid %}
dict.dictnamespace = {{scid}}::OID
{% endif %}

View File

@ -59,7 +59,10 @@ class FtsParserModule(SchemaChildModule):
:param did: database id
:param scid: schema id
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=FtsParserView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -163,6 +166,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'fts_parsers/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -238,7 +242,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
self.datistemplate = self.manager.db_info[
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = 'fts_parsers/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_ts_parser prs
WHERE
{% if scid %}
prs.prsnamespace = {{scid}}::OID
{% endif %}

View File

@ -65,7 +65,10 @@ class FtsTemplateModule(SchemaChildModule):
:param did: database id
:param scid: schema id
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(
sid, did, scid,
base_template_path=FtsTemplateView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -157,6 +160,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "FTS Template"
BASE_TEMPLATE_PATH = 'fts_templates/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -217,7 +221,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
):
self.datistemplate = self.manager.db_info[
kwargs['did']]['datistemplate']
self.template_path = 'fts_templates/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_ts_template tmpl
WHERE
{% if scid %}
tmpl.tmplnamespace = {{scid}}::OID
{% endif %}

View File

@ -81,7 +81,9 @@ class FunctionModule(SchemaChildModule):
"""
Generate Functions collection node.
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=FunctionView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -185,7 +187,7 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'functions/{0}/sql/#{1}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
{'type': 'int', 'id': 'sid'},
@ -351,21 +353,9 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
self.qtIdent = driver.qtIdent
self.qtLiteral = driver.qtLiteral
template_initial = None
if self.node_type == 'function':
template_initial = 'functions'
elif self.node_type == 'procedure':
template_initial = 'procedures'
elif self.node_type == 'trigger_function':
template_initial = 'trigger_functions'
# Set the template path for the SQL scripts
self.sql_template_path = "/".join([
template_initial,
self.manager.server_type,
'sql',
'#{0}#'
]).format(self.manager.version)
self.sql_template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.server_type, self.manager.version)
return f(*args, **kwargs)
@ -2074,7 +2064,9 @@ class ProcedureModule(SchemaChildModule):
"""
Generate Procedures collection node.
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=ProcedureView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -2099,6 +2091,7 @@ procedure_blueprint = ProcedureModule(__name__)
class ProcedureView(FunctionView):
node_type = procedure_blueprint.node_type
BASE_TEMPLATE_PATH = 'procedures/{0}/sql/#{1}#'
def __init__(self, *args, **kwargs):
"""
@ -2172,7 +2165,10 @@ class TriggerFunctionModule(SchemaChildModule):
"""
Generate Trigger function collection node.
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(
sid, did, scid,
base_template_path=TriggerFunctionView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def node_inode(self):
@ -2197,6 +2193,7 @@ trigger_function_blueprint = TriggerFunctionModule(__name__)
class TriggerFunctionView(FunctionView):
node_type = trigger_function_blueprint.node_type
BASE_TEMPLATE_PATH = 'trigger_functions/{0}/sql/#{1}#'
def __init__(self, *args, **kwargs):
"""

View File

@ -0,0 +1,9 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
WHERE
pr.prokind IN ('f', 'w')
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
proisagg = FALSE
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid

View File

@ -0,0 +1,9 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
WHERE
pr.prokind IN ('f', 'w')
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
proisagg = FALSE
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
pr.prokind = 'p'
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
pr.prokind = 'p'
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
pr.prokind = 'p'::char
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
pr.prokind = 'p'::char
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
proisagg = FALSE
AND typname NOT IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,14 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
pr.prokind IN ('f', 'w')
AND typname IN ('trigger', 'event_trigger')
AND lanname NOT IN ('edbspl', 'sql', 'internal')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,14 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
proisagg = FALSE
AND typname IN ('trigger', 'event_trigger')
AND lanname NOT IN ('edbspl', 'sql', 'internal')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,13 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
pr.prokind IN ('f', 'w')
AND typname IN ('trigger', 'event_trigger')
AND pronamespace = {{scid}}::oid;

View File

@ -0,0 +1,14 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_proc pr
JOIN
pg_catalog.pg_type typ ON typ.oid=prorettype
JOIN
pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace
JOIN
pg_catalog.pg_language lng ON lng.oid=prolang
WHERE
proisagg = FALSE
AND typname IN ('trigger', 'event_trigger')
AND lanname NOT IN ('sql', 'internal')
AND pronamespace = {{scid}}::oid;

View File

@ -67,7 +67,9 @@ class OperatorModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=OperatorView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -117,6 +119,7 @@ class OperatorView(PGChildNodeView):
node_type = blueprint.node_type
node_label = "Operator"
BASE_TEMPLATE_PATH = 'operators/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -164,8 +167,10 @@ class OperatorView(PGChildNodeView):
kwargs['did']]['datistemplate']
# Set the template path for the SQL scripts
self.template_path = \
self.BASE_TEMPLATE_PATH.format(self.manager.version)
self.template_path = compile_template_path(
'operators/sql/',
self.BASE_TEMPLATE_PATH,
self.manager.version
)

View File

@ -0,0 +1,6 @@
SELECT COUNT(*)
FROM pg_catalog.pg_operator op
JOIN pg_catalog.pg_type et on et.oid=op.oprresult
{% if scid %}
WHERE op.oprnamespace = {{scid}}::oid
{% endif %}

View File

@ -66,7 +66,9 @@ class PackageModule(SchemaChildModule):
"""
Generate the package node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=PackageView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -99,6 +101,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Package"
node_icon = "icon-%s" % node_type
BASE_TEMPLATE_PATH = 'packages/ppas/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -153,7 +156,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
"Connection to the server has been lost."
)
)
self.template_path = 'packages/ppas/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
sql = render_template(

View File

@ -0,0 +1,6 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_namespace nsp
WHERE nspparent = {{scid}}::oid
AND nspobjecttype = 0
AND nspcompoundtrigger = false

View File

@ -0,0 +1,5 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_namespace nsp
WHERE nspparent = {{scid}}::oid
AND nspobjecttype = 0;

View File

@ -64,7 +64,9 @@ class SequenceModule(SchemaChildModule):
"""
Generate the sequence node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=SequenceView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -91,6 +93,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Sequence"
node_icon = "icon-%s" % node_type
BASE_TEMPLATE_PATH = 'sequences/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -148,7 +151,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
self.datistemplate = self.manager.db_info[
kwargs['did']]['datistemplate']
self.template_path = 'sequences/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version
)
self.acl = ['r', 'w', 'U']

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_class cl
WHERE
relkind = 'S'
{% if scid %}
AND relnamespace = {{scid|qtLiteral(conn)}}::oid
{% endif %}

View File

@ -70,7 +70,9 @@ class SynonymModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=SynonymView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -148,6 +150,7 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Synonym"
BASE_TEMPLATE_PATH = 'synonyms/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -216,7 +219,7 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
kwargs['did']]['datistemplate']
# we will set template path for sql scripts
self.template_path = 'synonyms/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,4 @@
SELECT COUNT(*)
FROM pg_catalog.pg_synonym s
JOIN pg_catalog.pg_namespace ns ON s.synnamespace = ns.oid
AND s.synnamespace = {{scid}}::oid

View File

@ -72,7 +72,9 @@ class TableModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=BaseTableView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):

View File

@ -72,9 +72,13 @@ class ColumnsModule(CollectionNodeModule):
Generate the collection node
"""
assert ('tid' in kwargs or 'vid' in kwargs)
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
if self.has_nodes(sid, did, scid=scid,
tid=kwargs.get('tid', None),
vid=kwargs.get('vid', None),
base_template_path=ColumnsView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
@property
def script_load(self):
@ -159,6 +163,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
node_type = blueprint.node_type
node_label = "Column"
BASE_TEMPLATE_PATH = 'columns/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -207,7 +212,7 @@ class ColumnsView(PGChildNodeView, DataTypeReader):
self.qtTypeIdent = driver.qtTypeIdent
# Set the template path for the SQL scripts
self.template_path = 'columns/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
# Allowed ACL for column 'Select/Update/Insert/References'

View File

@ -105,9 +105,13 @@ class CompoundTriggerModule(CollectionNodeModule):
Generate the collection node
"""
assert ('tid' in kwargs or 'vid' in kwargs)
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
if self.has_nodes(
sid, did, scid=scid, tid=kwargs.get('tid', None),
vid=kwargs.get('vid', None),
base_template_path=CompoundTriggerView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
@property
def script_load(self):
@ -216,6 +220,7 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Compound Trigger"
BASE_TEMPLATE_PATH = 'compound_triggers/sql/{0}/#{1}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -278,7 +283,7 @@ class CompoundTriggerView(PGChildNodeView, SchemaDiffObjectCompare):
)
# we will set template path for sql scripts
self.template_path = 'compound_triggers/sql/{0}/#{1}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.server_type, self.manager.version)
# Store server type
self.server_type = self.manager.server_type

View File

@ -103,9 +103,13 @@ class IndexesModule(CollectionNodeModule):
Generate the collection node
"""
assert ('tid' in kwargs or 'vid' in kwargs)
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
if self.has_nodes(sid, did, scid=scid,
tid=kwargs.get('tid', None),
vid=kwargs.get('vid', None),
base_template_path=IndexesView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
@property
def script_load(self):
@ -194,6 +198,7 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Index"
BASE_TEMPLATE_PATH = 'indexes/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -252,8 +257,7 @@ class IndexesView(PGChildNodeView, SchemaDiffObjectCompare):
)
# we will set template path for sql scripts
self.template_path = compile_template_path(
'indexes/sql/',
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version
)

View File

@ -60,14 +60,18 @@ class RowSecurityModule(CollectionNodeModule):
self.min_ver = 90500
self.max_ver = None
def get_nodes(self, **kwargs):
def get_nodes(self, gid, sid, did, scid, **kwargs):
"""
Generate the collection node
"""
assert ('tid' in kwargs or 'vid' in kwargs)
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
if self.has_nodes(
sid, did, scid=scid, tid=kwargs.get('tid', None),
vid=kwargs.get('vid', None),
base_template_path=RowSecurityView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
@property
def node_inode(self):
@ -148,6 +152,7 @@ class RowSecurityView(PGChildNodeView):
node_type = blueprint.node_type
node_label = "RLS Policy"
BASE_TEMPLATE_PATH = 'row_security_policies/sql/#{0}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -205,7 +210,7 @@ class RowSecurityView(PGChildNodeView):
'tables/sql',
self.manager.version
)
self.template_path = 'row_security_policies/sql/#{0}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version)
return f(*args, **kwargs)

View File

@ -80,9 +80,13 @@ class RuleModule(CollectionNodeModule):
Generate the collection node
"""
assert ('tid' in kwargs or 'vid' in kwargs)
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
if self.has_nodes(sid, did, scid=scid,
tid=kwargs.get('tid', None),
vid=kwargs.get('vid', None),
base_template_path=RuleView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
@property
def node_inode(self):
@ -150,6 +154,7 @@ class RuleView(PGChildNodeView, SchemaDiffObjectCompare):
"""
node_type = blueprint.node_type
node_label = "Rule"
BASE_TEMPLATE_PATH = 'rules/sql'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -197,7 +202,7 @@ class RuleView(PGChildNodeView, SchemaDiffObjectCompare):
self.manager = get_driver(
PG_DEFAULT_DRIVER).connection_manager(kwargs['sid'])
self.conn = self.manager.connection(did=kwargs['did'])
self.template_path = 'rules/sql'
self.template_path = self.BASE_TEMPLATE_PATH
self.table_template_path = compile_template_path(
'tables/sql',
self.manager.version

View File

@ -0,0 +1,9 @@
SELECT COUNT(*)
FROM pg_catalog.pg_attribute att
WHERE
att.attrelid = {{ tid|qtLiteral(conn) }}::oid
{### To show system objects ###}
{% if not showsysobj %}
AND att.attnum > 0
{% endif %}
AND att.attisdropped IS FALSE

View File

@ -0,0 +1,5 @@
SELECT COUNT(*)
FROM pg_catalog.pg_trigger t
WHERE NOT tgisinternal
AND tgrelid = {{tid}}::OID
AND tgpackageoid != 0

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_index idx
JOIN pg_catalog.pg_class cls ON cls.oid=indexrelid
LEFT JOIN pg_catalog.pg_depend dep ON (dep.classid = cls.tableoid AND dep.objid = cls.oid AND dep.refobjsubid = '0' AND dep.refclassid=(SELECT oid FROM pg_catalog.pg_class WHERE relname='pg_constraint') AND dep.deptype='i')
LEFT OUTER JOIN pg_catalog.pg_constraint con ON (con.tableoid = dep.refclassid AND con.oid = dep.refobjid)
WHERE indrelid = {{tid}}::OID
AND conname is NULL

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_policy pl
WHERE
{% if tid %}
pl.polrelid = {{ tid }}
{% endif %}

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM
pg_catalog.pg_rewrite rw
WHERE
{% if tid %}
rw.ev_class = {{ tid }}
{% endif %}

View File

@ -0,0 +1,4 @@
SELECT COUNT(*)
FROM pg_catalog.pg_class rel
WHERE rel.relkind IN ('r','s','t','p') AND rel.relnamespace = {{ scid }}::oid
AND NOT rel.relispartition;

View File

@ -0,0 +1,4 @@
SELECT COUNT(*)
FROM pg_catalog.pg_trigger t
WHERE NOT tgisinternal
AND tgrelid = {{tid}}::OID

View File

@ -0,0 +1,5 @@
SELECT COUNT(*)
FROM pg_catalog.pg_trigger t
WHERE NOT tgisinternal
AND tgrelid = {{tid}}::OID
AND tgpackageoid = 0

View File

@ -0,0 +1,4 @@
SELECT COUNT(*)
FROM pg_catalog.pg_trigger t
WHERE NOT tgisinternal
AND tgrelid = {{tid}}::OID

View File

@ -101,9 +101,13 @@ class TriggerModule(CollectionNodeModule):
Generate the collection node
"""
assert ('tid' in kwargs or 'vid' in kwargs)
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
if self.has_nodes(sid, did, scid=scid,
tid=kwargs.get('tid', None),
vid=kwargs.get('vid', None),
base_template_path=TriggerView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(
kwargs['tid'] if 'tid' in kwargs else kwargs['vid']
)
@property
def script_load(self):
@ -213,6 +217,7 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
node_type = blueprint.node_type
node_label = "Trigger"
BASE_TEMPLATE_PATH = 'triggers/sql/{0}/#{1}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -266,7 +271,7 @@ class TriggerView(PGChildNodeView, SchemaDiffObjectCompare):
'tables/sql',
self.manager.version
)
self.template_path = 'triggers/sql/{0}/#{1}#'.format(
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.server_type, self.manager.version)
self.trigger_function_template_path = \

View File

@ -90,6 +90,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
node_label = "Table"
pattern = '\n{2,}'
double_newline = '\n\n'
BASE_TEMPLATE_PATH = 'tables/sql/#{0}#'
@staticmethod
def check_precondition(f):

View File

@ -71,7 +71,9 @@ class TypeModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(sid, did, scid=scid,
base_template_path=TypeView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -179,6 +181,7 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
node_type = blueprint.node_type
icon_str = "icon-%s"
BASE_TEMPLATE_PATH = 'types/{0}/sql/#{1}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -238,12 +241,8 @@ class TypeView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
# Declare allows acl on type
self.acl = ['U']
self.template_path = "/".join([
'types',
self.manager.server_type,
'sql',
'#{0}#'
]).format(self.manager.version)
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.server_type, self.manager.version)
return f(*args, **kwargs)

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_type t
LEFT OUTER JOIN pg_catalog.pg_class ct ON ct.oid=t.typrelid AND ct.relkind <> 'c'
WHERE t.typtype != 'd' AND t.typname NOT LIKE E'\\_%' AND t.typnamespace = {{scid}}::oid
{% if not showsysobj %}
AND ct.oid is NULL
{% endif %}

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_type t
LEFT OUTER JOIN pg_catalog.pg_class ct ON ct.oid=t.typrelid AND ct.relkind <> 'c'
WHERE t.typtype != 'd' AND t.typname NOT LIKE E'\\_%' AND t.typnamespace = {{scid}}::oid
{% if not showsysobj %}
AND ct.oid is NULL
{% endif %}

View File

@ -91,7 +91,10 @@ class ViewModule(SchemaChildModule):
"""
Generate the collection node
"""
yield self.generate_browser_collection_node(scid)
if self.has_nodes(
sid, did, scid, base_template_path=ViewNode.BASE_TEMPLATE_PATH +
'/' + ViewNode._SQL_PREFIX):
yield self.generate_browser_collection_node(scid)
@property
def script_load(self):
@ -216,6 +219,15 @@ class MViewModule(ViewModule):
self.min_ver = 90300
self.max_ver = None
def get_nodes(self, gid, sid, did, scid):
"""
Generate the collection node
"""
if self.has_nodes(
sid, did, scid, base_template_path=MViewNode.BASE_TEMPLATE_PATH +
'/' + MViewNode._SQL_PREFIX):
yield self.generate_browser_collection_node(scid)
view_blueprint = ViewModule(__name__)
mview_blueprint = MViewModule(__name__)
@ -242,12 +254,8 @@ def check_precondition(f):
kwargs['sid']
)
self.conn = self.manager.connection(did=kwargs['did'])
# Set template path for sql scripts
if self.manager.server_type == 'ppas':
_temp = self.ppas_template_path(self.manager.version)
else:
_temp = self.pg_template_path(self.manager.version)
self.template_path = self.template_initial + '/' + _temp
self.template_path = self.BASE_TEMPLATE_PATH.format(
self.manager.server_type, self.manager.version)
self.column_template_path = 'columns/sql/#{0}#'.format(
self.manager.version)
@ -327,6 +335,7 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
_SQL_PREFIX = 'sql/'
_ALLOWED_PRIVS_JSON = 'sql/allowed_privs.json'
PROPERTIES_PATH = 'sql/{0}/#{1}#/properties.sql'
BASE_TEMPLATE_PATH = 'views/{0}/#{1}#'
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -377,23 +386,8 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
self.manager = None
self.conn = None
self.template_path = None
self.template_initial = 'views'
self.allowed_acls = []
@staticmethod
def ppas_template_path(ver):
"""
Returns the template path for PPAS servers.
"""
return 'ppas/#{0}#'.format(ver)
@staticmethod
def pg_template_path(ver):
"""
Returns the template path for PostgreSQL servers.
"""
return 'pg/#{0}#'.format(ver)
@check_precondition
def list(self, gid, sid, did, scid):
"""
@ -1797,6 +1791,7 @@ class MViewNode(ViewNode, VacuumSettings):
node_type = mview_blueprint.node_type
operations = mview_operations
TOAST_STR = 'toast.'
BASE_TEMPLATE_PATH = 'mviews/{0}/#{1}#'
def __init__(self, *args, **kwargs):
"""
@ -1805,7 +1800,6 @@ class MViewNode(ViewNode, VacuumSettings):
super().__init__(*args, **kwargs)
self.template_initial = 'mviews'
self.allowed_acls = []
@staticmethod

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_class c
WHERE
c.relkind = 'm'
{% if scid %}
AND c.relnamespace = {{scid}}::oid
{% endif %}

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_class c
WHERE
c.relkind = 'm'
{% if scid %}
AND c.relnamespace = {{scid}}::oid
{% endif %}

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_class c
WHERE
c.relkind = 'v'
{% if scid %}
AND c.relnamespace = {{scid}}::oid
{% endif %}

View File

@ -0,0 +1,7 @@
SELECT COUNT(*)
FROM pg_catalog.pg_class c
WHERE
c.relkind = 'v'
{% if scid %}
AND c.relnamespace = {{scid}}::oid
{% endif %}

View File

@ -74,7 +74,10 @@ class SubscriptionModule(CollectionNodeModule):
sid: Server ID
did: Database Id
"""
yield self.generate_browser_collection_node(did)
if self.has_nodes(
sid, did,
base_template_path=SubscriptionView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(did)
@property
def node_inode(self):
@ -176,6 +179,7 @@ class SubscriptionView(PGChildNodeView, SchemaDiffObjectCompare):
_NOT_FOUND_PUB_INFORMATION = \
gettext("Could not find the subscription information.")
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = "subscriptions/sql/#{0}#"
parent_ids = [
{'type': 'int', 'id': 'gid'},
@ -232,7 +236,7 @@ class SubscriptionView(PGChildNodeView, SchemaDiffObjectCompare):
self.conn = self.manager.connection(did=kwargs['did'])
# Set the template path for the SQL scripts
self.template_path = (
"subscriptions/sql/#{0}#".format(self.manager.version)
self.BASE_TEMPLATE_PATH.format(self.manager.version)
)
return f(*args, **kwargs)

View File

@ -0,0 +1,3 @@
SELECT COUNT(*)
FROM pg_catalog.pg_subscription sub
WHERE sub.subdbid = {{ did }}

View File

@ -79,7 +79,10 @@ class ResourceGroupModule(CollectionNodeModule):
gid: Server Group ID
sid: Server ID
"""
yield self.generate_browser_collection_node(sid)
if self.has_nodes(
sid, None,
base_template_path=ResourceGroupView.BASE_TEMPLATE_PATH):
yield self.generate_browser_collection_node(sid)
@property
def node_inode(self):
@ -165,6 +168,7 @@ class ResourceGroupView(NodeView):
"""
node_type = blueprint.node_type
BASE_TEMPLATE_PATH = 'resource_groups/sql/#{0}#'
_PROPERTIES_SQL = 'properties.sql'
_CREATE_SQL = 'create.sql'
_UPDATE_SQL = 'update.sql'
@ -236,7 +240,7 @@ class ResourceGroupView(NodeView):
"Connection to the server has been lost."
)
)
self.sql_path = 'resource_groups/sql/#{0}#'.format(
self.sql_path = self.BASE_TEMPLATE_PATH.format(
self.manager.version
)
return f(*args, **kwargs)

View File

@ -0,0 +1,2 @@
SELECT COUNT(*)
FROM edb_resource_group

View File

@ -373,6 +373,7 @@ class PGChildNodeView(NodeView):
_NODE_SQL = 'node.sql'
_NODES_SQL = 'nodes.sql'
_COUNT_SQL = 'count.sql'
_CREATE_SQL = 'create.sql'
_UPDATE_SQL = 'update.sql'
_ALTER_SQL = 'alter.sql'

View File

@ -151,10 +151,10 @@ export class ManageTreeNodes {
await fill(treeData);
if (node.children.length > 0) res(node.children);
else {
res(null);
res([]);
if (node.data && node.data._type == 'server' && node.data.connected) {
Notify.info(gettext('Server children are not available.'
+' Please check these nodes are not hidden through the preferences setting `Browser > Nodes`.'));
+' Please check these nodes are not hidden through the preferences setting `Browser > Nodes`.'), null);
}
}