DB: Fixes for db 0.1.0 creation.

scenarios
Pierre-Antoine Rouby 2024-07-29 16:28:22 +02:00
parent 9ec080a107
commit 328f5656bf
11 changed files with 32 additions and 21 deletions

View File

@ -21,6 +21,7 @@ import logging
from tools import trace, timer
from Model.Tools.PamhyrDB import SQLSubModel
from Model.Scenario import Scenario
logger = logging.getLogger()
@ -55,7 +56,7 @@ class Friction(SQLSubModel):
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
FOREIGN KEY(begin_strickler) REFERENCES stricklers(pamhyr_id),
FOREIGN KEY(end_strickler) REFERENCES stricklers(pamhyr_id)
FOREIGN KEY(end_strickler) REFERENCES stricklers(pamhyr_id),
PRIMARY KEY(pamhyr_id, scenario)
)
""")

View File

@ -31,8 +31,7 @@ class PointXYZ(Point, SQLSubModel):
x: float = 0.0, y: float = 0.0, z: float = 0.0,
name: str = "", profile=None, status=None):
super(PointXYZ, self).__init__(
id=id
name=name, profile=profile, status=status
id=id, name=name, profile=profile, status=status
)
self._x = float(x)
@ -51,11 +50,11 @@ class PointXYZ(Point, SQLSubModel):
z INTEGER NOT NULL,
profile INTEGER NOT NULL,
sl INTEGER,
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(profile)
REFERENCES geometry_profileXYZ(pamhyr_id),
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
PRIMARY KEY(pamhyr_id, scenario)
)
""")

View File

@ -84,10 +84,10 @@ class ProfileXYZ(Profile, SQLSubModel):
code1 INTEGER NOT NULL,
code2 INTEGER NOT NULL,
sl INTEGER,
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
PRIMARY KEY(pamhyr_id, scenario)
)
""")

View File

@ -45,7 +45,6 @@ class Reach(SQLSubModel):
]
def __init__(self, status=None, parent=None):
self.id = parent.id if parent is not None else 0
self._status = status
self._parent = parent
self._profiles: List[Profile] = []
@ -53,6 +52,14 @@ class Reach(SQLSubModel):
self._guidelines_is_valid = False
self._guidelines = {}
@property
def pamhyr_id(self):
return self._parent.pamhyr_id
@property
def _pamhyr_id(self):
return self._parent.pamhyr_id
@classmethod
def _db_create(cls, execute):
return cls._create_submodel(execute)

View File

@ -21,6 +21,7 @@ import logging
from tools import trace, timer
from Model.Tools.PamhyrDB import SQLSubModel
from Model.Scenario import Scenario
from Model.Except import NotImplementedMethodeError
from Model.HydraulicStructures.Basic.Value import (
@ -48,7 +49,7 @@ class BasicHS(SQLSubModel):
self._data = []
@classmethod
def _db_create(cls, execute):
def _db_create(cls, execute, ext=""):
execute(f"""
CREATE TABLE hydraulic_structures_basic{ext} (
{cls.create_db_add_pamhyr_id()},
@ -56,9 +57,9 @@ class BasicHS(SQLSubModel):
type TEXT NOT NULL,
enabled BOOLEAN NOT NULL,
hs INTEGER,
FOREIGN KEY(hs) REFERENCES hydraulic_structures(pamhyr_id),
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(hs) REFERENCES hydraulic_structures(pamhyr_id),
PRIMARY KEY(pamhyr_id, scenario)
)
""")

View File

@ -17,6 +17,7 @@
# -*- coding: utf-8 -*-
from Model.Tools.PamhyrDB import SQLSubModel
from Model.Scenario import Scenario
class BHSValue(SQLSubModel):
@ -43,9 +44,9 @@ class BHSValue(SQLSubModel):
type TEXT NOT NULL,
value TEXT NOT NULL,
bhs INTEGER,
FOREIGN KEY(bhs) REFERENCES hydraulic_structures_basic(id),
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(bhs) REFERENCES hydraulic_structures_basic(id),
PRIMARY KEY(pamhyr_id, scenario)
)
""")

View File

@ -22,6 +22,7 @@ from functools import reduce
from tools import trace, timer, old_pamhyr_date_to_timestamp
from Model.Tools.PamhyrDB import SQLSubModel
from Model.Scenario import Scenario
from Model.Except import NotImplementedMethodeError
from Model.HydraulicStructures.Basic.HydraulicStructures import BasicHS
@ -63,10 +64,10 @@ class HydraulicStructure(SQLSubModel):
output_rk REAL NOT NULL,
input_reach INTEGER,
output_reach INTEGER,
FOREIGN KEY(input_reach) REFERENCES river_reach(pamhyr_id),
FOREIGN KEY(output_reach) REFERENCES river_reach(pamhyr_id),
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(input_reach) REFERENCES river_reach(pamhyr_id),
FOREIGN KEY(output_reach) REFERENCES river_reach(pamhyr_id),
PRIMARY KEY(pamhyr_id, scenario)
)
""")

View File

@ -47,7 +47,7 @@ class Data(SQLSubModel):
@classmethod
def _db_create(cls, execute, ext=""):
execute(f"""
CREATE TABLE lateral_contribution_data{ext}(
CREATE TABLE lateral_contribution_data{ext} (
{cls.create_db_add_pamhyr_id()},
ind INTEGER NOT NULL,
data0 TEXT NOT NULL,
@ -66,7 +66,7 @@ class Data(SQLSubModel):
def _db_update(cls, execute, version, data=None):
major, minor, release = version.strip().split(".")
if major == "0" and int(minor) < 1:
if major == minor == "0":
cls._db_update_to_0_1_0(execute)
return cls._update_submodel(execute, version, data)
@ -142,7 +142,7 @@ class Data(SQLSubModel):
class LateralContribution(SQLSubModel):
_sub_classes = []
_sub_classes = [Data]
_id_cnt = 0
def __init__(self, id: int = -1, name: str = "", status=None):

View File

@ -135,7 +135,7 @@ class Data(SQLSubModel):
class Reservoir(SQLSubModel):
_sub_classes = []
_sub_classes = [Data]
def __init__(self, id: int = -1,
name: str = "",

View File

@ -151,7 +151,7 @@ class RiverReach(Edge, SQLSubModel):
node1: RiverNode = None,
node2: RiverNode = None,
status=None):
self._pamhyr_id = self.get_new_pamhyr_id(id)
# self._pamhyr_id = self.get_new_pamhyr_id(id)
super(RiverReach, self).__init__(
id, name,

View File

@ -21,6 +21,7 @@ from functools import reduce
from tools import trace, timer
from Model.Tools.PamhyrDB import SQLSubModel
from Model.Scenario import Scenario
from Model.Except import NotImplementedMethodeError
@ -100,7 +101,7 @@ class Layer(SQLSubModel):
def _db_create(cls, execute, ext=""):
execute(f"""
CREATE TABLE sedimentary_layer_layer{ext} (
{cls.create_db_add_pamhyr_id()}
{cls.create_db_add_pamhyr_id()},
ind INTEGER NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL,
@ -109,9 +110,9 @@ class Layer(SQLSubModel):
sigma REAL NOT NULL,
critical_constraint REAL NOT NULL,
sl INTEGER,
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
{Scenario.create_db_add_scenario()},
{Scenario.create_db_add_scenario_fk()},
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
PRIMARY KEY(pamhyr_id, scenario)
)
""")
@ -266,7 +267,7 @@ class SedimentLayer(SQLSubModel):
def _db_create(cls, execute, ext=""):
execute(f"""
CREATE TABLE sedimentary_layer{ext} (
{cls.create_db_add_pamhyr_id()}
{cls.create_db_add_pamhyr_id()},
name TEXT NOT NULL,
comment TEXT NOT NULL,
{Scenario.create_db_add_scenario()},