Skip to content

Commit

Permalink
Fix error with migration data filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Oct 13, 2021
1 parent 4ca1507 commit d317107
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions bw2data/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit d317107

Please sign in to comment.