mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-10-12 16:11:59 -05:00
Add Packages as a synonym target type. Fixes #1611
This commit is contained in:
1 parent
821f70663e
commit
a113b43a1f
9 files changed
+216
-93
No files matched your search
@@ -195,7 +195,9 @@ class SynonymView(PGChildNodeView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# we will set template path for sql scripts
|
# we will set template path for sql scripts
|
||||||
self.template_path = 'synonym/sql/9.1_plus'
|
self.template_path = 'synonym/sql/'
|
||||||
|
self.template_path += '9.5_plus' if self.manager.version >= 90500 \
|
||||||
|
else '9.1_plus'
|
||||||
|
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
+82
-84
@@ -90,91 +90,89 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
|
|||||||
disabled: true , control: 'node-list-by-name',
|
disabled: true , control: 'node-list-by-name',
|
||||||
node: 'schema'
|
node: 'schema'
|
||||||
},{
|
},{
|
||||||
type: 'nested', control: 'fieldset', label: '{{ _('Definition') }}',
|
id: 'targettype', label:'{{ _('Target type') }}', cell: 'string',
|
||||||
schema:[{
|
disabled: 'inSchema', group: '{{ _('Definition') }}',
|
||||||
id: 'targettype', label:'{{ _('Target Type') }}', cell: 'string',
|
select2: { width: "50%", allowClear: false },
|
||||||
disabled: 'inSchema', group: '{{ _('Definition') }}',
|
options: function(obj) {
|
||||||
select2: { width: "50%", allowClear: false },
|
return [
|
||||||
options: function(obj) {
|
{label: "Table", value: "r"},
|
||||||
return [
|
{label: "Sequence", value: "S"},
|
||||||
{label: "Table", value: "r"},
|
{label: "View", value: "v"},
|
||||||
{label: "Sequence", value: "S"},
|
{label: "Function", value: "f"},
|
||||||
{label: "View", value: "v"},
|
{label: "Procedure", value: "p"},
|
||||||
{label: "Function", value: "f"},
|
{label: "Package", value: "P"},
|
||||||
{label: "Procedure", value: "p"},
|
{label: "Public Synonym", value: "s"}
|
||||||
{label: "Public Synonym", value: "s"}
|
]
|
||||||
]
|
},
|
||||||
},
|
control: 'select2'
|
||||||
control: 'select2'
|
|
||||||
},{
|
|
||||||
id: 'synobjschema', label:'{{ _('Target Schema') }}', cell: 'string',
|
|
||||||
type: 'text', mode: ['properties', 'create', 'edit'],
|
|
||||||
group: '{{ _('Definition') }}', deps: ['targettype'],
|
|
||||||
select2: { allowClear: false }, control: 'node-list-by-name',
|
|
||||||
node: 'schema', filter: function(d) {
|
|
||||||
// Exclude PPAS catalogs
|
|
||||||
var exclude_catalogs = ['pg_catalog', 'sys', 'dbo',
|
|
||||||
'pgagent', 'information_schema',
|
|
||||||
'dbms_job_procedure'];
|
|
||||||
return d && _.indexOf(exclude_catalogs, d.label) == -1;
|
|
||||||
},
|
|
||||||
disabled: function(m) {
|
|
||||||
// If tagetType is synonym then disable it
|
|
||||||
if(!m.inSchema.apply(this, [m])) {
|
|
||||||
var is_synonym = (m.get('targettype') == 's');
|
|
||||||
if(is_synonym) {
|
|
||||||
m.set('synobjschema', 'public', {silent: true});
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
},{
|
|
||||||
id: 'synobjname', label:'{{ _('Target Object') }}', cell: 'string',
|
|
||||||
type: 'text', disabled: 'inSchema', group: '{{ _('Definition') }}',
|
|
||||||
deps: ['targettype', 'synobjschema'],
|
|
||||||
control: 'node-ajax-options',
|
|
||||||
options: function(control) {
|
|
||||||
var trgTyp = control.model.get('targettype');
|
|
||||||
var trgSchema = control.model.get('synobjschema');
|
|
||||||
var res = [];
|
|
||||||
|
|
||||||
var node = control.field.get('schema_node'),
|
|
||||||
_url = node.generate_url.apply(
|
|
||||||
node, [
|
|
||||||
null, 'get_target_objects', control.field.get('node_data'), false,
|
|
||||||
control.field.get('node_info') ]);
|
|
||||||
$.ajax({
|
|
||||||
type: 'GET',
|
|
||||||
timeout: 30000,
|
|
||||||
url: _url,
|
|
||||||
cache: false,
|
|
||||||
async: false,
|
|
||||||
data: {"trgTyp" : trgTyp, "trgSchema" : trgSchema},
|
|
||||||
|
|
||||||
// On success return function list from server
|
|
||||||
success: function(result) {
|
|
||||||
res = result.data;
|
|
||||||
return res;
|
|
||||||
},
|
|
||||||
|
|
||||||
// On failure show error appropriate error message to user
|
|
||||||
error: function(xhr, status, error) {
|
|
||||||
try {
|
|
||||||
var err = $.parseJSON(xhr.responseText);
|
|
||||||
if (err.success == 0) {
|
|
||||||
alertify.error(err.errormsg);
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
},{
|
},{
|
||||||
id: 'is_public_synonym', label:'{{ _('Public Synonym?') }}',
|
id: 'synobjschema', label:'{{ _('Target schema') }}', cell: 'string',
|
||||||
|
type: 'text', mode: ['properties', 'create', 'edit'],
|
||||||
|
group: '{{ _('Definition') }}', deps: ['targettype'],
|
||||||
|
select2: { allowClear: false }, control: 'node-list-by-name',
|
||||||
|
node: 'schema', filter: function(d) {
|
||||||
|
// Exclude PPAS catalogs
|
||||||
|
var exclude_catalogs = ['pg_catalog', 'sys', 'dbo',
|
||||||
|
'pgagent', 'information_schema',
|
||||||
|
'dbms_job_procedure'];
|
||||||
|
return d && _.indexOf(exclude_catalogs, d.label) == -1;
|
||||||
|
},
|
||||||
|
disabled: function(m) {
|
||||||
|
// If tagetType is synonym then disable it
|
||||||
|
if(!m.inSchema.apply(this, [m])) {
|
||||||
|
var is_synonym = (m.get('targettype') == 's');
|
||||||
|
if(is_synonym) {
|
||||||
|
m.set('synobjschema', 'public', {silent: true});
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},{
|
||||||
|
id: 'synobjname', label:'{{ _('Target object') }}', cell: 'string',
|
||||||
|
type: 'text', disabled: 'inSchema', group: '{{ _('Definition') }}',
|
||||||
|
deps: ['targettype', 'synobjschema'],
|
||||||
|
control: 'node-ajax-options',
|
||||||
|
options: function(control) {
|
||||||
|
var trgTyp = control.model.get('targettype');
|
||||||
|
var trgSchema = control.model.get('synobjschema');
|
||||||
|
var res = [];
|
||||||
|
|
||||||
|
var node = control.field.get('schema_node'),
|
||||||
|
_url = node.generate_url.apply(
|
||||||
|
node, [
|
||||||
|
null, 'get_target_objects', control.field.get('node_data'), false,
|
||||||
|
control.field.get('node_info') ]);
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
timeout: 30000,
|
||||||
|
url: _url,
|
||||||
|
cache: false,
|
||||||
|
async: false,
|
||||||
|
data: {"trgTyp" : trgTyp, "trgSchema" : trgSchema},
|
||||||
|
|
||||||
|
// On success return function list from server
|
||||||
|
success: function(result) {
|
||||||
|
res = result.data;
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
|
// On failure show error appropriate error message to user
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
try {
|
||||||
|
var err = $.parseJSON(xhr.responseText);
|
||||||
|
if (err.success == 0) {
|
||||||
|
alertify.error(err.errormsg);
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
},{
|
||||||
|
id: 'is_public_synonym', label:'{{ _('Public synonym?') }}',
|
||||||
disabled: true, type: 'switch', mode: ['properties'], cell: 'switch',
|
disabled: true, type: 'switch', mode: ['properties'], cell: 'switch',
|
||||||
options: { onText: 'Yes', offText: 'No', onColor: 'success',
|
options: { onText: 'Yes', offText: 'No', onColor: 'success',
|
||||||
offColor: 'primary', size: 'mini'}
|
offColor: 'primary', size: 'mini'}
|
||||||
|
|||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
{# Below will provide oid for newly created collation #}
|
|
||||||
{% if data %}
|
|
||||||
SELECT c.oid
|
|
||||||
FROM pg_collation c, pg_namespace n
|
|
||||||
WHERE c.collnamespace=n.oid AND
|
|
||||||
n.nspname = {{ data.schema|qtLiteral }} AND
|
|
||||||
c.collname = {{ data.name|qtLiteral }}
|
|
||||||
{% endif %}
|
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
{% set is_public = False %}
|
||||||
|
{% if data.schema == 'public' %}
|
||||||
|
{% set is_public = True %}
|
||||||
|
{% endif %}
|
||||||
|
{% if comment %}
|
||||||
|
-- {% if is_public %}Public{% else %}Private{% endif %} synonym: {% if is_public %}{{ conn|qtIdent(data.name) }};
|
||||||
|
{% else %}{{ conn|qtIdent(data.schema, data.name) }};
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
-- DROP {% if is_public %}PUBLIC {% endif %}SYNONYM {% if is_public %}{{ conn|qtIdent(data.name) }};
|
||||||
|
{% else %}{{ conn|qtIdent(data.schema, data.name) }};
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
CREATE OR REPLACE {% if is_public %}
|
||||||
|
PUBLIC SYNONYM {{ conn|qtIdent(data.name) }}
|
||||||
|
{% else %}
|
||||||
|
SYNONYM {{ conn|qtIdent(data.schema, data.name) }}
|
||||||
|
{% endif %}
|
||||||
|
FOR {{ conn|qtIdent(data.synobjschema, data.synobjname) }};
|
||||||
|
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
{% set is_public = False %}
|
||||||
|
{% if data.schema == 'public' %}
|
||||||
|
{% set is_public = True %}
|
||||||
|
{% endif %}
|
||||||
|
DROP {% if is_public %}
|
||||||
|
PUBLIC SYNONYM {{ conn|qtIdent(data.name) }}{% else %}
|
||||||
|
SYNONYM {{ conn|qtIdent(data.schema, data.name) }}
|
||||||
|
{% endif %};
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
{###########################################}
|
||||||
|
{### If Target Type is Function ###}
|
||||||
|
{###########################################}
|
||||||
|
{% if trgTyp == 'f' %}
|
||||||
|
SELECT DISTINCT proname AS name
|
||||||
|
FROM pg_proc p, pg_namespace n
|
||||||
|
WHERE p.pronamespace = n.oid AND
|
||||||
|
n.nspname = {{ trgSchema|qtLiteral }} AND
|
||||||
|
p.protype = '0'
|
||||||
|
ORDER BY proname;
|
||||||
|
{###########################################}
|
||||||
|
{### If Target Type is Procedure ###}
|
||||||
|
{###########################################}
|
||||||
|
{% elif trgTyp == 'p' %}
|
||||||
|
SELECT DISTINCT proname AS name
|
||||||
|
FROM pg_proc p, pg_namespace n
|
||||||
|
WHERE p.pronamespace = n.oid AND
|
||||||
|
n.nspname = {{ trgSchema|qtLiteral }} AND
|
||||||
|
p.protype = '1'
|
||||||
|
ORDER BY proname;
|
||||||
|
{###########################################}
|
||||||
|
{### If Target Type is Synonym ###}
|
||||||
|
{###########################################}
|
||||||
|
{% elif trgTyp == 's' %}
|
||||||
|
SELECT synname AS name
|
||||||
|
FROM pg_synonym
|
||||||
|
ORDER BY synname;
|
||||||
|
{###########################################}
|
||||||
|
{### If Target Type is Package ###}
|
||||||
|
{###########################################}
|
||||||
|
{% elif trgTyp == 'P' %}
|
||||||
|
SELECT nspname AS name
|
||||||
|
FROM pg_namespace
|
||||||
|
WHERE nspparent IN (
|
||||||
|
SELECT oid
|
||||||
|
FROM pg_namespace
|
||||||
|
WHERE nspname = {{ trgSchema|qtLiteral }} LIMIT 1
|
||||||
|
)
|
||||||
|
AND nspobjecttype = 0
|
||||||
|
ORDER BY nspname;
|
||||||
|
{% else %}
|
||||||
|
{###################################################}
|
||||||
|
{### If Target Type is Table/View/M.View/Sequnce ###}
|
||||||
|
{###################################################}
|
||||||
|
SELECT relname AS name
|
||||||
|
FROM pg_class c, pg_namespace n
|
||||||
|
WHERE c.relnamespace = n.oid AND
|
||||||
|
n.nspname = {{ trgSchema|qtLiteral }} AND
|
||||||
|
{% if trgTyp == 'v' %}
|
||||||
|
{# If view is select then we need to fetch both view and materialized view #}
|
||||||
|
(c.relkind = 'v' OR c.relkind = 'm')
|
||||||
|
{% else %}
|
||||||
|
c.relkind = {{ trgTyp|qtLiteral }}
|
||||||
|
{% endif %}
|
||||||
|
ORDER BY relname;
|
||||||
|
{% endif %}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
SELECT synname as name
|
||||||
|
FROM pg_synonym s
|
||||||
|
JOIN pg_namespace ns ON s.synnamespace = ns.oid
|
||||||
|
AND s.synnamespace = {{scid}}::oid
|
||||||
|
ORDER BY synname;
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
SELECT synname AS name, pg_get_userbyid(synowner) AS owner,
|
||||||
|
synobjschema, synobjname, ns.nspname as schema,
|
||||||
|
COALESCE(
|
||||||
|
(SELECT relkind
|
||||||
|
FROM pg_class c, pg_namespace n
|
||||||
|
WHERE c.relnamespace = n.oid
|
||||||
|
AND n.nspname = synobjschema
|
||||||
|
AND c.relname = synobjname),
|
||||||
|
-- For Function/Procedure
|
||||||
|
(SELECT CASE WHEN p.protype = '0' THEN 'f'::"char" ELSE 'p'::"char" END
|
||||||
|
FROM pg_proc p, pg_namespace n
|
||||||
|
WHERE p.pronamespace = n.oid
|
||||||
|
AND n.nspname = synobjschema
|
||||||
|
AND p.proname = synobjname LIMIT 1),
|
||||||
|
-- For Package
|
||||||
|
(SELECT CASE WHEN count(*) > 0 THEN 'P'::"char" END
|
||||||
|
FROM pg_namespace
|
||||||
|
WHERE nspparent IN (SELECT oid
|
||||||
|
FROM pg_namespace
|
||||||
|
WHERE nspname = synobjschema LIMIT 1)
|
||||||
|
AND nspname = synobjname
|
||||||
|
AND nspobjecttype = 0),
|
||||||
|
-- Default s = Synonym
|
||||||
|
's') AS targettype,
|
||||||
|
CASE WHEN ns.nspname = 'public' THEN true ELSE false END AS is_public_synonym
|
||||||
|
FROM pg_synonym s JOIN pg_namespace ns ON s.synnamespace = ns.oid
|
||||||
|
WHERE s.synnamespace={{scid}}::oid
|
||||||
|
{% if syid %}
|
||||||
|
AND s.synname={{ syid|qtLiteral }}
|
||||||
|
{% endif %}
|
||||||
|
ORDER BY synname;
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
{% set is_public = False %}
|
||||||
|
{% if o_data.schema == 'public' %}
|
||||||
|
{% set is_public = True %}
|
||||||
|
{% endif %}
|
||||||
|
CREATE OR REPLACE {% if is_public %}
|
||||||
|
PUBLIC SYNONYM {{ conn|qtIdent(o_data.name) }}
|
||||||
|
{% else %}
|
||||||
|
SYNONYM {{ conn|qtIdent(o_data.schema, o_data.name) }}
|
||||||
|
{% endif %}
|
||||||
|
FOR {{ conn|qtIdent(data.synobjschema, data.synobjname) }};
|
||||||
Reference in new issue
Block a user