mirror of https://gitlab.com/pamhyr/pamhyr2
DB: Fixes some table fk to prepare update to 0.1.0.
parent
16350b4dec
commit
4081f96d68
|
|
@ -74,6 +74,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 = "boundary_condition_data"
|
table = "boundary_condition_data"
|
||||||
|
bcs = data['id2pid']['boundary_condition']
|
||||||
|
|
||||||
cls.update_db_add_pamhyr_id(
|
cls.update_db_add_pamhyr_id(
|
||||||
execute, table,
|
execute, table,
|
||||||
|
|
@ -92,6 +93,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_bc_pid(execute, table, bcs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update_to_0_1_0_set_bc_pid(cls, execute, table, bcs):
|
||||||
|
els = execute(
|
||||||
|
f"SELECT pamhyr_id, bc FROM {table}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in els:
|
||||||
|
it = iter(row)
|
||||||
|
pid = next(it)
|
||||||
|
bc_id = next(it)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
f"UPDATE {table} " +
|
||||||
|
f"SET bc = {bcs[bc_id]}, " +
|
||||||
|
f"WHERE pamhyr_id = {pid}"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
|
|
@ -208,23 +228,7 @@ class BoundaryCondition(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_node_pid(execute, nodes)
|
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _db_update_to_0_1_0_set_node_pid(cls, execute, nodes):
|
|
||||||
bcs = execute(
|
|
||||||
"SELECT pamhyr_id, node FROM boundary_condition"
|
|
||||||
)
|
|
||||||
|
|
||||||
for row in bcs:
|
|
||||||
pid = row[0]
|
|
||||||
node_id = row[1]
|
|
||||||
|
|
||||||
execute(
|
|
||||||
"UPDATE boundary_condition " +
|
|
||||||
f"SET node = {nodes[node_id]} " +
|
|
||||||
f"WHERE pamhyr_id = {pid}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_ctor_from_type(cls, t):
|
def _get_ctor_from_type(cls, t):
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ class Friction(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update_to_0_1_0(cls, execute, data):
|
def _db_update_to_0_1_0(cls, execute, data):
|
||||||
table = "friction"
|
table = "friction"
|
||||||
|
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)
|
||||||
|
|
@ -95,6 +96,8 @@ class Friction(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):
|
||||||
new = []
|
new = []
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,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 = "reservoir_data"
|
table = "reservoir_data"
|
||||||
|
reservoirs = data['id2pid']['reservoir']
|
||||||
|
|
||||||
cls.update_db_add_pamhyr_id(
|
cls.update_db_add_pamhyr_id(
|
||||||
execute, table,
|
execute, table,
|
||||||
|
|
@ -81,6 +82,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_reservoir_pid(execute, table, reservoirs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update_to_0_1_0_set_reservoir_pid(cls, execute, table, reservoirs):
|
||||||
|
bcs = execute(
|
||||||
|
f"SELECT pamhyr_id, reservoir FROM {table}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in bcs:
|
||||||
|
it = iter(row)
|
||||||
|
pid = next(it)
|
||||||
|
reservoir_id = next(it)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
f"UPDATE {table} " +
|
||||||
|
f"SET reservoir = {reservoirs[reservoir_id]}, " +
|
||||||
|
f"WHERE pamhyr_id = {pid}"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
|
|
@ -199,23 +219,6 @@ class Reservoir(SQLSubModel):
|
||||||
|
|
||||||
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _db_update_to_0_1_0_set_node_pid(cls, execute, table, nodes):
|
|
||||||
bcs = execute(
|
|
||||||
f"SELECT pamhyr_id, node FROM {table}"
|
|
||||||
)
|
|
||||||
|
|
||||||
for row in bcs:
|
|
||||||
it = iter(row)
|
|
||||||
pid = next(it)
|
|
||||||
node_id = next(it)
|
|
||||||
|
|
||||||
execute(
|
|
||||||
f"UPDATE {table} " +
|
|
||||||
f"SET node = {nodes[node_id]}, " +
|
|
||||||
f"WHERE pamhyr_id = {pid}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
new = []
|
new = []
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,41 @@ class SQLSubModel(PamhyrID):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedMethodeError(cls, cls._db_update)
|
raise NotImplementedMethodeError(cls, cls._db_update)
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update_to_0_1_0_set_node_pid(cls, execute, table, nodes):
|
||||||
|
els = execute(
|
||||||
|
f"SELECT pamhyr_id, node FROM {table}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in els:
|
||||||
|
it = iter(row)
|
||||||
|
pid = next(it)
|
||||||
|
node_id = next(it)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
f"UPDATE {table} " +
|
||||||
|
f"SET node = {nodes[node_id]}, " +
|
||||||
|
f"WHERE pamhyr_id = {pid}"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_update_to_0_1_0_set_reach_pid(cls, execute, table, reachs):
|
||||||
|
els = execute(
|
||||||
|
f"SELECT pamhyr_id, reach FROM {table}"
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in els:
|
||||||
|
it = iter(row)
|
||||||
|
pid = next(it)
|
||||||
|
reach_id = next(it)
|
||||||
|
|
||||||
|
execute(
|
||||||
|
f"UPDATE {table} " +
|
||||||
|
f"SET reach = {reachs[reach_id]}, " +
|
||||||
|
f"WHERE pamhyr_id = {pid}"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
"""Load instance of this class from SQL data base
|
"""Load instance of this class from SQL data base
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue