mirror of https://gitlab.com/pamhyr/pamhyr2
Adists: OutputRK: Prepare update for scenarios.
parent
7fa86c29e7
commit
5a6574921a
|
|
@ -77,13 +77,15 @@ class OutputRKAdists(SQLSubModel):
|
|||
self._status.modified()
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(
|
||||
"CREATE TABLE OutputRKAdists(" +
|
||||
"id INTEGER NOT NULL PRIMARY KEY, " +
|
||||
f"CREATE TABLE OutputRKAdists{ext}(" +
|
||||
f"{cls.create_db_add_pamhyr_id()},"
|
||||
"reach INTEGER NOT NULL, " +
|
||||
"rk REAL NOT NULL, " +
|
||||
"title TEXT NOT NULL, " +
|
||||
f"{Scenario.create_db_add_scenario()},"
|
||||
f"{Scenario.create_db_add_scenario_fk()},"
|
||||
"FOREIGN KEY(reach) REFERENCES river_reach(id)" +
|
||||
")"
|
||||
)
|
||||
|
|
@ -97,8 +99,34 @@ class OutputRKAdists(SQLSubModel):
|
|||
if int(release) < 7:
|
||||
cls._db_create(execute)
|
||||
|
||||
if major == "0" and int(minor) <= 2:
|
||||
if int(release) <= 0:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def _db_update_to_0_2_0(cls, execute, data):
|
||||
table = "OutputRKAdists"
|
||||
reachs = data['id2pid']['river_reach']
|
||||
|
||||
cls.update_db_add_pamhyr_id(execute, table, data)
|
||||
Scenario.update_db_add_scenario(execute, table)
|
||||
|
||||
cls._db_create(execute, ext="_tmp")
|
||||
|
||||
execute(
|
||||
f"INSERT INTO {table}_tmp " +
|
||||
"(pamhyr_id, reach, rk, title, scenario) " +
|
||||
"SELECT pamhyr_id, reach, rk, scenario " +
|
||||
f"FROM {table}"
|
||||
)
|
||||
|
||||
execute(f"DROP TABLE {table}")
|
||||
execute(f"ALTER TABLE {table}_tmp RENAME TO {table}")
|
||||
|
||||
cls._db_update_to_0_2_0_set_reach_pid(execute, table, reachs)
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
|
|
|
|||
|
|
@ -38,7 +38,10 @@ class OutputRKAdistsList(PamhyrModelList):
|
|||
ok = True
|
||||
|
||||
# Delete previous data
|
||||
execute("DELETE FROM OutputRKAdists")
|
||||
execute(
|
||||
"DELETE FROM OutputRKAdists" +
|
||||
f"AND scenario = {self._status.scenario_id}"
|
||||
)
|
||||
|
||||
for sl in self._lst:
|
||||
ok &= sl._db_save(execute, data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue