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

Inflow schema 300 #66

Merged
merged 33 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb9ae89
bump version
margrietpalm May 31, 2024
5d66d28
Change inflow models to match new schema
margrietpalm May 31, 2024
875a712
Implement migration
margrietpalm May 31, 2024
f83a065
Remove explicit link between surface and surface_parameters
margrietpalm Jun 4, 2024
13fead7
Add test for successfull upgrade and extend test data with samples co…
margrietpalm Jun 4, 2024
c85927e
Register tests for 223
margrietpalm Jun 4, 2024
0154b0c
update changes
margrietpalm Jun 4, 2024
99d8ee0
Check for dry_weather_flow value on migration
margrietpalm Jun 4, 2024
9aca398
Add manifest to include migration data in python package
margrietpalm Jun 4, 2024
b9bcba0
Add missing tags attribute
margrietpalm Jun 7, 2024
26b0985
Fix type of DryWeatherFlowMap.geom
margrietpalm Jun 10, 2024
3ecc08c
Remove resolved TODO
margrietpalm Jun 10, 2024
4ff0fa6
Attempt to fix geometry crs
margrietpalm Jun 10, 2024
6c3dd42
Merge branch 'master' into margriet_65_schema_300_inflow
margrietpalm Jun 13, 2024
499c157
Merge branch 'master' into margriet_65_schema_300_inflow
margrietpalm Jun 13, 2024
ff21c26
Modify tests to not use anything geopackage related
margrietpalm Jun 13, 2024
f5b749a
Skip tests because we know they fail (fix later)
margrietpalm Jun 17, 2024
7ace447
Fix migration for surfaces and dry weather flow
margrietpalm Jun 17, 2024
2d54993
Improve migration speed by properly filtering
margrietpalm Jun 18, 2024
43d59f3
Fix tests
margrietpalm Jun 18, 2024
fc372b3
Correctly use tmp_geom column
margrietpalm Jun 19, 2024
48bd959
Handle surfaces with multipolygon geometry
margrietpalm Jun 24, 2024
a8e78e7
Handle polygons :D :D :D :D :D
margrietpalm Jul 1, 2024
e998436
More fixes and make type tests not case sensitive
margrietpalm Jul 2, 2024
31c5331
Correct SQLite for creating geometries for DWF
margrietpalm Jul 2, 2024
e1ac02d
fix mistake
margrietpalm Jul 2, 2024
800481e
Fix typo
margrietpalm Jul 2, 2024
1c45a35
bump version for testing
margrietpalm Jul 5, 2024
b57fb79
Use server_default instead of default when making new columns with de…
margrietpalm Jul 30, 2024
e0b55b2
Revert using server_default
margrietpalm Jul 31, 2024
cf88667
Revert version to default
margrietpalm Aug 1, 2024
6d14a00
Remove commented class from model
margrietpalm Aug 1, 2024
76e96e5
Clarify changes
margrietpalm Aug 1, 2024
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
8 changes: 6 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Changelog of threedi-schema
0.222.3 (unreleased)
--------------------

- Nothing changed yet.
- Implement changes for schema version 300 concerning inflow
- Replace v2_surface and v2_impervious_surface (and maps) with surface and dry_weather_flow tables
- Redistribute data from v2_surface or v2_impervious_surface, depending on simulation_template_settings.use_0d_inflow, over suface and dry_weather_flow tables
- Populate surface_parameters and dry_weather_flow_distribution tables with default data
- A full overview can be obtained from the migration code (`threedi_schema/migrations/versions/0223_upgrade_db_inflow.py`)


0.222.2 (2024-06-13)
Expand All @@ -26,7 +30,7 @@ Changelog of threedi-schema

- Implement changes for schema version 300 concerning simulation settings
- Reduce all settings tables to a single row. Multiple settings per schematisation are no longer allowed.
- A full overview can most easily be obtained from the migration; to summarize:
- A full overview can most easily be obtained from the migration code (`threedi_schema/migrations/versions/0222_upgrade_db_settings.py`); to summarize:
- Rename settings tables from "v2_foo" to "foo"
- Rename several columns in settings tables
- Move settings to context specific tables instead of a single generic table
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include LICENSE
# Include docs in the root.
include *.rst
# Include migration data
include threedi_schema/migrations/versions/data/*
# Exclude byte-compiled code
recursive-exclude .venv *
recursive-exclude * __pycache__
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
markers =
migrations: all migration tests
migration_222: migration to schema 222
migration_223: migration to schema 223

2 changes: 1 addition & 1 deletion threedi_schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from .domain import constants, custom_types, models # NOQA

# fmt: off
__version__ = '0.222.3.dev0'
__version__ = '0.223.dev0'
# fmt: on
123 changes: 60 additions & 63 deletions threedi_schema/domain/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def max_infiltration_capacity_file(self):


class SurfaceParameter(Base):
__tablename__ = "v2_surface_parameters"
__tablename__ = "surface_parameters"
id = Column(Integer, primary_key=True)
outflow_delay = Column(Float, nullable=False)
surface_layer_thickness = Column(Float, nullable=False)
Expand All @@ -172,33 +172,63 @@ class SurfaceParameter(Base):
min_infiltration_capacity = Column(Float, nullable=False)
infiltration_decay_constant = Column(Float, nullable=False)
infiltration_recovery_constant = Column(Float, nullable=False)

surface = relationship(
"Surface",
back_populates="surface_parameters",
)
tags = Column(Text)
description = Column(Text)


class Surface(Base):
__tablename__ = "v2_surface"
__tablename__ = "surface"
id = Column(Integer, primary_key=True)
display_name = Column(String(255))
code = Column(String(100))
zoom_category = Column(IntegerEnum(constants.ZoomCategories))
nr_of_inhabitants = Column(Float)
dry_weather_flow = Column(Float)
function = Column(String(64))
display_name = Column(String(255))
area = Column(Float)
surface_parameters_id = Column(
Integer, ForeignKey(SurfaceParameter.__tablename__ + ".id"), nullable=False
)
the_geom = Column(
Geometry("GEOMETRY"),
geom = Column(
Geometry("POLYGON"),
nullable=True,
)
surface_parameters = relationship(
SurfaceParameter, foreign_keys=surface_parameters_id, back_populates="surface"
tags = Column(Text)


class DryWeatherFlow(Base):
__tablename__ = "dry_weather_flow"
id = Column(Integer, primary_key=True)
multiplier = Column(Float)
dry_weather_flow_distribution_id = Column(Text)
daily_total = Column(Float)
interpolate = Column(Boolean)
display_name = Column(String(255))
code = Column(String(100))
geom = Column(
Geometry("POLYGON"),
nullable=False,
)
tags = Column(Text)


class DryWeatherFlowMap(Base):
__tablename__ = "dry_weather_flow_map"
id = Column(Integer, primary_key=True)
connection_node_id = Column(Integer)
dry_weather_flow_id = Column(Integer)
display_name = Column(String(255))
code = Column(String(100))
geom = Column(
Geometry("LINESTRING"),
nullable=False,
)
percentage = Column(Float)
tags = Column(Text)


class DryWeatherFlowDistribution(Base):
__tablename__ = "dry_weather_flow_distribution"
id = Column(Integer, primary_key=True)
description = Column(Text)
tags = Column(Text)
distribution = Column(Text)


class GroundWater(Base):
Expand Down Expand Up @@ -289,9 +319,6 @@ class ConnectionNode(Base):
boundary_conditions = relationship(
"BoundaryCondition1D", back_populates="connection_node"
)
impervious_surface_maps = relationship(
"ImperviousSurfaceMap", back_populates="connection_node"
)
laterals1d = relationship("Lateral1d", back_populates="connection_node")


Expand Down Expand Up @@ -497,13 +524,17 @@ class BoundaryCondition1D(Base):


class SurfaceMap(Base):
__tablename__ = "v2_surface_map"
__tablename__ = "surface_map"
id = Column(Integer, primary_key=True)
surface_id = Column(Integer, nullable=False)
connection_node_id = Column(
Integer, ForeignKey(ConnectionNode.__tablename__ + ".id"), nullable=False
)
percentage = Column(Float)
geom = Column(Geometry("LINESTRING"), nullable=False)
tags = Column(Text)
code = Column(String(100))
display_name = Column(String(255))


class Channel(Base):
Expand Down Expand Up @@ -772,47 +803,6 @@ class Obstacle(Base):
the_geom = Column(Geometry("LINESTRING"), nullable=False)


class ImperviousSurface(Base):
__tablename__ = "v2_impervious_surface"
id = Column(Integer, primary_key=True)
code = Column(String(100))
display_name = Column(String(255))
surface_inclination = Column(
VarcharEnum(constants.SurfaceInclinationType), nullable=False
)
surface_class = Column(VarcharEnum(constants.SurfaceClass), nullable=False)
surface_sub_class = Column(String(128))
zoom_category = Column(IntegerEnum(constants.ZoomCategories))
nr_of_inhabitants = Column(Float)
area = Column(Float)
dry_weather_flow = Column(Float)
the_geom = Column(
Geometry("GEOMETRY"),
nullable=True,
)
impervious_surface_maps = relationship(
"ImperviousSurfaceMap", back_populates="impervious_surface"
)


class ImperviousSurfaceMap(Base):
__tablename__ = "v2_impervious_surface_map"
id = Column(Integer, primary_key=True)
percentage = Column(Float, nullable=False)
impervious_surface_id = Column(
Integer, ForeignKey(ImperviousSurface.__tablename__ + ".id"), nullable=False
)
impervious_surface = relationship(
ImperviousSurface, back_populates="impervious_surface_maps"
)
connection_node_id = Column(
Integer, ForeignKey(ConnectionNode.__tablename__ + ".id"), nullable=False
)
connection_node = relationship(
ConnectionNode, back_populates="impervious_surface_maps"
)


class PotentialBreach(Base):
__tablename__ = "v2_potential_breach"
id = Column(Integer, primary_key=True)
Expand Down Expand Up @@ -843,6 +833,12 @@ class ExchangeLine(Base):
exchange_level = Column(Float)


class Tags(Base):
__tablename__ = "tags"
id = Column(Integer, primary_key=True)
description = Column(Text)


DECLARED_MODELS = [
AggregationSettings,
BoundaryCondition1D,
Expand All @@ -862,14 +858,15 @@ class ExchangeLine(Base):
CrossSectionLocation,
Culvert,
DemAverageArea,
DryWeatherFlow,
DryWeatherFlowMap,
DryWeatherFlowDistribution,
ExchangeLine,
Floodfill,
ModelSettings,
GridRefinement,
GridRefinementArea,
GroundWater,
ImperviousSurface,
ImperviousSurfaceMap,
Interflow,
Lateral1d,
Lateral2D,
Expand Down
Loading
Loading