mirror of https://gitlab.com/pamhyr/pamhyr2
DB: Fixes for db 0.1.0 creation.
parent
9ec080a107
commit
328f5656bf
|
|
@ -21,6 +21,7 @@ import logging
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Scenario import Scenario
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
@ -55,7 +56,7 @@ class Friction(SQLSubModel):
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
|
FOREIGN KEY(reach) REFERENCES river_reach(pamhyr_id),
|
||||||
FOREIGN KEY(begin_strickler) REFERENCES stricklers(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)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,7 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
x: float = 0.0, y: float = 0.0, z: float = 0.0,
|
x: float = 0.0, y: float = 0.0, z: float = 0.0,
|
||||||
name: str = "", profile=None, status=None):
|
name: str = "", profile=None, status=None):
|
||||||
super(PointXYZ, self).__init__(
|
super(PointXYZ, self).__init__(
|
||||||
id=id
|
id=id, name=name, profile=profile, status=status
|
||||||
name=name, profile=profile, status=status
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self._x = float(x)
|
self._x = float(x)
|
||||||
|
|
@ -51,11 +50,11 @@ class PointXYZ(Point, SQLSubModel):
|
||||||
z INTEGER NOT NULL,
|
z INTEGER NOT NULL,
|
||||||
profile INTEGER NOT NULL,
|
profile INTEGER NOT NULL,
|
||||||
sl INTEGER,
|
sl INTEGER,
|
||||||
|
{Scenario.create_db_add_scenario()},
|
||||||
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
FOREIGN KEY(profile)
|
FOREIGN KEY(profile)
|
||||||
REFERENCES geometry_profileXYZ(pamhyr_id),
|
REFERENCES geometry_profileXYZ(pamhyr_id),
|
||||||
FOREIGN KEY(sl) REFERENCES sedimentary_layer(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)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -84,10 +84,10 @@ class ProfileXYZ(Profile, SQLSubModel):
|
||||||
code1 INTEGER NOT NULL,
|
code1 INTEGER NOT NULL,
|
||||||
code2 INTEGER NOT NULL,
|
code2 INTEGER NOT NULL,
|
||||||
sl INTEGER,
|
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()},
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{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)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ class Reach(SQLSubModel):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, status=None, parent=None):
|
def __init__(self, status=None, parent=None):
|
||||||
self.id = parent.id if parent is not None else 0
|
|
||||||
self._status = status
|
self._status = status
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
self._profiles: List[Profile] = []
|
self._profiles: List[Profile] = []
|
||||||
|
|
@ -53,6 +52,14 @@ class Reach(SQLSubModel):
|
||||||
self._guidelines_is_valid = False
|
self._guidelines_is_valid = False
|
||||||
self._guidelines = {}
|
self._guidelines = {}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pamhyr_id(self):
|
||||||
|
return self._parent.pamhyr_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _pamhyr_id(self):
|
||||||
|
return self._parent.pamhyr_id
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute):
|
def _db_create(cls, execute):
|
||||||
return cls._create_submodel(execute)
|
return cls._create_submodel(execute)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import logging
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Scenario import Scenario
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
from Model.HydraulicStructures.Basic.Value import (
|
from Model.HydraulicStructures.Basic.Value import (
|
||||||
|
|
@ -48,7 +49,7 @@ class BasicHS(SQLSubModel):
|
||||||
self._data = []
|
self._data = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE hydraulic_structures_basic{ext} (
|
CREATE TABLE hydraulic_structures_basic{ext} (
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
|
|
@ -56,9 +57,9 @@ class BasicHS(SQLSubModel):
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
enabled BOOLEAN NOT NULL,
|
enabled BOOLEAN NOT NULL,
|
||||||
hs INTEGER,
|
hs INTEGER,
|
||||||
FOREIGN KEY(hs) REFERENCES hydraulic_structures(pamhyr_id),
|
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
|
FOREIGN KEY(hs) REFERENCES hydraulic_structures(pamhyr_id),
|
||||||
PRIMARY KEY(pamhyr_id, scenario)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Scenario import Scenario
|
||||||
|
|
||||||
|
|
||||||
class BHSValue(SQLSubModel):
|
class BHSValue(SQLSubModel):
|
||||||
|
|
@ -43,9 +44,9 @@ class BHSValue(SQLSubModel):
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
value TEXT NOT NULL,
|
value TEXT NOT NULL,
|
||||||
bhs INTEGER,
|
bhs INTEGER,
|
||||||
FOREIGN KEY(bhs) REFERENCES hydraulic_structures_basic(id),
|
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
|
FOREIGN KEY(bhs) REFERENCES hydraulic_structures_basic(id),
|
||||||
PRIMARY KEY(pamhyr_id, scenario)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ from functools import reduce
|
||||||
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
from tools import trace, timer, old_pamhyr_date_to_timestamp
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Scenario import Scenario
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
from Model.HydraulicStructures.Basic.HydraulicStructures import BasicHS
|
from Model.HydraulicStructures.Basic.HydraulicStructures import BasicHS
|
||||||
|
|
@ -63,10 +64,10 @@ class HydraulicStructure(SQLSubModel):
|
||||||
output_rk REAL NOT NULL,
|
output_rk REAL NOT NULL,
|
||||||
input_reach INTEGER,
|
input_reach INTEGER,
|
||||||
output_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()},
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{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)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class Data(SQLSubModel):
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
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)
|
cls._db_update_to_0_1_0(execute)
|
||||||
|
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
@ -142,7 +142,7 @@ class Data(SQLSubModel):
|
||||||
|
|
||||||
|
|
||||||
class LateralContribution(SQLSubModel):
|
class LateralContribution(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = [Data]
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id: int = -1, name: str = "", status=None):
|
def __init__(self, id: int = -1, name: str = "", status=None):
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ class Data(SQLSubModel):
|
||||||
|
|
||||||
|
|
||||||
class Reservoir(SQLSubModel):
|
class Reservoir(SQLSubModel):
|
||||||
_sub_classes = []
|
_sub_classes = [Data]
|
||||||
|
|
||||||
def __init__(self, id: int = -1,
|
def __init__(self, id: int = -1,
|
||||||
name: str = "",
|
name: str = "",
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ class RiverReach(Edge, SQLSubModel):
|
||||||
node1: RiverNode = None,
|
node1: RiverNode = None,
|
||||||
node2: RiverNode = None,
|
node2: RiverNode = None,
|
||||||
status=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__(
|
super(RiverReach, self).__init__(
|
||||||
id, name,
|
id, name,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from functools import reduce
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
|
from Model.Scenario import Scenario
|
||||||
from Model.Except import NotImplementedMethodeError
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -100,7 +101,7 @@ class Layer(SQLSubModel):
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE sedimentary_layer_layer{ext} (
|
CREATE TABLE sedimentary_layer_layer{ext} (
|
||||||
{cls.create_db_add_pamhyr_id()}
|
{cls.create_db_add_pamhyr_id()},
|
||||||
ind INTEGER NOT NULL,
|
ind INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
|
|
@ -109,9 +110,9 @@ class Layer(SQLSubModel):
|
||||||
sigma REAL NOT NULL,
|
sigma REAL NOT NULL,
|
||||||
critical_constraint REAL NOT NULL,
|
critical_constraint REAL NOT NULL,
|
||||||
sl INTEGER,
|
sl INTEGER,
|
||||||
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
|
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
{Scenario.create_db_add_scenario_fk()},
|
{Scenario.create_db_add_scenario_fk()},
|
||||||
|
FOREIGN KEY(sl) REFERENCES sedimentary_layer(pamhyr_id),
|
||||||
PRIMARY KEY(pamhyr_id, scenario)
|
PRIMARY KEY(pamhyr_id, scenario)
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
@ -266,7 +267,7 @@ class SedimentLayer(SQLSubModel):
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(f"""
|
execute(f"""
|
||||||
CREATE TABLE sedimentary_layer{ext} (
|
CREATE TABLE sedimentary_layer{ext} (
|
||||||
{cls.create_db_add_pamhyr_id()}
|
{cls.create_db_add_pamhyr_id()},
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
comment TEXT NOT NULL,
|
comment TEXT NOT NULL,
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue