mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] use sqlparse also to determine which ddl to update
This commit is contained in:
@@ -41,12 +41,17 @@ def post_load():
|
|||||||
|
|
||||||
def execute(self, query, params=None, log_exceptions=None):
|
def execute(self, query, params=None, log_exceptions=None):
|
||||||
"""Wrap DDL in pglogical.replicate_ddl_command"""
|
"""Wrap DDL in pglogical.replicate_ddl_command"""
|
||||||
parsed_queries = [x.get_type() for x in sqlparse.parse(query)]
|
# short circuit statements that must be as fast as possible
|
||||||
if any(q in ["CREATE", "ALTER", "DROP"] for q in parsed_queries) and (
|
if query[:6] != "SELECT":
|
||||||
|
parsed_queries = sqlparse.parse(query)
|
||||||
|
if any(
|
||||||
|
parsed_query.get_type() in ("CREATE", "ALTER", "DROP")
|
||||||
|
for parsed_query in parsed_queries
|
||||||
|
) and not any(
|
||||||
|
token.is_keyword and token.normalized in
|
||||||
# don't replicate constraints, triggers, indexes
|
# don't replicate constraints, triggers, indexes
|
||||||
"CONSTRAINT" not in query
|
("CONSTRAINT", "TRIGGER", "INDEX")
|
||||||
and "TRIGGER" not in query
|
for parsed in parsed_queries for token in parsed.tokens[1:]
|
||||||
and "INDEX" not in query
|
|
||||||
):
|
):
|
||||||
mogrified = self.mogrify(query, params).decode("utf8")
|
mogrified = self.mogrify(query, params).decode("utf8")
|
||||||
query = "SELECT pglogical.replicate_ddl_command(%s, %s)"
|
query = "SELECT pglogical.replicate_ddl_command(%s, %s)"
|
||||||
|
|||||||
Reference in New Issue
Block a user