mirror of https://gitlab.com/pamhyr/pamhyr2
DB: Continue to prepare update 0.1.0.
parent
32cda58064
commit
1dfdcb0413
|
|
@ -123,6 +123,7 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
table = "geometry_profileXYZ"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
|
@ -141,6 +142,8 @@ class ProfileXYZ(Profile, SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
profiles = []
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ class HydraulicStructure(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
table = "hydraulic_structures"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
|
@ -122,6 +123,33 @@ class HydraulicStructure(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0_set_reach_pid(cls, execute, table, reachs):
|
||||
els = execute(
|
||||
f"SELECT pamhyr_id, input_reach, output_reach FROM {table}"
|
||||
)
|
||||
|
||||
for row in els:
|
||||
it = iter(row)
|
||||
pid = next(it)
|
||||
in_reach_id = next(it)
|
||||
out_reach_id = next(it)
|
||||
|
||||
if in_reach_id == -1:
|
||||
return
|
||||
|
||||
if out_reach_id == -1:
|
||||
out_reach_id = in_reach_id
|
||||
|
||||
execute(
|
||||
f"UPDATE {table} " +
|
||||
f"SET input_reach = {reachs[in_reach_id]}, " +
|
||||
f"output_reach = {reachs[out_reach_id]} " +
|
||||
f"WHERE pamhyr_id = {pid}"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ class Data(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
table = "initial_conditions"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
|
@ -111,6 +112,8 @@ class Data(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
id = data["reach"].pamhyr_id
|
||||
|
|
|
|||
|
|
@ -214,6 +214,7 @@ class LateralContribution(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
table = "lateral_contribution"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
|
@ -230,6 +231,8 @@ class LateralContribution(SQLSubModel):
|
|||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _get_ctor_from_type(cls, t):
|
||||
from Model.LateralContribution.LateralContributionTypes import (
|
||||
|
|
|
|||
|
|
@ -216,6 +216,9 @@ class SQLSubModel(PamhyrID):
|
|||
pid = next(it)
|
||||
node_id = next(it)
|
||||
|
||||
if node_id == -1:
|
||||
return
|
||||
|
||||
execute(
|
||||
f"UPDATE {table} " +
|
||||
f"SET node = {nodes[node_id]} " +
|
||||
|
|
@ -233,6 +236,9 @@ class SQLSubModel(PamhyrID):
|
|||
pid = next(it)
|
||||
reach_id = next(it)
|
||||
|
||||
if reach_id == -1:
|
||||
return
|
||||
|
||||
execute(
|
||||
f"UPDATE {table} " +
|
||||
f"SET reach = {reachs[reach_id]} " +
|
||||
|
|
|
|||
Loading…
Reference in New Issue