mirror of https://gitlab.com/pamhyr/pamhyr2
DB: Prepare to update 0.1.0.
parent
1dfdcb0413
commit
3675dc5b9d
|
|
@ -80,6 +80,7 @@ class BasicHS(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_basic"
|
table = "hydraulic_structures_basic"
|
||||||
|
hs = data['id2pid']['hydraulic_structures']
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -96,6 +97,25 @@ class BasicHS(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_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
|
@classmethod
|
||||||
def _get_ctor_from_type(cls, t):
|
def _get_ctor_from_type(cls, t):
|
||||||
from Model.HydraulicStructures.Basic.Types import (
|
from Model.HydraulicStructures.Basic.Types import (
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ class BHSValue(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_basic_value"
|
table = "hydraulic_structures_basic_value"
|
||||||
|
bhs = data['id2pid']['hydraulic_structures_basic']
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -83,6 +84,25 @@ class BHSValue(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_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
|
@classmethod
|
||||||
def _str_to_type(cls, type):
|
def _str_to_type(cls, type):
|
||||||
res = str
|
res = str
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ class Data(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update_to_0_1_0(cls, execute, data=None):
|
def _db_update_to_0_1_0(cls, execute, data=None):
|
||||||
table = "lateral_contribution_data"
|
table = "lateral_contribution_data"
|
||||||
|
lcs = data['id2pid']['lateral_contribution']
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -89,6 +90,25 @@ 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_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
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue