DB: Prepare update to 0.1.0.

This commit is contained in:
Pierre-Antoine Rouby committed 2024-08-05 15:40:06 +02:00
1 parent 3675dc5b9d
commit bf7b18f158
5 files changed
+102 -3

No files matched your search

+21
View File
@@ -78,6 +78,7 @@ class Friction(SQLSubModel):
def _db_update_to_0_1_0(cls, execute, data):
table = "friction"
reachs = data['id2pid']['river_reach']
stricklers = data['id2pid']['stricklers']
cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table)
@@ -97,6 +98,26 @@ class Friction(SQLSubModel):
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
cls._db_update_to_0_1_0_set_stricklers_pid(execute, table, stricklers)
@classmethod
def _db_update_to_0_1_0_set_stricklers_pid(cls, execute, table, stricklers):
els = execute(
f"SELECT pamhyr_id, begin_strickler, end_strickler FROM {table}"
)
for row in els:
it = iter(row)
pid = next(it)
b_s_id = next(it)
e_s_id = next(it)
execute(
f"UPDATE {table} " +
f"SET begin_strickler = {stricklers[b_s_id]}, " +
f"end_strickler = {stricklers[e_s_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
+41 -2
View File
@@ -81,6 +81,8 @@ class PointXYZ(Point, SQLSubModel):
@classmethod
def _db_update_to_0_1_0(cls, execute, data):
table = "geometry_pointXYZ"
reachs = data['id2pid']['sedimentary_layer']
profiles = data['id2pid']['geometry_profileXYZ']
cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table)
@@ -89,14 +91,51 @@ class PointXYZ(Point, SQLSubModel):
execute(
f"INSERT INTO {table}_tmp " +
"(pamhyr_id, name, comment, minor, medium, scenario) " +
"SELECT pamhyr_id, name, comment, minor, medium, scenario " +
"(pamhyr_id, name, x, y, z, profile, sl, scenario) " +
"SELECT pamhyr_id, name, x, y, z, profile, sl, scenario " +
f"FROM {table}"
)
execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_profile_pid(execute, table, profiles)
cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl)
@classmethod
def _db_update_to_0_1_0_set_profile_pid(cls, execute, table, profiles):
els = execute(
f"SELECT pamhyr_id, profile FROM {table}"
)
for row in els:
it = iter(row)
pid = next(it)
profile_id = next(it)
execute(
f"UPDATE {table} " +
f"SET profile = {profiles[profile_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl):
els = execute(
f"SELECT pamhyr_id, sl FROM {table}"
)
for row in els:
it = iter(row)
pid = next(it)
sl_id = next(it)
execute(
f"UPDATE {table} " +
f"SET sl = {sl[sl_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
status = data["status"]
+19
View File
@@ -124,6 +124,7 @@ class ProfileXYZ(Profile, SQLSubModel):
def _db_update_to_0_1_0(cls, execute, data):
table = "geometry_profileXYZ"
reachs = data['id2pid']['river_reach']
sl = data['id2pid']['sedimentary_layer']
cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table)
@@ -143,6 +144,24 @@ class ProfileXYZ(Profile, SQLSubModel):
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_reach_pid(execute, table, reachs)
cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl)
@classmethod
def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl):
els = execute(
f"SELECT pamhyr_id, sl FROM {table}"
)
for row in els:
it = iter(row)
pid = next(it)
sl_id = next(it)
execute(
f"UPDATE {table} " +
f"SET sl = {sl[sl_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
@@ -93,7 +93,7 @@ class Data(SQLSubModel):
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):
def _db_update_to_0_1_0_set_lc_pid(cls, execute, table, lcs):
els = execute(
f"SELECT pamhyr_id, lc FROM {table}"
)
+20
View File
@@ -133,6 +133,7 @@ class Layer(SQLSubModel):
@classmethod
def _db_update_to_0_1_0(cls, execute, data):
table = "sedimentary_layer_layer"
sl = data['id2pid']['sedimentary_layer']
cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table)
@@ -151,6 +152,25 @@ class Layer(SQLSubModel):
execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
cls._db_update_to_0_1_0_set_sl_pid(execute, table, sl)
@classmethod
def _db_update_to_0_1_0_set_sl_pid(cls, execute, table, sl):
els = execute(
f"SELECT pamhyr_id, sl FROM {table}"
)
for row in els:
it = iter(row)
pid = next(it)
sl_id = next(it)
execute(
f"UPDATE {table} " +
f"SET sl = {sl[sl_id]} " +
f"WHERE pamhyr_id = {pid}"
)
@classmethod
def _db_load(cls, execute, data=None):
new = []