From 6e79fe4cd5bda02e54de51d3b1cbfd5eff693c09 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Fri, 15 Aug 2025 13:54:21 +0200 Subject: [PATCH] Pollutants: Fix update for sceanrio. --- src/Model/Pollutants/Pollutants.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Model/Pollutants/Pollutants.py b/src/Model/Pollutants/Pollutants.py index dc733d49..f03c5162 100644 --- a/src/Model/Pollutants/Pollutants.py +++ b/src/Model/Pollutants/Pollutants.py @@ -107,13 +107,17 @@ 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: - cls._db_update_to_0_2_0(execute, data) - cls._db_update_to_0_2_0_char(execute, data) + 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) return True @@ -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))})" )