mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[UPD] pglogical - using sqlparse to deduce DDL statements to replicate.
This commit is contained in:
committed by
Holger Brunn
parent
84047078a2
commit
377aa43832
@@ -10,4 +10,7 @@
|
|||||||
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
|
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"post_load": "post_load",
|
"post_load": "post_load",
|
||||||
|
'external_dependencies': {
|
||||||
|
'python': ['sqlparse'],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ import logging
|
|||||||
from odoo.sql_db import Cursor
|
from odoo.sql_db import Cursor
|
||||||
from odoo.tools import config
|
from odoo.tools import config
|
||||||
|
|
||||||
|
try:
|
||||||
|
import sqlparse
|
||||||
|
except ImportError:
|
||||||
|
sqlparse = None
|
||||||
|
|
||||||
SECTION_NAME = "pglogical"
|
SECTION_NAME = "pglogical"
|
||||||
|
|
||||||
|
|
||||||
@@ -24,6 +29,9 @@ def post_load():
|
|||||||
if not replication_sets:
|
if not replication_sets:
|
||||||
_logger.error("no replication sets defined, not doing anything")
|
_logger.error("no replication sets defined, not doing anything")
|
||||||
return
|
return
|
||||||
|
if not sqlparse:
|
||||||
|
_logger.error("DDL replication not supported - sqlparse is not available")
|
||||||
|
return
|
||||||
if config["test_enable"]:
|
if config["test_enable"]:
|
||||||
_logger.info("test mode enabled, not doing anything")
|
_logger.info("test mode enabled, not doing anything")
|
||||||
return
|
return
|
||||||
@@ -33,7 +41,8 @@ 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"""
|
||||||
if (query[:6] == "CREATE" or query[:5] == "ALTER" or query[:4] == "DROP") and (
|
parsed_queries = [x.get_type() for x in sqlparse.parse(query)]
|
||||||
|
if any(q in ["CREATE", "ALTER", "DROP"] for q in parsed_queries) and (
|
||||||
# don't replicate constraints, triggers, indexes
|
# don't replicate constraints, triggers, indexes
|
||||||
"CONSTRAINT" not in query
|
"CONSTRAINT" not in query
|
||||||
and "TRIGGER" not in query
|
and "TRIGGER" not in query
|
||||||
|
|||||||
Reference in New Issue
Block a user