mirror of https://gitlab.com/pamhyr/pamhyr2
OutputRKAdists: Fix update and DB table name.
parent
826e532605
commit
f66d8c7a34
|
|
@ -128,10 +128,13 @@ class Friction(SQLSubModel):
|
||||||
b_s_id = next(it)
|
b_s_id = next(it)
|
||||||
e_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(
|
execute(
|
||||||
f"UPDATE {table} " +
|
f"UPDATE {table} " +
|
||||||
f"SET begin_strickler = {stricklers[b_s_id]}, " +
|
f"SET begin_strickler = {b_s}, " +
|
||||||
f"end_strickler = {stricklers[e_s_id]} " +
|
f"end_strickler = {e_s} " +
|
||||||
f"WHERE pamhyr_id = {pid}"
|
f"WHERE pamhyr_id = {pid}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ class OutputRKAdists(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
execute(
|
execute(
|
||||||
f"CREATE TABLE OutputRKAdists{ext}(" +
|
f"CREATE TABLE output_rk_adists{ext}(" +
|
||||||
f"{cls.create_db_add_pamhyr_id()},"
|
f"{cls.create_db_add_pamhyr_id()},"
|
||||||
"reach INTEGER NOT NULL, " +
|
"reach INTEGER NOT NULL, " +
|
||||||
"rk REAL NOT NULL, " +
|
"rk REAL NOT NULL, " +
|
||||||
|
|
@ -94,12 +94,15 @@ class OutputRKAdists(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update(cls, execute, version, data=None):
|
def _db_update(cls, execute, version, data=None):
|
||||||
major, minor, release = version.strip().split(".")
|
major, minor, release = version.strip().split(".")
|
||||||
|
created = False
|
||||||
|
|
||||||
if major == "0" and int(minor) <= 1:
|
if major == "0" and int(minor) <= 1:
|
||||||
if int(release) < 7:
|
if int(release) < 7:
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
|
created = True
|
||||||
|
|
||||||
elif major == "0" and int(minor) <= 2:
|
if major == "0" and int(minor) <= 2:
|
||||||
if int(release) <= 0:
|
if not created:
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
cls._db_update_to_0_2_0(execute, data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
@ -107,6 +110,7 @@ class OutputRKAdists(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_update_to_0_2_0(cls, execute, data):
|
def _db_update_to_0_2_0(cls, execute, data):
|
||||||
table = "OutputRKAdists"
|
table = "OutputRKAdists"
|
||||||
|
table_new = "output_rk_adists"
|
||||||
reachs = data['id2pid']['river_reach']
|
reachs = data['id2pid']['river_reach']
|
||||||
|
|
||||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||||
|
|
@ -115,16 +119,16 @@ class OutputRKAdists(SQLSubModel):
|
||||||
cls._db_create(execute, ext="_tmp")
|
cls._db_create(execute, ext="_tmp")
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
f"INSERT INTO {table}_tmp " +
|
f"INSERT INTO {table_new}_tmp " +
|
||||||
"(pamhyr_id, reach, rk, title, scenario) " +
|
"(pamhyr_id, reach, rk, title, scenario) " +
|
||||||
"SELECT pamhyr_id, reach, rk, scenario " +
|
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||||
f"FROM {table}"
|
f"FROM {table}"
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(f"DROP TABLE {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
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
|
|
@ -141,7 +145,7 @@ class OutputRKAdists(SQLSubModel):
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
"SELECT pamhyr_id, reach, rk, title, scenario " +
|
||||||
f"FROM OutputRKAdists"
|
f"FROM output_rk_adists"
|
||||||
)
|
)
|
||||||
|
|
||||||
if table is not None:
|
if table is not None:
|
||||||
|
|
@ -175,14 +179,14 @@ class OutputRKAdists(SQLSubModel):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM OutputRKAdists " +
|
"DELETE FROM output_rk_adists " +
|
||||||
f"WHERE pamhyr_id = {self.id} " +
|
f"WHERE pamhyr_id = {self.id} " +
|
||||||
f"AND scenario = {self._status.scenario_id} "
|
f"AND scenario = {self._status.scenario_id} "
|
||||||
)
|
)
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"OutputRKAdists(pamhyr_id, reach, rk, title, scenario) " +
|
"output_rk_adists(pamhyr_id, reach, rk, title, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._reach}, {self._rk}, " +
|
f"{self.id}, {self._reach}, {self._rk}, " +
|
||||||
f"'{self._db_format(self._title)}'" +
|
f"'{self._db_format(self._title)}'" +
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class OutputRKAdistsList(PamhyrModelList):
|
||||||
|
|
||||||
# Delete previous data
|
# Delete previous data
|
||||||
execute(
|
execute(
|
||||||
"DELETE FROM OutputRKAdists " +
|
"DELETE FROM output_rk_adists " +
|
||||||
f"WHERE scenario = {self._status.scenario_id}"
|
f"WHERE scenario = {self._status.scenario_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue