[FIX] core: merge scripts found in --upgrade-path

Don't limit on the first directory found in the upgrade-path.

It follow the same behavior regarding scripts found in the `maintenance`
directory and the ones in the local `upgrades` directory of modules.

opw-2868713

closes odoo/odoo#111087

X-original-commit: d2e6c9d5010ab8092eff37775e92b486f89d28fc
Signed-off-by: Christophe Simonis <chs@odoo.com>
This commit is contained in:
Christophe Simonis
2023-01-26 19:55:55 +01:00
parent 418c46be03
commit 04487da7c5
+17 -23
View File
@@ -69,14 +69,13 @@ class MigrationManager(object):
for path in odoo.upgrade.__path__:
upgrade_path = opj(path, pkg)
if os.path.exists(upgrade_path):
return upgrade_path
return None
yield upgrade_path
def get_scripts(path):
if not path:
return {}
return {
version: glob.glob1(opj(path, version), '*.py')
version: glob.glob(opj(path, version, '*.py'))
for version in os.listdir(path)
if os.path.isdir(opj(path, version))
}
@@ -89,9 +88,14 @@ 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')),
'upgrade': get_scripts(_get_upgrade_path(pkg.name)),
}
scripts = defaultdict(list)
for p in _get_upgrade_path(pkg.name):
for v, s in get_scripts(p).items():
scripts[v].extend(s)
self.migrations[pkg.name]["upgrade"] = scripts
def migrate_module(self, pkg, stage):
assert stage in ('pre', 'post', 'end')
stageformat = {
@@ -129,26 +133,16 @@ class MigrationManager(object):
""" return a list of migration script files
"""
m = self.migrations[pkg.name]
lst = []
mapping = {
'module': opj(pkg.name, 'migrations'),
'module_upgrades': opj(pkg.name, 'upgrades'),
}
for path in odoo.upgrade.__path__:
if os.path.exists(opj(path, pkg.name)):
mapping['upgrade'] = opj(path, pkg.name)
break
for x in mapping:
if version in m.get(x):
for f in m[x][version]:
if not f.startswith(stage + '-'):
continue
lst.append(opj(mapping[x], version, f))
lst.sort()
return lst
return sorted(
(
f
for k in m
for f in m[k].get(version, [])
if os.path.basename(f).startswith(f"{stage}-")
),
key=os.path.basename,
)
installed_version = getattr(pkg, 'load_version', pkg.installed_version) or ''
parsed_installed_version = parse_version(installed_version)