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}(
|
CREATE TABLE pollutants{ext}(
|
||||||
{cls.create_db_add_pamhyr_id()},
|
{cls.create_db_add_pamhyr_id()},
|
||||||
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
deleted BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
{Scenario.create_db_add_scenario()},
|
{Scenario.create_db_add_scenario()},
|
||||||
{Scenario.create_db_add_scenario_fk()}
|
{Scenario.create_db_add_scenario_fk()}
|
||||||
|
|
@ -379,6 +380,14 @@ class Pollutants(SQLSubModel):
|
||||||
if not created:
|
if not created:
|
||||||
cls._db_update_to_0_2_0(execute, data)
|
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:
|
if not created:
|
||||||
return cls._update_submodel(execute, version, data)
|
return cls._update_submodel(execute, version, data)
|
||||||
|
|
||||||
|
|
@ -416,7 +425,7 @@ class Pollutants(SQLSubModel):
|
||||||
return new
|
return new
|
||||||
|
|
||||||
table = execute(
|
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"WHERE scenario = {scenario.id} " +
|
||||||
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))})"
|
||||||
)
|
)
|
||||||
|
|
@ -427,6 +436,7 @@ class Pollutants(SQLSubModel):
|
||||||
|
|
||||||
pid = next(it)
|
pid = next(it)
|
||||||
deleted = (next(it) == 1)
|
deleted = (next(it) == 1)
|
||||||
|
enabled = (next(it) == 1)
|
||||||
name = next(it)
|
name = next(it)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
|
|
@ -437,6 +447,8 @@ class Pollutants(SQLSubModel):
|
||||||
)
|
)
|
||||||
if deleted:
|
if deleted:
|
||||||
new_pollutant.set_as_deleted()
|
new_pollutant.set_as_deleted()
|
||||||
|
if not enabled:
|
||||||
|
new_pollutant.enabled = False
|
||||||
|
|
||||||
data["pollutant"] = new_pollutant
|
data["pollutant"] = new_pollutant
|
||||||
new_pollutant._data = PollutantCharacteristics._db_load(
|
new_pollutant._data = PollutantCharacteristics._db_load(
|
||||||
|
|
@ -478,9 +490,10 @@ class Pollutants(SQLSubModel):
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"pollutants(pamhyr_id, deleted, name, scenario) " +
|
"pollutants(pamhyr_id, deleted, enabled, name, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
||||||
|
f"{self._db_format(self._enabled)}, " +
|
||||||
f"'{self._db_format(self._name)}', " +
|
f"'{self._db_format(self._name)}', " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Study(SQLModel):
|
class Study(SQLModel):
|
||||||
_version = "0.2.4"
|
_version = "0.2.5"
|
||||||
|
|
||||||
_sub_classes = [
|
_sub_classes = [
|
||||||
Scenario,
|
Scenario,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue