mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
DB: Fixes some table fk to prepare update to 0.1.0.
This commit is contained in:
1 parent
16350b4dec
commit
4081f96d68
4 files changed
+79
-34
No files matched your search
@@ -74,6 +74,7 @@ class Data(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_update_to_0_1_0(cls, execute, data):
|
||||
table = "boundary_condition_data"
|
||||
bcs = data['id2pid']['boundary_condition']
|
||||
|
||||
cls.update_db_add_pamhyr_id(
|
||||
execute, table,
|
||||
@@ -92,6 +93,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_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
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
@@ -208,23 +228,7 @@ class BoundaryCondition(SQLSubModel):
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_1_0_set_node_pid(execute, 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}"
|
||||
)
|
||||
cls._db_update_to_0_1_0_set_node_pid(execute, table, nodes)
|
||||
|
||||
@classmethod
|
||||
def _get_ctor_from_type(cls, t):
|
||||
|
||||
Reference in new issue
Block a user