mirror of https://gitlab.com/pamhyr/pamhyr2
DB version: Upgrade to add enabled in pollutants db
parent
a425c9a6ac
commit
c51c06e6ec
|
|
@ -354,6 +354,7 @@ class Pollutants(SQLSubModel):
|
|||
CREATE TABLE pollutants{ext}(
|
||||
{cls.create_db_add_pamhyr_id()},
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
name TEXT NOT NULL,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()}
|
||||
|
|
@ -378,6 +379,14 @@ class Pollutants(SQLSubModel):
|
|||
if major == "0" and int(minor) < 2:
|
||||
if not created:
|
||||
cls._db_update_to_0_2_0(execute, data)
|
||||
|
||||
if major == "0" and minor == "2":
|
||||
if int(release) < 5:
|
||||
execute(f"ALTER TABLE pollutants " +
|
||||
f"ADD COLUMN enabled BOOLEAN NOT NULL DEFAULT TRUE")
|
||||
|
||||
# cls._db_update_to_0_2_5(execute, data)
|
||||
# # created = True
|
||||
|
||||
if not created:
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
|
@ -416,7 +425,7 @@ class Pollutants(SQLSubModel):
|
|||
return new
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, deleted, name, scenario FROM pollutants " +
|
||||
"SELECT pamhyr_id, deleted, enabled, name, scenario FROM pollutants " +
|
||||
f"WHERE scenario = {scenario.id} " +
|
||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||
)
|
||||
|
|
@ -427,6 +436,7 @@ class Pollutants(SQLSubModel):
|
|||
|
||||
pid = next(it)
|
||||
deleted = (next(it) == 1)
|
||||
enabled = (next(it) == 1)
|
||||
name = next(it)
|
||||
owner_scenario = next(it)
|
||||
|
||||
|
|
@ -437,6 +447,8 @@ class Pollutants(SQLSubModel):
|
|||
)
|
||||
if deleted:
|
||||
new_pollutant.set_as_deleted()
|
||||
if not enabled:
|
||||
new_pollutant.enabled = False
|
||||
|
||||
data["pollutant"] = new_pollutant
|
||||
new_pollutant._data = PollutantCharacteristics._db_load(
|
||||
|
|
@ -478,9 +490,10 @@ class Pollutants(SQLSubModel):
|
|||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"pollutants(pamhyr_id, deleted, name, scenario) " +
|
||||
"pollutants(pamhyr_id, deleted, enabled, name, scenario) " +
|
||||
"VALUES (" +
|
||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||
f"{self._db_format(self._enabled)}, " +
|
||||
f"'{self._db_format(self._name)}', " +
|
||||
f"{self._status.scenario_id}" +
|
||||
")"
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ logger = logging.getLogger()
|
|||
|
||||
|
||||
class Study(SQLModel):
|
||||
_version = "0.2.4"
|
||||
_version = "0.2.5"
|
||||
|
||||
_sub_classes = [
|
||||
Scenario,
|
||||
|
|
|
|||
Loading…
Reference in New Issue