DB: Continue to prepare update 0.1.0.

This commit is contained in:
Pierre-Antoine Rouby committed 2024-08-05 12:00:10 +02:00
1 parent 32cda58064
commit 1dfdcb0413
5 files changed
+43

No files matched your search

+3
View File
@@ -123,6 +123,7 @@ class ProfileXYZ(Profile, SQLSubModel):
@classmethod @classmethod
def _db_update_to_0_1_0(cls, execute, data): def _db_update_to_0_1_0(cls, execute, data):
table = "geometry_profileXYZ" table = "geometry_profileXYZ"
reachs = data['id2pid']['river_reach']
cls.update_db_add_pamhyr_id(execute, table, data) cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table) Scenario.update_db_add_scenario(execute, table)
@@ -141,6 +142,8 @@ class ProfileXYZ(Profile, SQLSubModel):
execute(f"DROP TABLE {table}") execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}") execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
@classmethod @classmethod
def _db_load(cls, execute, data=None): def _db_load(cls, execute, data=None):
profiles = [] profiles = []
@@ -104,6 +104,7 @@ class HydraulicStructure(SQLSubModel):
@classmethod @classmethod
def _db_update_to_0_1_0(cls, execute, data): def _db_update_to_0_1_0(cls, execute, data):
table = "hydraulic_structures" table = "hydraulic_structures"
reachs = data['id2pid']['river_reach']
cls.update_db_add_pamhyr_id(execute, table, data) cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table) Scenario.update_db_add_scenario(execute, table)
@@ -122,6 +123,33 @@ class HydraulicStructure(SQLSubModel):
execute(f"DROP TABLE {table}") execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {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 @classmethod
def _db_load(cls, execute, data=None): def _db_load(cls, execute, data=None):
new = [] new = []
@@ -93,6 +93,7 @@ class Data(SQLSubModel):
@classmethod @classmethod
def _db_update_to_0_1_0(cls, execute, data): def _db_update_to_0_1_0(cls, execute, data):
table = "initial_conditions" table = "initial_conditions"
reachs = data['id2pid']['river_reach']
cls.update_db_add_pamhyr_id(execute, table, data) cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table) Scenario.update_db_add_scenario(execute, table)
@@ -111,6 +112,8 @@ class Data(SQLSubModel):
execute(f"DROP TABLE {table}") execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}") execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
@classmethod @classmethod
def _db_load(cls, execute, data=None): def _db_load(cls, execute, data=None):
id = data["reach"].pamhyr_id id = data["reach"].pamhyr_id
@@ -214,6 +214,7 @@ class LateralContribution(SQLSubModel):
@classmethod @classmethod
def _db_update_to_0_1_0(cls, execute, data): def _db_update_to_0_1_0(cls, execute, data):
table = "lateral_contribution" table = "lateral_contribution"
reachs = data['id2pid']['river_reach']
cls.update_db_add_pamhyr_id(execute, table, data) cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table) Scenario.update_db_add_scenario(execute, table)
@@ -230,6 +231,8 @@ class LateralContribution(SQLSubModel):
execute(f"DROP TABLE {table}") execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}") execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
@classmethod @classmethod
def _get_ctor_from_type(cls, t): def _get_ctor_from_type(cls, t):
from Model.LateralContribution.LateralContributionTypes import ( from Model.LateralContribution.LateralContributionTypes import (
+6
View File
@@ -216,6 +216,9 @@ class SQLSubModel(PamhyrID):
pid = next(it) pid = next(it)
node_id = next(it) node_id = next(it)
if node_id == -1:
return
execute( execute(
f"UPDATE {table} " + f"UPDATE {table} " +
f"SET node = {nodes[node_id]} " + f"SET node = {nodes[node_id]} " +
@@ -233,6 +236,9 @@ class SQLSubModel(PamhyrID):
pid = next(it) pid = next(it)
reach_id = next(it) reach_id = next(it)
if reach_id == -1:
return
execute( execute(
f"UPDATE {table} " + f"UPDATE {table} " +
f"SET reach = {reachs[reach_id]} " + f"SET reach = {reachs[reach_id]} " +