diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 667f9ffe48..0fa4ea56fb 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -1,3 +1,4 @@ +* Allow skipping index creation * Add assert methods to test tools * Set ELLIPSIS option flag on doctest * Set IGNORE_EXCEPTION_DETAIL option flag on doctest diff --git a/trytond/bin/trytond-admin b/trytond/bin/trytond-admin index d15e80b078..8ae76e1c07 100755 --- a/trytond/bin/trytond-admin +++ b/trytond/bin/trytond-admin @@ -22,6 +22,8 @@ parser = commandline.get_parser_admin() if argcomplete: argcomplete.autocomplete(parser) options = parser.parse_args() +if options.indexes is None: + options.indexes = bool(options.update) config.update_etc(options.configfile) commandline.config_log(options) diff --git a/trytond/trytond/admin.py b/trytond/trytond/admin.py index 348af696ff..3b47d5dca3 100644 --- a/trytond/trytond/admin.py +++ b/trytond/trytond/admin.py @@ -55,7 +55,8 @@ def run(options): lang |= set(options.languages) pool = Pool(db_name) pool.init(update=options.update, lang=list(lang), - activatedeps=options.activatedeps) + activatedeps=options.activatedeps, + indexes=options.indexes) if options.update_modules_list: with Transaction().start(db_name, 0) as transaction: diff --git a/trytond/trytond/commandline.py b/trytond/trytond/commandline.py index c95517a088..bd6e2ba190 100644 --- a/trytond/trytond/commandline.py +++ b/trytond/trytond/commandline.py @@ -107,6 +107,9 @@ def get_parser_admin(): "-u", "--update", dest="update", nargs='+', default=[], metavar='MODULE', help="activate or update a module").completer = module_completer + parser.add_argument( + "--indexes", dest="indexes", action=argparse.BooleanOptionalAction, + default=None, help="update indexes") parser.add_argument("--all", dest="update", action="append_const", const="ir", help="update all activated modules") parser.add_argument("--activate-dependencies", dest="activatedeps", diff --git a/trytond/trytond/modules/__init__.py b/trytond/trytond/modules/__init__.py index c0d6d8527e..d27ddac3e5 100644 --- a/trytond/trytond/modules/__init__.py +++ b/trytond/trytond/modules/__init__.py @@ -132,7 +132,7 @@ def load_translations(pool, node, languages): Translation.translation_import(language, module, files) -def load_module_graph(graph, pool, update=None, lang=None): +def load_module_graph(graph, pool, update=None, lang=None, indexes=True): # Prevent to import backend when importing module from trytond.cache import Cache from trytond.ir.lang import get_parent_language @@ -247,12 +247,15 @@ def load_module_graph(graph, pool, update=None, lang=None): pool.setup_mixin() if update: - for model_name in models_with_indexes: - model = pool.get(model_name) - if model._sql_indexes: - logger.info('index:create %s', model_name) - model._update_sql_indexes() - transaction.commit() + if indexes: + for model_name in models_with_indexes: + model = pool.get(model_name) + if model._sql_indexes: + logger.info('index:create %s', model_name) + model._update_sql_indexes() + transaction.commit() + else: + logger.info('index:skipping indexes creation') for model_name in models_to_update_history: model = pool.get(model_name) if model._history: @@ -310,7 +313,8 @@ def register_classes(with_test=False): def load_modules( - database_name, pool, update=None, lang=None, activatedeps=False): + database_name, pool, update=None, lang=None, indexes=True, + activatedeps=False): # Do not import backend when importing module res = True if update: @@ -343,7 +347,7 @@ def load_modules( raise update += e.missings - load_module_graph(graph, pool, update, lang) + load_module_graph(graph, pool, update, lang, indexes) Configuration = pool.get('ir.configuration') Configuration(1).check() diff --git a/trytond/trytond/pool.py b/trytond/trytond/pool.py index 86cf972338..1fbe30a08b 100644 --- a/trytond/trytond/pool.py +++ b/trytond/trytond/pool.py @@ -144,11 +144,12 @@ class Pool(object): ''' return self._locks[self.database_name] - def init(self, update=None, lang=None, activatedeps=False): + def init(self, update=None, lang=None, activatedeps=False, indexes=True): ''' Init pool Set update to proceed to update lang is a list of language code to be updated + indexes is a boolean specifying if the indexes should be created ''' with self._lock: if not self._started: @@ -166,7 +167,7 @@ class Pool(object): try: restart = not load_modules( self.database_name, self, update=update, lang=lang, - activatedeps=activatedeps) + indexes=indexes) except Exception: del self._pool[self.database_name] self._modules = None