mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added support of Packages, Sequences and Synonyms to the Schema Diff. Fixes #5264
This commit is contained in:
@@ -423,6 +423,7 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
pkgid: Package ID
|
||||
only_sql: Return SQL only if True
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -583,6 +584,8 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
pkgid: Package ID
|
||||
sqltab: True
|
||||
diff_schema: Target Schema
|
||||
"""
|
||||
|
||||
required_args = [
|
||||
@@ -818,16 +821,27 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
def get_sql_from_diff(self, gid, sid, did, scid, oid, data=None,
|
||||
diff_schema=None, drop_sql=False):
|
||||
"""
|
||||
This function is used to get the DDL/DML statements.
|
||||
:param gid: Group ID
|
||||
:param sid: Serve ID
|
||||
:param did: Database ID
|
||||
:param scid: Schema ID
|
||||
:param oid: Package ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the domains
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
status, sql = self.getSQL(gid, sid, did, data, scid, oid)
|
||||
sql, name = self.getSQL(gid, sid, did, data, scid, oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, pkgid=oid, only_sql=True)
|
||||
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pkgid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
@@ -837,4 +851,5 @@ class PackageView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, PackageView)
|
||||
PackageView.register_node_view(blueprint)
|
||||
|
||||
@@ -10,6 +10,7 @@ END {{ conn|qtIdent(data.name) }};
|
||||
CREATE OR REPLACE PACKAGE BODY {{ conn|qtIdent(data.schema,data.name) }}
|
||||
IS
|
||||
{{data.pkgbodysrc}}
|
||||
|
||||
END {{ conn|qtIdent(data.name) }};
|
||||
{% endif %}
|
||||
{% if data.pkgacl %}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
|
||||
|
||||
{% if data %}
|
||||
{% set recreate_pkg_body = false %}
|
||||
{% if data.pkgheadsrc is defined and data.pkgheadsrc != o_data.pkgheadsrc and o_data.pkgbodysrc != None or (data.pkgbodysrc is defined and data.pkgbodysrc == '') %}
|
||||
{% set recreate_pkg_body = true %}
|
||||
DROP PACKAGE BODY {{ conn|qtIdent(data.schema,data.name) }};
|
||||
{% endif %}
|
||||
{% if data.pkgheadsrc %}
|
||||
@@ -12,11 +14,12 @@ IS
|
||||
END {{ conn|qtIdent(data.name) }};
|
||||
|
||||
{% endif %}
|
||||
{% if data.pkgbodysrc %}
|
||||
{% if data.pkgbodysrc or (o_data.pkgbodysrc and recreate_pkg_body) %}
|
||||
|
||||
CREATE OR REPLACE PACKAGE BODY {{ conn|qtIdent(data.schema,data.name) }}
|
||||
IS
|
||||
{{data.pkgbodysrc}}
|
||||
{% if data.pkgbodysrc %}{{data.pkgbodysrc}}{% else %}{{o_data.pkgbodysrc}}{% endif %}
|
||||
|
||||
END {{ conn|qtIdent(data.name) }};
|
||||
{% endif %}
|
||||
{% if data.pkgacl %}
|
||||
|
||||
@@ -436,7 +436,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition(action='delete')
|
||||
def delete(self, gid, sid, did, scid, seid=None):
|
||||
def delete(self, gid, sid, did, scid, seid=None, only_sql=False):
|
||||
"""
|
||||
This function will drop the object
|
||||
|
||||
@@ -446,6 +446,7 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
seid: Sequence ID
|
||||
only_sql: Return SQL only if True
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -489,6 +490,10 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
"/".join([self.template_path, 'delete.sql']),
|
||||
data=res['rows'][0], cascade=cascade
|
||||
)
|
||||
|
||||
if only_sql:
|
||||
return SQL
|
||||
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -675,7 +680,8 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return SQL, data['name']
|
||||
|
||||
@check_precondition(action="sql")
|
||||
def sql(self, gid, sid, did, scid, seid):
|
||||
def sql(self, gid, sid, did, scid, seid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will generate sql for sql panel
|
||||
|
||||
@@ -685,6 +691,8 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
seid: Sequence ID
|
||||
diff_schema: Schema diff target schema name
|
||||
json_resp: json response or plain text response
|
||||
"""
|
||||
|
||||
SQL = render_template(
|
||||
@@ -714,6 +722,10 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
row['cycled'] = rset1['rows'][0]['is_cycled']
|
||||
|
||||
result = res['rows'][0]
|
||||
|
||||
if diff_schema:
|
||||
result['schema'] = diff_schema
|
||||
|
||||
result = self._formatter(result, scid, seid)
|
||||
SQL, name = self.getSQL(gid, sid, did, result, scid)
|
||||
# Most probably this is due to error
|
||||
@@ -721,6 +733,10 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return SQL
|
||||
SQL = SQL.strip('\n').strip(' ')
|
||||
|
||||
# Return sql for schema diff
|
||||
if not json_resp:
|
||||
return SQL
|
||||
|
||||
sql_header = u"""-- SEQUENCE: {0}
|
||||
|
||||
-- DROP SEQUENCE {0};
|
||||
@@ -912,5 +928,37 @@ class SequenceView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
return res
|
||||
|
||||
def get_sql_from_diff(self, gid, sid, did, scid, oid, data=None,
|
||||
diff_schema=None, drop_sql=False):
|
||||
"""
|
||||
This function is used to get the DDL/DML statements.
|
||||
:param gid: Group ID
|
||||
:param sid: Serve ID
|
||||
:param did: Database ID
|
||||
:param scid: Schema ID
|
||||
:param oid: Sequence ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the domains
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, name = self.getSQL(gid, sid, did, data, scid, oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, seid=oid, only_sql=True)
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, seid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, seid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, SequenceView)
|
||||
SequenceView.register_node_view(blueprint)
|
||||
|
||||
@@ -483,7 +483,7 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return internal_server_error(errormsg=str(e))
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, syid=None):
|
||||
def delete(self, gid, sid, did, scid, syid=None, only_sql=False):
|
||||
"""
|
||||
This function will delete existing the synonym object
|
||||
|
||||
@@ -493,6 +493,7 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
syid: Synonym ID
|
||||
only_sql: Return SQL only if True
|
||||
"""
|
||||
if syid is None:
|
||||
data = request.form if request.form else json.loads(
|
||||
@@ -525,6 +526,9 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
'delete.sql']),
|
||||
data=data,
|
||||
conn=self.conn)
|
||||
if only_sql:
|
||||
return SQL
|
||||
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -648,7 +652,8 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return SQL.strip('\n')
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, syid):
|
||||
def sql(self, gid, sid, did, scid, syid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will generates reverse engineered sql for synonym object
|
||||
|
||||
@@ -658,6 +663,8 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
syid: Synonym ID
|
||||
diff_schema:
|
||||
json_resp:
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
@@ -673,9 +680,14 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
gettext('The specified synonym could not be found.')
|
||||
)
|
||||
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=data, conn=self.conn, comment=True)
|
||||
if not json_resp:
|
||||
return SQL
|
||||
|
||||
return ajax_response(response=SQL)
|
||||
|
||||
@@ -751,5 +763,38 @@ class SynonymView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
return res
|
||||
|
||||
def get_sql_from_diff(self, gid, sid, did, scid, oid, data=None,
|
||||
diff_schema=None, drop_sql=False):
|
||||
"""
|
||||
This function is used to get the DDL/DML statements.
|
||||
:param gid: Group ID
|
||||
:param sid: Serve ID
|
||||
:param did: Database ID
|
||||
:param scid: Schema ID
|
||||
:param oid: Synonyms ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the domains
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql = self.get_sql(gid, sid, data, scid, oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, syid=oid, only_sql=True)
|
||||
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, syid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, syid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, SynonymView)
|
||||
SynonymView.register_node_view(blueprint)
|
||||
|
||||
@@ -155,6 +155,8 @@ define('pgadmin.node.synonym', [
|
||||
var trgSchema = control.model.get('synobjschema');
|
||||
var res = [];
|
||||
|
||||
control.model.set('synobjname', undefined);
|
||||
|
||||
var node = control.field.get('schema_node'),
|
||||
_url = node.generate_url.apply(
|
||||
node, [
|
||||
|
||||
@@ -4,5 +4,4 @@
|
||||
{% endif %}
|
||||
DROP {% if is_public %}
|
||||
PUBLIC SYNONYM {{ conn|qtIdent(data.name) }}{% else %}
|
||||
SYNONYM {{ conn|qtIdent(data.schema, data.name) }}
|
||||
{% endif %};
|
||||
SYNONYM {{ conn|qtIdent(data.schema, data.name) }}{% endif %};
|
||||
|
||||
Reference in New Issue
Block a user