diff options
| author | Laurent Contzen <lco@odoo.com> | 2019-04-11 09:48:35 +0000 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-08-05 12:21:00 +0000 |
| commit | bbb1a8f151b07d0125fc6d7d89375aa22681aac5 (patch) | |
| tree | bf5ccedb87685b8901ad30c10742a1ae7c4adcd6 /odoo/modules | |
| parent | 6edb18be0d58a77c760668c006307ddf7dfd4935 (diff) | |
[IMP] ORM: Add new --upgrades-paths CLI option
This commit adds a new way to use upgrades scripts folders
whithout needing to symlink them to an hardcoded path.
The folders specified in --upgrades-paths is then being used by
migration.py to find and execute migrations scripts per module
specified in the -u CLI option.
The folder needs to have the following structure:
- <upgrades_paths folder 1>
- <module1 name>
- <version1>
- <script1>
- <script2>
- ...
- <scriptn>
- <version2>
- <scripts>
- <module2 name>
- <versions>
- <scripts>
- ...
- <upgrades_paths folder 2>
- ...
Update odoo/tools/config.py
Co-Authored-By: Olivier Dony <odony@users.noreply.github.com>
Diffstat (limited to 'odoo/modules')
| -rw-r--r-- | odoo/modules/migration.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/odoo/modules/migration.py b/odoo/modules/migration.py index 6331af43660..8faf8735a8d 100644 --- a/odoo/modules/migration.py +++ b/odoo/modules/migration.py @@ -19,7 +19,7 @@ _logger = logging.getLogger(__name__) def load_script(path, module_name): - full_path = get_resource_path(*path.split(os.path.sep)) + full_path = get_resource_path(*path.split(os.path.sep)) if not os.path.isabs(path) else path spec = importlib.util.spec_from_file_location(module_name, full_path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) @@ -62,6 +62,13 @@ class MigrationManager(object): self._get_files() def _get_files(self): + def _get_upgrades_paths(pkg): + for path in tools.config['upgrades_paths'].split(','): + upgrade_path = opj(path, pkg) + if os.path.exists(upgrade_path): + return upgrade_path + return None + def get_scripts(path): if not path: return {} @@ -78,7 +85,10 @@ class MigrationManager(object): self.migrations[pkg.name] = { 'module': get_scripts(get_resource_path(pkg.name, 'migrations')), + 'module_upgrades': get_scripts(get_resource_path(pkg.name, 'upgrades')), 'maintenance': get_scripts(get_resource_path('base', 'maintenance', 'migrations', pkg.name)), + 'maintenance_upgrades': get_scripts(get_resource_path('base', 'maintenance', 'upgrades', pkg.name)), + 'upgrades': get_scripts(_get_upgrades_paths(pkg.name)), } def migrate_module(self, pkg, stage): @@ -122,9 +132,16 @@ class MigrationManager(object): mapping = { 'module': opj(pkg.name, 'migrations'), + 'module_upgrades': opj(pkg.name, 'upgrades'), 'maintenance': opj('base', 'maintenance', 'migrations', pkg.name), + 'maintenance_upgrades': opj('base', 'maintenance', 'upgrades', pkg.name), } + for path in tools.config['upgrades_paths'].split(','): + if os.path.exists(opj(path, pkg.name)): + mapping['upgrades'] = opj(path, pkg.name) + break + for x in mapping: if version in m.get(x): for f in m[x][version]: |
