From d317107f7e2fd5b57a6ba5337d22c98ac617b6f6 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Wed, 13 Oct 2021 21:55:01 +0200 Subject: [PATCH] Fix error with migration data filenames https://github.com/brightway-lca/brightway2-io/issues/115 --- bw2data/updates.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bw2data/updates.py b/bw2data/updates.py index 4445282e..9c64cf92 100644 --- a/bw2data/updates.py +++ b/bw2data/updates.py @@ -19,6 +19,10 @@ import sqlite3 import warnings import pickle +import bw2io as bi +from pathlib import Path +from bw_processing import safe_filename + hash_re = re.compile("^[a-zA-Z0-9]{32}$") is_hash = lambda x: bool(hash_re.match(x)) @@ -100,11 +104,16 @@ class Updates: "automatic": True, "explanation": "", }, - # "4.0 new processed format": { - # 'method': 'expire_all_processed_data_40', - # 'automatic': True, - # 'explanation': "bw2data 4.0 release requires all database be reprocessed" - # } + "4.0 new processed format": { + 'method': 'expire_all_processed_data_40', + 'automatic': True, + 'explanation': "bw2data 4.0 release requires all database be reprocessed" + }, + "4.0 migrations filename change": { + 'method': 'fix_migrations_filename', + 'automatic': True, + 'explanation': "bw2data 4.0 release requires migrations filename changes" + } } @classmethod @@ -201,6 +210,17 @@ def processed_data_format_change_23(cls): def expire_all_processed_data_40(cls): cls._reprocess_all() + @classmethod + def fix_migrations_filename(cls): + """"Fix migration data filenames to use shorter hash. + + See https://github.com/brightway-lca/brightway2-io/issues/115""" + for name in bi.migrations: + current = Path(projects.request_directory("migrations") / (safe_filename(name, full=True) + ".json")) + assert current.is_file() + target = Path(projects.request_directory("migrations") / (safe_filename(name) + ".json")) + current.replace(target) + @classmethod def _reprocess_all(cls): objects = [