Skip to content

Commit

Permalink
Add migration functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Jan 29, 2025
1 parent 054e977 commit 85d6d63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__version__ = "2025.1.0"
# Keep synced write_schema_version in ribasim_qgis/core/geopackage.py
__schema_version__ = 3
__schema_version__ = 4

from ribasim.config import Allocation, Logging, Node, Solver
from ribasim.geometry.edge import EdgeTable
Expand Down
14 changes: 14 additions & 0 deletions python/ribasim/ribasim/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,17 @@ def outletstaticschema_migration(df: DataFrame, schema_version: int) -> DataFram
df.rename(columns={"min_crest_level": "min_upstream_level"}, inplace=True)

return df


for node_type in ["UserDemand", "LevelDemand", "FlowDemand"]:
for table_type in ["static", "time"]:

def migration_func(df: DataFrame, schema_version: int) -> DataFrame:
if schema_version < 4:
warnings.warn(

Check warning on line 100 in python/ribasim/ribasim/migrations.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/migrations.py#L99-L100

Added lines #L99 - L100 were not covered by tests
f"Migrating outdated {node_type} / {table_type} table.", UserWarning
)
df.rename(columns={"priority": "demand_priority"}, inplace=True)
return df

Check warning on line 104 in python/ribasim/ribasim/migrations.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/migrations.py#L103-L104

Added lines #L103 - L104 were not covered by tests

globals()[f"{node_type.lower()}{table_type}_migration"] = migration_func
2 changes: 1 addition & 1 deletion ribasim_qgis/core/geopackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def layers(path: Path) -> list[str]:


# Keep version synced __schema_version__ in ribasim/__init__.py
def write_schema_version(path: Path, version: int = 3) -> None:
def write_schema_version(path: Path, version: int = 4) -> None:

Check warning on line 55 in ribasim_qgis/core/geopackage.py

View check run for this annotation

Codecov / codecov/patch

ribasim_qgis/core/geopackage.py#L55

Added line #L55 was not covered by tests
"""Write the schema version to the geopackage."""
with sqlite3_cursor(path) as cursor:
cursor.execute(
Expand Down

0 comments on commit 85d6d63

Please sign in to comment.