diff --git a/web/pgadmin/browser/server_groups/servers/databases/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/__init__.py index e4bdc5d..69e9d81 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/__init__.py @@ -22,6 +22,7 @@ from config import PG_DEFAULT_DRIVER from functools import wraps import re + class DatabaseModule(CollectionNodeModule): NODE_TYPE = 'database' COLLECTION_LABEL = _("Databases") @@ -853,4 +854,38 @@ class DatabaseView(PGChildNodeView): return ajax_response(response=SQL) + @check_precondition() + def dependents(self, gid, sid, did): + """ + This function get the dependents and return ajax response + for the tablespace node. + + Args: + gid: Server Group ID + sid: Server ID + did: Database ID + """ + dependents_result = self.get_dependents(self.conn, did) + return ajax_response( + response=dependents_result, + status=200 + ) + + @check_precondition() + def dependencies(self, gid, sid, did): + """ + This function get the dependencies and return ajax response + for the tablespace node. + + Args: + gid: Server Group ID + sid: Server ID + did: Database ID + """ + dependencies_result = self.get_dependencies(self.conn, did) + return ajax_response( + response=dependencies_result, + status=200 + ) + DatabaseView.register_node_view(blueprint) diff --git a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js index 655fd9d..220265a 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js +++ b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js @@ -46,6 +46,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { parent_type: 'server', type: 'database', hasSQL: true, + hasDepends: true, canDrop: true, label: '{{ _('Database') }}', node_image: function() { diff --git a/web/pgadmin/browser/server_groups/servers/roles/__init__.py b/web/pgadmin/browser/server_groups/servers/roles/__init__.py index bb726f9..317c343 100644 --- a/web/pgadmin/browser/server_groups/servers/roles/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/roles/__init__.py @@ -6,7 +6,7 @@ # This software is released under the PostgreSQL Licence # ########################################################################## -from flask import render_template, request, jsonify +from flask import render_template, request, jsonify, current_app from flask.ext.babel import gettext as _ from pgadmin.utils.ajax import make_json_response, \ make_response as ajax_response, precondition_required, \ @@ -822,11 +822,149 @@ rolmembership:{ @check_precondition() def dependencies(self, gid, sid, rid): - return not_implemented() + """ + This function get the dependencies and return ajax response + for the role. + + Args: + gid: Server Group ID + sid: Server ID + rid: Role ID + """ + dependencies_result = self.get_dependencies(self.conn, rid) + return ajax_response( + response=dependencies_result, + status=200 + ) @check_precondition() def dependents(self, gid, sid, rid): - return not_implemented() + """ + This function get the dependents and return ajax response + for the role. + + Args: + gid: Server Group ID + sid: Server ID + rid: Role ID + """ + dependents_result = self.get_dependents(self.conn, sid, rid) + return ajax_response( + response=dependents_result, + status=200 + ) + + def get_dependents(self, conn, sid, rid): + """ + This function is used to fetch the dependents for the selected node. + + Args: + conn: Connection object + sid: Server Id + rid: Role Id. + + Returns: Dictionary of dependents for the selected node. + """ + + # Dictionary for the object types + types = { + # None specified special handling for this type + 'r': 'table', + 'i': None, + 'S': 'sequence', + 'v': 'view', + 'x': 'external_table', + 'p': 'function', + 'n': 'schema', + 'y': 'type', + 'd': 'domain', + 'T': 'trigger_function', + 'C': 'conversion', + 'o': None + } + + query = render_template("/".join([self.sql_path, 'dependents.sql']), + fetch_database=True, rid=rid) + status, db_result = self.conn.execute_dict(query) + if not status: + current_app.logger.error(db_result) + + dependents = list() + + # Get the server manager + manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid) + + for db_row in db_result['rows']: + oid = db_row['datdba'] + if db_row['type'] == 'd': + if rid == oid: + dependents.append({'type': 'database', 'name': '', 'field': db_row['datname']}) + else: + dependents.append({'type': 'tablespace', 'name': db_row['datname'], 'field': ''}) + + # If connection to the database is not allowed then continue + # with the next database + if not db_row['datallowconn']: + continue + + # Get the connection from the manager for the specified database. + # Check the connect status and if it is not connected then create + # a new connection to run the query and fetch the dependents. + is_connected = True + try: + temp_conn = manager.connection(db_row['datname']) + is_connected = temp_conn.connected() + if not is_connected: + temp_conn.connect() + except Exception as e: + current_app.logger.exception(e) + + if temp_conn.connected(): + query = render_template("/".join([self.sql_path, 'dependents.sql']), + fetch_dependents=True, rid=rid, lastsysoid=db_row['datlastsysoid']) + + status, result = temp_conn.execute_dict(query) + if not status: + current_app.logger.error(result) + + for row in result['rows']: + rel_name = row['nspname'] + if rel_name is not None: + rel_name += '.' + + if rel_name is None: + rel_name = row['relname'] + else: + rel_name += row['relname'] + + type_name = '' + type_str = row['relkind'] + # Fetch the type name from the dictionary + # if type is not present in the types dictionary then + # we will continue and not going to add it. + if type_str[0] in types: + + # if type is present in the types dictionary, but it's + # value is None then it requires special handling. + if types[type_str[0]] is None: + if type_str[0] == 'i': + type_name = 'index' + rel_name = row['indname'] + ' ON ' + rel_name + elif type_str[0] == 'o': + type_name = 'operator' + rel_name = row['relname'] + else: + type_name = types[type_str[0]] + else: + continue + + dependents.append({'type': type_name, 'name': rel_name, 'field': db_row['datname']}) + + # Release only those connections which we have created above. + if not is_connected: + manager.release(db_row['datname']) + + return dependents @check_precondition() def variables(self, gid, sid, rid): diff --git a/web/pgadmin/browser/server_groups/servers/roles/templates/role/js/role.js b/web/pgadmin/browser/server_groups/servers/roles/templates/role/js/role.js index 77a1a22..a6ecfff 100644 --- a/web/pgadmin/browser/server_groups/servers/roles/templates/role/js/role.js +++ b/web/pgadmin/browser/server_groups/servers/roles/templates/role/js/role.js @@ -293,10 +293,13 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backform) { label: '{{ _('Login/Group Role') }}', hasSQL: true, canDrop: true, + hasDepends: true, node_label: function(r) { return r.label; }, node_image: function(r) { + if (r == null || r == undefined) + return 'icon-role'; return (r.can_login ? 'icon-role' : 'icon-group'); }, title: function(d) { diff --git a/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post8_4/dependents.sql b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post8_4/dependents.sql new file mode 100644 index 0000000..581c2e0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post8_4/dependents.sql @@ -0,0 +1,40 @@ +{% if fetch_database %} +SELECT 'd' as type, datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + datdba, datlastsysoid +FROM pg_database db +UNION +SELECT 'M', spcname, null, null, null + FROM pg_tablespace where spcowner= {{rid}}::int +ORDER BY 1, 2 +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid +WHERE cl.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND cl.oid > {{lastsysoid}}::int +UNION ALL SELECT 'n', null, nspname, null + FROM pg_namespace nsp + WHERE nsp.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND nsp.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN typtype='d' THEN 'd' ELSE 'y' END, null, typname, null + FROM pg_type ty + WHERE ty.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND ty.oid > {{lastsysoid}}::int +UNION ALL SELECT 'C', null, conname, null + FROM pg_conversion co + WHERE co.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND co.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN prorettype=2279 THEN 'T' ELSE 'p' END, null, proname, null + FROM pg_proc pr + WHERE pr.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND pr.oid > {{lastsysoid}}::int +UNION ALL SELECT 'o', null, oprname || '('::text || COALESCE(tl.typname, ''::text) || CASE WHEN tl.oid IS NOT NULL + AND tr.oid IS NOT NULL THEN ','::text END || COALESCE(tr.typname, ''::text) || ')'::text, null + FROM pg_operator op + LEFT JOIN pg_type tl ON tl.oid=op.oprleft + LEFT JOIN pg_type tr ON tr.oid=op.oprright + WHERE op.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND op.oid > {{lastsysoid}}::int +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_0/dependents.sql b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_0/dependents.sql new file mode 100644 index 0000000..581c2e0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_0/dependents.sql @@ -0,0 +1,40 @@ +{% if fetch_database %} +SELECT 'd' as type, datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + datdba, datlastsysoid +FROM pg_database db +UNION +SELECT 'M', spcname, null, null, null + FROM pg_tablespace where spcowner= {{rid}}::int +ORDER BY 1, 2 +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid +WHERE cl.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND cl.oid > {{lastsysoid}}::int +UNION ALL SELECT 'n', null, nspname, null + FROM pg_namespace nsp + WHERE nsp.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND nsp.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN typtype='d' THEN 'd' ELSE 'y' END, null, typname, null + FROM pg_type ty + WHERE ty.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND ty.oid > {{lastsysoid}}::int +UNION ALL SELECT 'C', null, conname, null + FROM pg_conversion co + WHERE co.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND co.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN prorettype=2279 THEN 'T' ELSE 'p' END, null, proname, null + FROM pg_proc pr + WHERE pr.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND pr.oid > {{lastsysoid}}::int +UNION ALL SELECT 'o', null, oprname || '('::text || COALESCE(tl.typname, ''::text) || CASE WHEN tl.oid IS NOT NULL + AND tr.oid IS NOT NULL THEN ','::text END || COALESCE(tr.typname, ''::text) || ')'::text, null + FROM pg_operator op + LEFT JOIN pg_type tl ON tl.oid=op.oprleft + LEFT JOIN pg_type tr ON tr.oid=op.oprright + WHERE op.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND op.oid > {{lastsysoid}}::int +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_1/dependents.sql b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_1/dependents.sql new file mode 100644 index 0000000..581c2e0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_1/dependents.sql @@ -0,0 +1,40 @@ +{% if fetch_database %} +SELECT 'd' as type, datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + datdba, datlastsysoid +FROM pg_database db +UNION +SELECT 'M', spcname, null, null, null + FROM pg_tablespace where spcowner= {{rid}}::int +ORDER BY 1, 2 +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid +WHERE cl.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND cl.oid > {{lastsysoid}}::int +UNION ALL SELECT 'n', null, nspname, null + FROM pg_namespace nsp + WHERE nsp.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND nsp.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN typtype='d' THEN 'd' ELSE 'y' END, null, typname, null + FROM pg_type ty + WHERE ty.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND ty.oid > {{lastsysoid}}::int +UNION ALL SELECT 'C', null, conname, null + FROM pg_conversion co + WHERE co.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND co.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN prorettype=2279 THEN 'T' ELSE 'p' END, null, proname, null + FROM pg_proc pr + WHERE pr.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND pr.oid > {{lastsysoid}}::int +UNION ALL SELECT 'o', null, oprname || '('::text || COALESCE(tl.typname, ''::text) || CASE WHEN tl.oid IS NOT NULL + AND tr.oid IS NOT NULL THEN ','::text END || COALESCE(tr.typname, ''::text) || ')'::text, null + FROM pg_operator op + LEFT JOIN pg_type tl ON tl.oid=op.oprleft + LEFT JOIN pg_type tr ON tr.oid=op.oprright + WHERE op.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND op.oid > {{lastsysoid}}::int +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_4/dependents.sql b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_4/dependents.sql new file mode 100644 index 0000000..e198ad1 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/roles/templates/role/sql/post9_4/dependents.sql @@ -0,0 +1,40 @@ +{% if fetch_database %} +SELECT 'd' as type, datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + datdba, datlastsysoid +FROM pg_database db +UNION +SELECT 'M', spcname, null, null, null + FROM pg_tablespace where spcowner={{rid}}::int +ORDER BY 1, 2 +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid +WHERE cl.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND cl.oid > {{lastsysoid}}::int +UNION ALL SELECT 'n', null, nspname, null + FROM pg_namespace nsp + WHERE nsp.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND nsp.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN typtype='d' THEN 'd' ELSE 'y' END, null, typname, null + FROM pg_type ty + WHERE ty.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND ty.oid > {{lastsysoid}}::int +UNION ALL SELECT 'C', null, conname, null + FROM pg_conversion co + WHERE co.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND co.oid > {{lastsysoid}}::int +UNION ALL SELECT CASE WHEN prorettype=2279 THEN 'T' ELSE 'p' END, null, proname, null + FROM pg_proc pr + WHERE pr.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND pr.oid > {{lastsysoid}}::int +UNION ALL SELECT 'o', null, oprname || '('::text || COALESCE(tl.typname, ''::text) || CASE WHEN tl.oid IS NOT NULL + AND tr.oid IS NOT NULL THEN ','::text END || COALESCE(tr.typname, ''::text) || ')'::text, null + FROM pg_operator op + LEFT JOIN pg_type tl ON tl.oid=op.oprleft + LEFT JOIN pg_type tr ON tr.oid=op.oprright + WHERE op.oid IN (SELECT objid FROM pg_shdepend WHERE refobjid={{rid}}::oid) AND op.oid > {{lastsysoid}}::int +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py index 3d6ade2..b79cd8a 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py @@ -569,5 +569,149 @@ class TablespaceView(PGChildNodeView): return ajax_response(response=result) + @check_precondition + def dependencies(self, gid, sid, tsid): + """ + This function get the dependencies and return ajax response + for the tablespace node. + + Args: + gid: Server Group ID + sid: Server ID + tsid: Tablespace ID + """ + dependencies_result = self.get_dependencies(self.conn, tsid) + return ajax_response( + response=dependencies_result, + status=200 + ) + + @check_precondition + def dependents(self, gid, sid, tsid): + """ + This function get the dependents and return ajax response + for the tablespace node. + + Args: + gid: Server Group ID + sid: Server ID + tsid: Tablespace ID + """ + dependents_result = self.get_dependents(self.conn, sid, tsid) + return ajax_response( + response=dependents_result, + status=200 + ) + + def get_dependents(self, conn, sid, tsid): + """ + This function is used to fetch the dependents for the selected node. + + Args: + conn: Connection object + sid: Server Id + tsid: Tablespace ID + + Returns: Dictionary of dependents for the selected node. + """ + # Dictionary for the object types + types = { + # None specified special handling for this type + 'r': 'table', + 'i': None, + 'S': 'sequence', + 'v': 'view', + 'x': 'external_table', + 'p': 'function', + 'n': 'schema', + 'y': 'type', + 'd': 'domain', + 'T': 'trigger_function', + 'C': 'conversion', + 'o': None + } + + # Fetching databases with CONNECT privileges status. + query = render_template("/".join([self.template_path, 'dependents.sql']), fetch_database=True) + status, db_result = self.conn.execute_dict(query) + if not status: + current_app.logger.error(db_result) + + dependents = list() + + # Get the server manager + manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(sid) + + for db_row in db_result['rows']: + oid = db_row['dattablespace'] + + # Append all the databases to the dependents list if oid is same + if tsid == oid: + dependents.append({ + 'type': 'database', 'name': '', 'field': db_row['datname'] + }) + + # If connection to the database is not allowed then continue + # with the next database + if not db_row['datallowconn']: + continue + + # Get the connection from the manager for the specified database. + # Check the connect status and if it is not connected then create + # a new connection to run the query and fetch the dependents. + is_connected = True + try: + temp_conn = manager.connection(db_row['datname']) + is_connected = temp_conn.connected() + if not is_connected: + temp_conn.connect() + except Exception as e: + current_app.logger.exception(e) + + if temp_conn.connected(): + query = render_template("/".join([self.template_path, 'dependents.sql']), + fetch_dependents=True, tsid=tsid) + status, result = temp_conn.execute_dict(query) + if not status: + current_app.logger.error(result) + + for row in result['rows']: + rel_name = row['nspname'] + if rel_name is not None: + rel_name += '.' + + if rel_name is None: + rel_name = row['relname'] + else: + rel_name += row['relname'] + + type_name = '' + type_str = row['relkind'] + # Fetch the type name from the dictionary + # if type is not present in the types dictionary then + # we will continue and not going to add it. + if type_str[0] in types: + + # if type is present in the types dictionary, but it's + # value is None then it requires special handling. + if types[type_str[0]] is None: + if type_str[0] == 'i': + type_name = 'index' + rel_name = row['indname'] + ' ON ' + rel_name + elif type_str[0] == 'o': + type_name = 'operator' + rel_name = row['relname'] + else: + type_name = types[type_str[0]] + else: + continue + + dependents.append({'type': type_name, 'name': rel_name, 'field': db_row['datname']}) + + # Release only those connections which we have created above. + if not is_connected: + manager.release(db_row['datname']) + + return dependents TablespaceView.register_node_view(blueprint) diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js index 33985a7..a304c58 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js @@ -48,6 +48,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { label: '{{ _('Tablespace') }}', hasSQL: true, canDrop: true, + hasDepends: true, Init: function() { /* Avoid mulitple registration of menus */ if (this.initialized) diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/dependents.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/dependents.sql new file mode 100644 index 0000000..52ddc76 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/dependents.sql @@ -0,0 +1,20 @@ +{% if fetch_database %} +SELECT datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + dattablespace +FROM pg_database db +ORDER BY datname +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid, +pg_database WHERE datname = current_database() AND +(cl.reltablespace = {{tsid}}::oid OR (cl.reltablespace=0 AND dattablespace = {{tsid}}::oid)) +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/dependents.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/dependents.sql new file mode 100644 index 0000000..52ddc76 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/dependents.sql @@ -0,0 +1,20 @@ +{% if fetch_database %} +SELECT datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + dattablespace +FROM pg_database db +ORDER BY datname +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid, +pg_database WHERE datname = current_database() AND +(cl.reltablespace = {{tsid}}::oid OR (cl.reltablespace=0 AND dattablespace = {{tsid}}::oid)) +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/pre_9.1/dependents.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/pre_9.1/dependents.sql new file mode 100644 index 0000000..52ddc76 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/pre_9.1/dependents.sql @@ -0,0 +1,20 @@ +{% if fetch_database %} +SELECT datname, + datallowconn AND pg_catalog.has_database_privilege(datname, 'CONNECT') AS datallowconn, + dattablespace +FROM pg_database db +ORDER BY datname +{% endif %} + +{% if fetch_dependents %} +SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, + COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname +FROM pg_class cl +JOIN pg_namespace cln ON cl.relnamespace=cln.oid +LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid +LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid +LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid, +pg_database WHERE datname = current_database() AND +(cl.reltablespace = {{tsid}}::oid OR (cl.reltablespace=0 AND dattablespace = {{tsid}}::oid)) +ORDER BY 1,2,3 +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/templates/depends/sql/9.1_plus/dependents.sql b/web/pgadmin/browser/server_groups/servers/templates/depends/sql/9.1_plus/dependents.sql new file mode 100644 index 0000000..614694b --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/templates/depends/sql/9.1_plus/dependents.sql @@ -0,0 +1,90 @@ +{% if fetch_dependencies %} +SELECT DISTINCT dep.deptype, dep.refclassid, cl.relkind, ad.adbin, ad.adsrc, + CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind || COALESCE(dep.refobjsubid::text, '') + WHEN tg.oid IS NOT NULL THEN 'T'::text + WHEN ty.oid IS NOT NULL THEN 'y'::text + WHEN ns.oid IS NOT NULL THEN 'n'::text + WHEN pr.oid IS NOT NULL THEN 'p'::text + WHEN la.oid IS NOT NULL THEN 'l'::text + WHEN rw.oid IS NOT NULL THEN 'R'::text + WHEN co.oid IS NOT NULL THEN 'C'::text || contype + WHEN ad.oid IS NOT NULL THEN 'A'::text ELSE '' + END AS type, + COALESCE(coc.relname, clrw.relname) AS ownertable, + CASE WHEN cl.relname IS NOT NULL OR att.attname IS NOT NULL THEN cl.relname || '.' || att.attname + ELSE COALESCE(cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname) + END AS refname, + COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname) AS nspname +FROM pg_depend dep +LEFT JOIN pg_class cl ON dep.refobjid=cl.oid +LEFT JOIN pg_attribute att ON dep.refobjid=att.attrelid AND dep.refobjsubid=att.attnum +LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid +LEFT JOIN pg_proc pr ON dep.refobjid=pr.oid +LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid +LEFT JOIN pg_trigger tg ON dep.refobjid=tg.oid +LEFT JOIN pg_type ty ON dep.refobjid=ty.oid +LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid +LEFT JOIN pg_constraint co ON dep.refobjid=co.oid +LEFT JOIN pg_class coc ON co.conrelid=coc.oid +LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid +LEFT JOIN pg_rewrite rw ON dep.refobjid=rw.oid +LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class +LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid +LEFT JOIN pg_language la ON dep.refobjid=la.oid +LEFT JOIN pg_namespace ns ON dep.refobjid=ns.oid +LEFT JOIN pg_attrdef ad ON ad.adrelid=att.attrelid AND ad.adnum=att.attnum +{{where_clause}} AND +refclassid IN ( SELECT oid FROM pg_class WHERE relname IN + ('pg_class', 'pg_constraint', 'pg_conversion', 'pg_language', 'pg_proc', 'pg_rewrite', 'pg_namespace', + 'pg_trigger', 'pg_type', 'pg_attrdef', 'pg_event_trigger')) +ORDER BY refclassid, cl.relkind +{% endif %} + +{% if fetch_role_dependencies %} +SELECT rolname AS refname, refclassid, deptype +FROM pg_shdepend dep +LEFT JOIN pg_roles r ON refclassid=1260 AND refobjid=r.oid +{{where_clause}} ORDER BY 1 +{% endif %} + +{% if fetch_dependents %} +SELECT DISTINCT dep.deptype, dep.classid, cl.relkind, ad.adbin, ad.adsrc, + CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind || COALESCE(dep.objsubid::text, '') + WHEN tg.oid IS NOT NULL THEN 'T'::text + WHEN ty.oid IS NOT NULL THEN 'y'::text + WHEN ns.oid IS NOT NULL THEN 'n'::text + WHEN pr.oid IS NOT NULL THEN 'p'::text + WHEN la.oid IS NOT NULL THEN 'l'::text + WHEN rw.oid IS NOT NULL THEN 'R'::text + WHEN co.oid IS NOT NULL THEN 'C'::text || contype + WHEN ad.oid IS NOT NULL THEN 'A'::text ELSE '' + END AS type, + COALESCE(coc.relname, clrw.relname) AS ownertable, + CASE WHEN cl.relname IS NOT NULL AND att.attname IS NOT NULL THEN cl.relname || '.' || att.attname + ELSE COALESCE(cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname) + END AS refname, + COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname) AS nspname +FROM pg_depend dep +LEFT JOIN pg_class cl ON dep.objid=cl.oid +LEFT JOIN pg_attribute att ON dep.objid=att.attrelid AND dep.objsubid=att.attnum +LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid +LEFT JOIN pg_proc pr ON dep.objid=pr.oid +LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid +LEFT JOIN pg_trigger tg ON dep.objid=tg.oid +LEFT JOIN pg_type ty ON dep.objid=ty.oid +LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid +LEFT JOIN pg_constraint co ON dep.objid=co.oid +LEFT JOIN pg_class coc ON co.conrelid=coc.oid +LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid +LEFT JOIN pg_rewrite rw ON dep.objid=rw.oid +LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class +LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid +LEFT JOIN pg_language la ON dep.objid=la.oid +LEFT JOIN pg_namespace ns ON dep.objid=ns.oid +LEFT JOIN pg_attrdef ad ON ad.oid=dep.objid +{{where_clause}} AND +classid IN ( SELECT oid FROM pg_class WHERE relname IN + ('pg_class', 'pg_constraint', 'pg_conversion', 'pg_language', 'pg_proc', 'pg_rewrite', 'pg_namespace', + 'pg_trigger', 'pg_type', 'pg_attrdef', 'pg_event_trigger')) +ORDER BY classid, cl.relkind +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index ccf3217..3aac518 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -94,7 +94,7 @@ function(require, $, _, S, Bootstrap, pgAdmin, alertify, CodeMirror) { width: 500, isCloseable: false, isPrivate: true, - content: '
Depedencies pane
', + content: 'Dependent pane
', + content: '