mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added support of Collation, FTS Configuration, FTS Dictionary, FTS Parser, and FTS Template to the Schema Diff. Fixes #5261
This commit is contained in:
@@ -501,7 +501,7 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, coid=None):
|
||||
def delete(self, gid, sid, did, scid, coid=None, only_sql=False):
|
||||
"""
|
||||
This function will delete existing the collation object
|
||||
|
||||
@@ -511,6 +511,7 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
coid: Collation ID
|
||||
only_sql: Return only sql if True
|
||||
"""
|
||||
if coid is None:
|
||||
data = request.form if request.form else json.loads(
|
||||
@@ -548,6 +549,11 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
nspname=data['schema'],
|
||||
cascade=cascade,
|
||||
conn=self.conn)
|
||||
|
||||
# Used for schema diff tool
|
||||
if only_sql:
|
||||
return SQL
|
||||
|
||||
status, res = self.conn.execute_scalar(SQL)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -685,7 +691,8 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
return SQL.strip('\n'), data['name']
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, coid):
|
||||
def sql(self, gid, sid, did, scid, coid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will generates reverse engineered sql for collation
|
||||
object
|
||||
@@ -696,6 +703,8 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
did: Database ID
|
||||
scid: Schema ID
|
||||
coid: Collation ID
|
||||
diff_schema: Target Schema for schema diff
|
||||
json_resp: True then return json response
|
||||
"""
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'properties.sql']),
|
||||
@@ -710,6 +719,9 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
data = res['rows'][0]
|
||||
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
|
||||
SQL = render_template("/".join([self.template_path,
|
||||
'create.sql']),
|
||||
data=data, conn=self.conn)
|
||||
@@ -722,6 +734,9 @@ class CollationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
nspname=data['schema'])
|
||||
SQL = sql_header + '\n\n' + SQL.strip('\n')
|
||||
|
||||
if not json_resp:
|
||||
return SQL
|
||||
|
||||
return ajax_response(response=SQL)
|
||||
|
||||
@check_precondition
|
||||
@@ -793,5 +808,38 @@ class CollationView(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: Collation ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the collation
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, name = self.get_sql(gid=gid, sid=sid, data=data, scid=scid,
|
||||
coid=oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, coid=oid, only_sql=True)
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, coid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, coid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, CollationView)
|
||||
CollationView.register_node_view(blueprint)
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
{% if data %}
|
||||
{# Change object's owner #}
|
||||
{% if (data.lc_collate and data.lc_type) or data.locale or data.copy_collation %}
|
||||
-- WARNING:
|
||||
-- We have found the difference in either of LC_COLLATE or LC_CTYPE or LOCALE,
|
||||
-- so we need to drop the existing collation first and re-create it.
|
||||
DROP COLLATION {{ conn|qtIdent(o_data.schema, o_data.name) }};
|
||||
|
||||
CREATE COLLATION {{ conn|qtIdent(o_data.schema, o_data.name) }}
|
||||
{% if data.lc_collate and data.lc_type %}
|
||||
(LC_COLLATE = {{ data.lc_collate|qtLiteral }}, LC_CTYPE = {{ data.lc_type|qtLiteral }});
|
||||
{% endif %}
|
||||
{% if data.locale %}
|
||||
(LOCALE = {{ data.locale|qtLiteral }});
|
||||
{% endif %}
|
||||
{% if data.copy_collation %}
|
||||
FROM {{ data.copy_collation }};
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% if data.owner and data.owner != o_data.owner %}
|
||||
ALTER COLLATION {{ conn|qtIdent(o_data.schema, o_data.name) }}
|
||||
OWNER TO {{ conn|qtIdent(data.owner) }};
|
||||
|
||||
@@ -532,7 +532,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, cfgid=None):
|
||||
def delete(self, gid, sid, did, scid, cfgid=None, only_sql=False):
|
||||
"""
|
||||
This function will drop the FTS Configuration object
|
||||
:param gid: group id
|
||||
@@ -540,6 +540,7 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param cfgid: FTS Configuration id
|
||||
:param only_sql: Return only sql if True
|
||||
"""
|
||||
if cfgid is None:
|
||||
data = request.form if request.form else json.loads(
|
||||
@@ -587,6 +588,10 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
cascade=cascade
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if only_sql:
|
||||
return sql
|
||||
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -869,7 +874,8 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, cfgid):
|
||||
def sql(self, gid, sid, did, scid, cfgid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will reverse generate sql for sql panel
|
||||
:param gid: group id
|
||||
@@ -877,6 +883,8 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param cfgid: FTS Configuration id
|
||||
:param diff_schema: Target Schema for schema diff
|
||||
:param json_resp: True then return json response
|
||||
"""
|
||||
try:
|
||||
sql = render_template(
|
||||
@@ -901,6 +909,25 @@ class FtsConfigurationView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
"FTS Configuration node.")
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if diff_schema:
|
||||
data = {'schema': scid}
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'schema.sql']),
|
||||
data=data,
|
||||
conn=self.conn,
|
||||
)
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=schema)
|
||||
|
||||
res = res.replace(schema, diff_schema)
|
||||
|
||||
if not json_resp:
|
||||
return res
|
||||
|
||||
return ajax_response(response=res)
|
||||
|
||||
except Exception as e:
|
||||
@@ -970,5 +997,38 @@ class FtsConfigurationView(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: Collation ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the fts configuration
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid,
|
||||
data=data, cfgid=oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, cfgid=oid, only_sql=True)
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, cfgid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, cfgid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, FtsConfigurationView)
|
||||
FtsConfigurationView.register_node_view(blueprint)
|
||||
|
||||
@@ -527,7 +527,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, dcid=None):
|
||||
def delete(self, gid, sid, did, scid, dcid=None, only_sql=False):
|
||||
"""
|
||||
This function will drop the FTS Dictionary object
|
||||
:param gid: group id
|
||||
@@ -535,6 +535,7 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param dcid: FTS Dictionary id
|
||||
:param only_sql: Return only sql if True
|
||||
"""
|
||||
if dcid is None:
|
||||
data = request.form if request.form else json.loads(
|
||||
@@ -581,6 +582,10 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
cascade=cascade
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if only_sql:
|
||||
return sql
|
||||
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -766,7 +771,8 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, dcid):
|
||||
def sql(self, gid, sid, did, scid, dcid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will reverse generate sql for sql panel
|
||||
:param gid: group id
|
||||
@@ -774,6 +780,8 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param dcid: FTS Dictionary id
|
||||
:param diff_schema: Target Schema for schema diff
|
||||
:param json_resp: True then return json response
|
||||
"""
|
||||
|
||||
sql = render_template(
|
||||
@@ -819,6 +827,9 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
# Replace schema oid with schema name
|
||||
res['rows'][0]['schema'] = schema
|
||||
|
||||
if diff_schema:
|
||||
res['rows'][0]['schema'] = diff_schema
|
||||
|
||||
sql = render_template("/".join([self.template_path, 'create.sql']),
|
||||
data=res['rows'][0],
|
||||
conn=self.conn, is_displaying=True)
|
||||
@@ -832,6 +843,9 @@ class FtsDictionaryView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
|
||||
sql = sql_header + sql
|
||||
|
||||
if not json_resp:
|
||||
return sql
|
||||
|
||||
return ajax_response(response=sql.strip('\n'))
|
||||
|
||||
@check_precondition
|
||||
@@ -897,5 +911,38 @@ class FtsDictionaryView(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: Collation ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the fts configuration
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid,
|
||||
data=data, dcid=oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, dcid=oid, only_sql=True)
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, dcid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, dcid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, FtsDictionaryView)
|
||||
FtsDictionaryView.register_node_view(blueprint)
|
||||
|
||||
@@ -476,7 +476,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, pid=None):
|
||||
def delete(self, gid, sid, did, scid, pid=None, only_sql=False):
|
||||
"""
|
||||
This function will drop the fts_parser object
|
||||
:param gid: group id
|
||||
@@ -484,6 +484,7 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param pid: fts tempate id
|
||||
:param only_sql: Return only sql if True
|
||||
"""
|
||||
if pid is None:
|
||||
data = request.form if request.form else json.loads(
|
||||
@@ -530,6 +531,10 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
cascade=cascade
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if only_sql:
|
||||
return sql
|
||||
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -813,7 +818,8 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, pid):
|
||||
def sql(self, gid, sid, did, scid, pid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will reverse generate sql for sql panel
|
||||
:param gid: group id
|
||||
@@ -821,6 +827,8 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param pid: fts tempate id
|
||||
:param diff_schema: Target Schema for schema diff
|
||||
:param json_resp: True then return json response
|
||||
"""
|
||||
try:
|
||||
sql = render_template(
|
||||
@@ -846,6 +854,25 @@ class FtsParserView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if diff_schema:
|
||||
data = {'schema': scid}
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'schema.sql']),
|
||||
data=data,
|
||||
conn=self.conn,
|
||||
)
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=schema)
|
||||
|
||||
res = res.replace(schema, diff_schema)
|
||||
|
||||
if not json_resp:
|
||||
return res
|
||||
|
||||
return ajax_response(response=res)
|
||||
|
||||
except Exception as e:
|
||||
@@ -915,5 +942,38 @@ class FtsParserView(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: Collation ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the fts configuration
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid,
|
||||
data=data, pid=oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, pid=oid, only_sql=True)
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, pid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, FtsParserView)
|
||||
FtsParserView.register_node_view(blueprint)
|
||||
|
||||
@@ -15,6 +15,23 @@ ALTER TEXT SEARCH PARSER {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(o_data.n
|
||||
ALTER TEXT SEARCH PARSER {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(name)}}
|
||||
SET SCHEMA {{data.schema}};
|
||||
{% endif %}
|
||||
{# Schema Diff SQL for FTS PARSER #}
|
||||
{% if data.prsstart or data.prstoken or data.prsend or data.prslextype or data.prsheadline %}
|
||||
-- WARNING:
|
||||
-- We have found the difference in either of START or GETTOKEN or END or
|
||||
-- LEXTYPES or HEADLINE, so we need to drop the existing parser first
|
||||
-- and re-create it.
|
||||
DROP TEXT SEARCH PARSER {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(name)}};
|
||||
|
||||
CREATE TEXT SEARCH PARSER {{ conn|qtIdent(o_data.schema, name) }} (
|
||||
START = {% if data.prsstart is defined %}{{data.prsstart}}{% else %}{{o_data.prsstart}}{% endif %},
|
||||
GETTOKEN = {% if data.prstoken is defined %}{{data.prstoken}}{% else %}{{o_data.prstoken}}{% endif %},
|
||||
END = {% if data.prsend is defined %}{{data.prsend}}{% else %}{{o_data.prsend}}{% endif %},
|
||||
LEXTYPES = {% if data.prslextype is defined %}{{data.prslextype}}{% else %}{{o_data.prslextype}}{% endif %}{% if (data.prsheadline and data.prsheadline != '-') or (o_data.prsheadline and o_data.prsheadline != '-') %},
|
||||
HEADLINE = {% if data.prsheadline is defined %}{{data.prsheadline}}{% else %}{{o_data.prsheadline}}{% endif %}{% endif %}
|
||||
|
||||
);
|
||||
{% endif %}
|
||||
{% if "description" in data and data.description != o_data.description %}
|
||||
COMMENT ON TEXT SEARCH PARSER {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(name)}}
|
||||
IS {{ data.description|qtLiteral }};
|
||||
|
||||
@@ -443,7 +443,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def delete(self, gid, sid, did, scid, tid=None):
|
||||
def delete(self, gid, sid, did, scid, tid=None, only_sql=False):
|
||||
"""
|
||||
This function will drop the fts_template object
|
||||
:param gid: group id
|
||||
@@ -451,6 +451,7 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param tid: fts tempate id
|
||||
:param only_sql: Return only sql if True
|
||||
"""
|
||||
if tid is None:
|
||||
data = request.form if request.form else json.loads(
|
||||
@@ -493,6 +494,10 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
cascade=cascade
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if only_sql:
|
||||
return sql
|
||||
|
||||
status, res = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=res)
|
||||
@@ -691,7 +696,8 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
)
|
||||
|
||||
@check_precondition
|
||||
def sql(self, gid, sid, did, scid, tid):
|
||||
def sql(self, gid, sid, did, scid, tid, diff_schema=None,
|
||||
json_resp=True):
|
||||
"""
|
||||
This function will reverse generate sql for sql panel
|
||||
:param gid: group id
|
||||
@@ -699,6 +705,8 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
:param did: database id
|
||||
:param scid: schema id
|
||||
:param tid: fts tempate id
|
||||
:param diff_schema: Target Schema for schema diff
|
||||
:param json_resp: True then return json response
|
||||
"""
|
||||
sql = render_template(
|
||||
"/".join([self.template_path, 'sql.sql']),
|
||||
@@ -721,6 +729,25 @@ class FtsTemplateView(PGChildNodeView, SchemaDiffObjectCompare):
|
||||
"FTS Template node.")
|
||||
)
|
||||
|
||||
# Used for schema diff tool
|
||||
if diff_schema:
|
||||
data = {'schema': scid}
|
||||
# Fetch schema name from schema oid
|
||||
sql = render_template("/".join([self.template_path,
|
||||
'schema.sql']),
|
||||
data=data,
|
||||
conn=self.conn,
|
||||
)
|
||||
|
||||
status, schema = self.conn.execute_scalar(sql)
|
||||
if not status:
|
||||
return internal_server_error(errormsg=schema)
|
||||
|
||||
res = res.replace(schema, diff_schema)
|
||||
|
||||
if not json_resp:
|
||||
return res
|
||||
|
||||
return ajax_response(response=res)
|
||||
|
||||
@check_precondition
|
||||
@@ -786,5 +813,38 @@ class FtsTemplateView(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: Collation ID
|
||||
:param data: Difference data
|
||||
:param diff_schema: Target Schema
|
||||
:param drop_sql: True if need to drop the fts configuration
|
||||
:return:
|
||||
"""
|
||||
sql = ''
|
||||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, name = self.get_sql(gid=gid, sid=sid, did=did, scid=scid,
|
||||
data=data, tid=oid)
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid, tid=oid, only_sql=True)
|
||||
elif diff_schema:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, tid=oid,
|
||||
diff_schema=diff_schema, json_resp=False)
|
||||
else:
|
||||
sql = self.sql(gid=gid, sid=sid, did=did, scid=scid, tid=oid,
|
||||
json_resp=False)
|
||||
return sql
|
||||
|
||||
|
||||
SchemaDiffRegistry(blueprint.node_type, FtsTemplateView)
|
||||
FtsTemplateView.register_node_view(blueprint)
|
||||
|
||||
@@ -15,6 +15,21 @@ ALTER TEXT SEARCH TEMPLATE {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(o_data
|
||||
ALTER TEXT SEARCH TEMPLATE {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(name)}}
|
||||
SET SCHEMA {{conn|qtIdent(data.schema)}};
|
||||
{% endif %}
|
||||
{# Schema Diff SQL for FTS PARSER #}
|
||||
{% if data.tmplinit or data.tmpllexize %}
|
||||
-- WARNING:
|
||||
-- We have found the difference in either of INIT or LEXIZE,
|
||||
-- so we need to drop the existing template first and re-create it.
|
||||
DROP TEXT SEARCH TEMPLATE {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(name)}};
|
||||
|
||||
CREATE TEXT SEARCH TEMPLATE {{ conn|qtIdent(o_data.schema, name) }} (
|
||||
{% if data.tmplinit and data.tmplinit != '-'%}
|
||||
INIT = {{data.tmplinit}},
|
||||
{% endif %}
|
||||
LEXIZE = {% if data.tmpllexize is defined %}{{data.tmpllexize}}{% else %}{{o_data.tmpllexize}}{% endif %}
|
||||
|
||||
);
|
||||
{% endif %}
|
||||
{% if 'description' in data and data.description != o_data.description %}
|
||||
COMMENT ON TEXT SEARCH TEMPLATE {{conn|qtIdent(o_data.schema)}}.{{conn|qtIdent(name)}}
|
||||
IS {{ data.description|qtLiteral }};
|
||||
|
||||
@@ -1366,7 +1366,10 @@ class BaseTableView(PGChildNodeView, BasePartitionTable):
|
||||
|
||||
# Check if partition is again declare as partitioned table.
|
||||
if 'is_sub_partitioned' in row and row['is_sub_partitioned']:
|
||||
part_data['partition_scheme'] = self.get_partition_scheme(row)
|
||||
part_data['partition_scheme'] = row['sub_partition_scheme'] \
|
||||
if 'sub_partition_scheme' in row else \
|
||||
self.get_partition_scheme(row)
|
||||
|
||||
part_data['is_partitioned'] = True
|
||||
|
||||
if 'is_attach' in row and row['is_attach']:
|
||||
|
||||
Reference in New Issue
Block a user