Skip to content

Commit

Permalink
Add storage migration
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Oct 29, 2024
1 parent 2ffd279 commit 85dc11f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ert/storage/local_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

logger = logging.getLogger(__name__)

_LOCAL_STORAGE_VERSION = 7
_LOCAL_STORAGE_VERSION = 8


class _Migrations(BaseModel):
Expand Down Expand Up @@ -468,6 +468,7 @@ def _migrate(self, version: int) -> None:
to5,
to6,
to7,
to8,
)

try:
Expand Down Expand Up @@ -511,7 +512,9 @@ def _migrate(self, version: int) -> None:
return None

elif version < _LOCAL_STORAGE_VERSION:
migrations = list(enumerate([to2, to3, to4, to5, to6, to7], start=1))
migrations = list(
enumerate([to2, to3, to4, to5, to6, to7, to8], start=1)
)
for from_version, migration in migrations[version - 1 :]:
print(f"* Updating storage to version: {from_version+1}")
migration.migrate(self.path)
Expand Down
22 changes: 22 additions & 0 deletions src/ert/storage/migration/to8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pathlib import Path


info = "Introducing init_source to GenKwConfig"


def migrate(path: Path) -> None:
for experiment in path.glob("experiments/*"):
with open(experiment / "parameter.json", encoding="utf-8") as fin:
parameters_json = json.load(fin)
key_to_add = "init_source"
for config in parameters_json.values():
if config["_ert_kind"] == "GenKwConfig" and key_to_add not in config:
config[key_to_add] = "sample"
with open(experiment / "parameter.json", "w", encoding="utf-8") as fout:
fout.write(json.dumps(parameters_json, indent=4))

0 comments on commit 85dc11f

Please sign in to comment.