diff --git a/src/Model/HydraulicStructures/Basic/HydraulicStructures.py b/src/Model/HydraulicStructures/Basic/HydraulicStructures.py index bcbaabea..4540e28d 100644 --- a/src/Model/HydraulicStructures/Basic/HydraulicStructures.py +++ b/src/Model/HydraulicStructures/Basic/HydraulicStructures.py @@ -80,6 +80,7 @@ class BasicHS(SQLSubModel): @classmethod def _db_update_to_0_1_0(cls, execute, data): table = "hydraulic_structures_basic" + hs = data['id2pid']['hydraulic_structures'] cls.update_db_add_pamhyr_id(execute, table, data) Scenario.update_db_add_scenario(execute, table) @@ -96,6 +97,25 @@ class BasicHS(SQLSubModel): execute(f"DROP TABLE {table}") execute(f"ALTER TABLE {table}_tmp RENAME TO {table}") + cls._db_update_to_0_1_0_set_hs_pid(execute, table, hs) + + @classmethod + def _db_update_to_0_1_0_set_hs_pid(cls, execute, table, hs): + els = execute( + f"SELECT pamhyr_id, hs FROM {table}" + ) + + for row in els: + it = iter(row) + pid = next(it) + hs_id = next(it) + + execute( + f"UPDATE {table} " + + f"SET hs = {hs[hs_id]} " + + f"WHERE pamhyr_id = {pid}" + ) + @classmethod def _get_ctor_from_type(cls, t): from Model.HydraulicStructures.Basic.Types import ( diff --git a/src/Model/HydraulicStructures/Basic/Value.py b/src/Model/HydraulicStructures/Basic/Value.py index 54f762ba..f7fa21b7 100644 --- a/src/Model/HydraulicStructures/Basic/Value.py +++ b/src/Model/HydraulicStructures/Basic/Value.py @@ -67,6 +67,7 @@ class BHSValue(SQLSubModel): @classmethod def _db_update_to_0_1_0(cls, execute, data): table = "hydraulic_structures_basic_value" + bhs = data['id2pid']['hydraulic_structures_basic'] cls.update_db_add_pamhyr_id(execute, table, data) Scenario.update_db_add_scenario(execute, table) @@ -83,6 +84,25 @@ class BHSValue(SQLSubModel): execute(f"DROP TABLE {table}") execute(f"ALTER TABLE {table}_tmp RENAME TO {table}") + cls._db_update_to_0_1_0_set_bhs_pid(execute, table, bhs) + + @classmethod + def _db_update_to_0_1_0_set_bhs_pid(cls, execute, table, bhs): + els = execute( + f"SELECT pamhyr_id, bhs FROM {table}" + ) + + for row in els: + it = iter(row) + pid = next(it) + bhs_id = next(it) + + execute( + f"UPDATE {table} " + + f"SET bhs = {bhs[bhs_id]} " + + f"WHERE pamhyr_id = {pid}" + ) + @classmethod def _str_to_type(cls, type): res = str diff --git a/src/Model/LateralContribution/LateralContribution.py b/src/Model/LateralContribution/LateralContribution.py index e3bec9c6..637e3544 100644 --- a/src/Model/LateralContribution/LateralContribution.py +++ b/src/Model/LateralContribution/LateralContribution.py @@ -74,6 +74,7 @@ class Data(SQLSubModel): @classmethod def _db_update_to_0_1_0(cls, execute, data=None): table = "lateral_contribution_data" + lcs = data['id2pid']['lateral_contribution'] cls.update_db_add_pamhyr_id(execute, table, data) Scenario.update_db_add_scenario(execute, table) @@ -89,6 +90,25 @@ 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_lc_pid(execute, table, lcs) + + @classmethod + def _db_update_to_0_1_0_set_lc_pid(cls, execute, table, bcs): + els = execute( + f"SELECT pamhyr_id, lc FROM {table}" + ) + + for row in els: + it = iter(row) + pid = next(it) + lc_id = next(it) + + execute( + f"UPDATE {table} " + + f"SET lc = {lcs[lc_id]} " + + f"WHERE pamhyr_id = {pid}" + ) + @classmethod def _db_load(cls, execute, data=None): new = []