OutputRKAdists: Fix update and DB table name.

scenarios
Pierre-Antoine 2025-08-15 13:39:16 +02:00
parent 826e532605
commit f66d8c7a34
3 changed files with 20 additions and 13 deletions

View File

@ -128,10 +128,13 @@ class Friction(SQLSubModel):
b_s_id = next(it)
e_s_id = next(it)
b_s = stricklers[b_s_id] if b_s_id != -1 else -1
e_s = stricklers[e_s_id] if e_s_id != -1 else -1
execute(
f"UPDATE {table} " +
f"SET begin_strickler = {stricklers[b_s_id]}, " +
f"end_strickler = {stricklers[e_s_id]} " +
f"SET begin_strickler = {b_s}, " +
f"end_strickler = {e_s} " +
f"WHERE pamhyr_id = {pid}"
)

View File

@ -78,7 +78,7 @@ class OutputRKAdists(SQLSubModel):
@classmethod
def _db_create(cls, execute, ext=""):
execute(
f"CREATE TABLE OutputRKAdists{ext}(" +
f"CREATE TABLE output_rk_adists{ext}(" +
f"{cls.create_db_add_pamhyr_id()},"
"reach INTEGER NOT NULL, " +
"rk REAL NOT NULL, " +
@ -94,12 +94,15 @@ class OutputRKAdists(SQLSubModel):
@classmethod
def _db_update(cls, execute, version, data=None):
major, minor, release = version.strip().split(".")
created = False
if major == "0" and int(minor) <= 1:
if int(release) < 7:
cls._db_create(execute)
created = True
elif major == "0" and int(minor) <= 2:
if int(release) <= 0:
if major == "0" and int(minor) <= 2:
if not created:
cls._db_update_to_0_2_0(execute, data)
return True
@ -107,6 +110,7 @@ class OutputRKAdists(SQLSubModel):
@classmethod
def _db_update_to_0_2_0(cls, execute, data):
table = "OutputRKAdists"
table_new = "output_rk_adists"
reachs = data['id2pid']['river_reach']
cls.update_db_add_pamhyr_id(execute, table, data)
@ -115,16 +119,16 @@ class OutputRKAdists(SQLSubModel):
cls._db_create(execute, ext="_tmp")
execute(
f"INSERT INTO {table}_tmp " +
f"INSERT INTO {table_new}_tmp " +
"(pamhyr_id, reach, rk, title, scenario) " +
"SELECT pamhyr_id, reach, rk, scenario " +
"SELECT pamhyr_id, reach, rk, title, scenario " +
f"FROM {table}"
)
execute(f"DROP TABLE {table}")
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
execute(f"ALTER TABLE {table_new}_tmp RENAME TO {table_new}")
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
cls._db_update_to_0_2_0_set_reach_pid(execute, table_new, reachs)
@classmethod
def _db_load(cls, execute, data=None):
@ -141,7 +145,7 @@ class OutputRKAdists(SQLSubModel):
table = execute(
"SELECT pamhyr_id, reach, rk, title, scenario " +
f"FROM OutputRKAdists"
f"FROM output_rk_adists"
)
if table is not None:
@ -175,14 +179,14 @@ class OutputRKAdists(SQLSubModel):
return True
execute(
"DELETE FROM OutputRKAdists " +
"DELETE FROM output_rk_adists " +
f"WHERE pamhyr_id = {self.id} " +
f"AND scenario = {self._status.scenario_id} "
)
execute(
"INSERT INTO " +
"OutputRKAdists(pamhyr_id, reach, rk, title, scenario) " +
"output_rk_adists(pamhyr_id, reach, rk, title, scenario) " +
"VALUES (" +
f"{self.id}, {self._reach}, {self._rk}, " +
f"'{self._db_format(self._title)}'" +

View File

@ -39,7 +39,7 @@ class OutputRKAdistsList(PamhyrModelList):
# Delete previous data
execute(
"DELETE FROM OutputRKAdists " +
"DELETE FROM output_rk_adists " +
f"WHERE scenario = {self._status.scenario_id}"
)