Pollutants: Fix update for sceanrio.

scenarios
Pierre-Antoine 2025-08-15 13:54:21 +02:00
parent f66d8c7a34
commit 6e79fe4cd5
1 changed files with 13 additions and 9 deletions

View File

@ -107,11 +107,15 @@ class Pollutants(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 major == "0" and int(minor) < 2:
if not created:
cls._db_update_to_0_2_0(execute, data)
cls._db_update_to_0_2_0_char(execute, data)
@ -125,12 +129,12 @@ class Pollutants(SQLSubModel):
cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table)
cls._db_create_lca(execute, ext="_tmp")
cls._db_create_pol(execute, ext="_tmp")
execute(
f"INSERT INTO {table_new}_tmp " +
"(pamhyr_id, name, scenario) " +
"SELECT pamhyr_id, name, scenario) " +
"SELECT pamhyr_id, name, scenario " +
f"FROM {table}"
)
@ -145,7 +149,7 @@ class Pollutants(SQLSubModel):
cls.update_db_add_pamhyr_id(execute, table, data)
Scenario.update_db_add_scenario(execute, table)
cls._db_create_lca(execute, ext="_tmp")
cls._db_create_pol_char(execute, ext="_tmp")
execute(
f"INSERT INTO {table_new}_tmp " +
@ -179,11 +183,11 @@ class Pollutants(SQLSubModel):
if table is not None:
for row in table:
id = row[0]
pid = row[0]
name = row[1]
new_pollutant = cls(
id=id, name=name,
id=pid, name=name,
status=status
)
@ -191,7 +195,7 @@ class Pollutants(SQLSubModel):
table = execute(
"SELECT * " +
"FROM pollutants_characteristics " +
f"WHERE pollutant = {id}" +
f"WHERE pollutant = {pid} " +
f"AND scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
)