DB: Some fixes for db update to 0.1.0.

scenarios
Pierre-Antoine Rouby 2024-08-07 10:45:31 +02:00
parent 2290e2eb6d
commit 74c61262b7
7 changed files with 33 additions and 15 deletions

View File

@ -91,8 +91,8 @@ class PointXYZ(Point, SQLSubModel):
execute(
f"INSERT INTO {table}_tmp " +
"(pamhyr_id, name, x, y, z, profile, sl, scenario) " +
"SELECT pamhyr_id, name, x, y, z, profile, sl, scenario " +
"(pamhyr_id, ind, name, x, y, z, profile, sl, scenario) " +
"SELECT pamhyr_id, ind, name, x, y, z, profile, sl, scenario " +
f"FROM {table}"
)
@ -133,6 +133,9 @@ class PointXYZ(Point, SQLSubModel):
pid = next(it)
sl_id = next(it)
if sl_id == -1:
continue
execute(
f"UPDATE {table} " +
f"SET sl = {sl[sl_id]} " +

View File

@ -92,6 +92,9 @@ class ProfileXYZ(Profile, SQLSubModel):
)
""")
if ext == "_tmp":
return True
return cls._create_submodel(execute)
@classmethod
@ -160,6 +163,9 @@ class ProfileXYZ(Profile, SQLSubModel):
pid = next(it)
sl_id = next(it)
if sl_id == -1:
continue
execute(
f"UPDATE {table} " +
f"SET sl = {sl[sl_id]} " +

View File

@ -64,6 +64,9 @@ class BasicHS(SQLSubModel):
)
""")
if ext == "_tmp":
return True
return cls._create_submodel(execute)
@classmethod

View File

@ -72,6 +72,9 @@ class HydraulicStructure(SQLSubModel):
)
""")
if ext == "_tmp":
return True
return cls._create_submodel(execute)
@classmethod
@ -83,7 +86,7 @@ class HydraulicStructure(SQLSubModel):
if rl < 6:
cls._db_create(execute)
if rl < 11:
if 6 < rl < 11:
for v in ["input", "output"]:
execute(
f"""

View File

@ -309,13 +309,13 @@ class RiverReach(Edge, SQLSubModel):
class River(Graph, SQLSubModel):
_sub_classes = [
StricklersList,
SedimentLayerList,
RiverNode,
RiverReach,
BoundaryConditionList,
LateralContributionList,
InitialConditionsDict,
SolverParametersList,
SedimentLayerList,
ReservoirList,
HydraulicStructureList,
AddFileList,

View File

@ -103,11 +103,11 @@ class Scenario(SQLSubModel):
"ADD COLUMN scenario INTEGER NOT NULL DEFAULT 0"
)
execute(
f"ALTER TABLE {table} " +
"ADD CONSTRAINT fk_scenario FOREIGN KEY (scenario) " +
"REFERENCES scenario(id)"
)
# execute(
# f"ALTER TABLE {table} " +
# "ADD CONSTRAINT fk_scenario FOREIGN KEY (scenario) " +
# "REFERENCES scenario(id)"
# )
@classmethod
def _db_load(cls, execute, data=None):

View File

@ -125,8 +125,8 @@ class Layer(SQLSubModel):
if major == minor == "0":
if int(release) < 2:
cls._db_create(execute)
cls._db_update_to_0_1_0(execute, data)
else:
cls._db_update_to_0_1_0(execute, data)
return cls._update_submodel(execute, version, data)
@ -142,9 +142,9 @@ class Layer(SQLSubModel):
execute(
f"INSERT INTO {table}_tmp " +
"(pamhyr_id, name, type, height, " +
"(pamhyr_id, ind, name, type, height, " +
"d50, sigma, critical_constraint, sl, scenario) " +
"SELECT pamhyr_id, name, type, height, " +
"SELECT pamhyr_id, ind, name, type, height, " +
"d50, sigma, critical_constraint, sl, scenario " +
f"FROM {table}"
)
@ -296,6 +296,9 @@ class SedimentLayer(SQLSubModel):
)
""")
if ext == "_tmp":
return True
return cls._create_submodel(execute)
@classmethod
@ -304,8 +307,8 @@ class SedimentLayer(SQLSubModel):
if major == minor == "0":
if int(release) < 2:
cls._db_create(execute)
cls._db_update_to_0_1_0(execute, data)
else:
cls._db_update_to_0_1_0(execute, data)
return cls._update_submodel(execute, version, data)