Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump schema version to 3 #1979

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/ribasim/ribasim/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/ribasim/ribasim/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion ribasim_qgis/core/geopackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
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:

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
Loading