diff --git a/python/ribasim/ribasim/__init__.py b/python/ribasim/ribasim/__init__.py index 26b54545a..9deb0099f 100644 --- a/python/ribasim/ribasim/__init__.py +++ b/python/ribasim/ribasim/__init__.py @@ -1,5 +1,6 @@ __version__ = "2024.11.0" -__schema_version__ = 2 +# Keep synced write_schema_version in ribasim_qgis/core/geopackage.py +__schema_version__ = 3 from ribasim.config import Allocation, Logging, Node, Solver from ribasim.geometry.edge import EdgeTable diff --git a/python/ribasim/ribasim/migrations.py b/python/ribasim/ribasim/migrations.py index 31a326e83..d122b7e69 100644 --- a/python/ribasim/ribasim/migrations.py +++ b/python/ribasim/ribasim/migrations.py @@ -8,7 +8,7 @@ def nodeschema_migration(gdf: GeoDataFrame, schema_version: int) -> GeoDataFrame: - if "node_id" in gdf.columns and schema_version == 0: + if schema_version == 0 and "node_id" in gdf.columns: warnings.warn("Migrating outdated Node table.", UserWarning) assert gdf["node_id"].is_unique, "Node IDs have to be unique." gdf.set_index("node_id", inplace=True) @@ -27,7 +27,7 @@ def edgeschema_migration(gdf: GeoDataFrame, schema_version: int) -> GeoDataFrame warnings.warn("Migrating outdated Edge table.", UserWarning) assert gdf["edge_id"].is_unique, "Edge IDs have to be unique." gdf.set_index("edge_id", inplace=True) - if "subnetwork_id" in gdf.columns: + if schema_version < 3 and "subnetwork_id" in gdf.columns: warnings.warn("Migrating outdated Edge table.", UserWarning) gdf.drop(columns="subnetwork_id", inplace=True, errors="ignore") diff --git a/ribasim_qgis/core/geopackage.py b/ribasim_qgis/core/geopackage.py index 4017f7800..7af9c789a 100644 --- a/ribasim_qgis/core/geopackage.py +++ b/ribasim_qgis/core/geopackage.py @@ -51,7 +51,8 @@ def layers(path: Path) -> list[str]: return layers -def write_schema_version(path: Path, version: int = 2) -> None: +# Keep version synced __schema_version__ in ribasim/__init__.py +def write_schema_version(path: Path, version: int = 3) -> None: """Write the schema version to the geopackage.""" with sqlite3_cursor(path) as cursor: cursor.execute(