mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Use IN and BETWEEN in CHECK
This commit is contained in:
parent
f18e06a39b
commit
ce913f92eb
1 changed files with 10 additions and 25 deletions
|
@ -58,8 +58,7 @@ class PartStudent(db.Model):
|
|||
id = db.Column(db.Integer, primary_key=True)
|
||||
final_part_mark = db.Column(
|
||||
db.Integer,
|
||||
db.CheckConstraint(f"final_part_mark >= {MIN_MARK}"),
|
||||
db.CheckConstraint(f"final_part_mark <= {MAX_MARK}"),
|
||||
db.CheckConstraint(f"final_part_mark BETWEEN {MIN_MARK} AND {MAX_MARK}"),
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
|
@ -274,22 +273,19 @@ class SemesterExperiment(db.Model):
|
|||
id = db.Column(db.Integer, primary_key=True)
|
||||
oral_weighting = db.Column(
|
||||
db.Float,
|
||||
db.CheckConstraint("oral_weighting >= 0"),
|
||||
db.CheckConstraint("oral_weighting <= 1"),
|
||||
db.CheckConstraint("oral_weighting BETWEEN 0 AND 1"),
|
||||
default=0.5,
|
||||
nullable=False,
|
||||
)
|
||||
protocol_weighting = db.Column(
|
||||
db.Float,
|
||||
db.CheckConstraint("protocol_weighting >= 0"),
|
||||
db.CheckConstraint("protocol_weighting <= 1"),
|
||||
db.CheckConstraint("protocol_weighting BETWEEN 0 AND 1"),
|
||||
default=0.5,
|
||||
nullable=False,
|
||||
)
|
||||
final_weighting = db.Column(
|
||||
db.Float,
|
||||
db.CheckConstraint("final_weighting >= 0"),
|
||||
db.CheckConstraint("final_weighting <= 1"),
|
||||
db.CheckConstraint("final_weighting BETWEEN 0 AND 1"),
|
||||
default=1.0,
|
||||
nullable=False,
|
||||
)
|
||||
|
@ -436,10 +432,8 @@ class Part(db.Model):
|
|||
|
||||
class Semester(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
label = db.Column(db.String(10), nullable=False)
|
||||
year = db.Column(
|
||||
db.Integer, db.CheckConstraint(f"year >= {MIN_YEAR}"), db.CheckConstraint(f"year <= {MAX_YEAR}"), nullable=False
|
||||
)
|
||||
label = db.Column(db.String(10), db.CheckConstraint("label IN ('WS', 'SS')"), nullable=False)
|
||||
year = db.Column(db.Integer, db.CheckConstraint(f"year BETWEEN {MIN_YEAR} AND {MAX_YEAR}"), nullable=False)
|
||||
|
||||
parts = db.relationship("Part", backref="semester", lazy=True)
|
||||
semester_experiments = db.relationship("SemesterExperiment", backref="semester", lazy=True)
|
||||
|
@ -448,14 +442,8 @@ class Semester(db.Model):
|
|||
|
||||
__table_args__ = (db.UniqueConstraint(label, year),)
|
||||
|
||||
def customInit(label, year):
|
||||
if label not in ("WS", "SS"):
|
||||
raise DataBaseException("The semester label has to be WS or SS!")
|
||||
|
||||
return Semester(label=label, year=year)
|
||||
|
||||
def customInitFromOldSemester(label, year, oldSemester, transferParts, transferAssistants):
|
||||
semester = Semester.customInit(label=label, year=year)
|
||||
semester = Semester(label=label, year=year)
|
||||
|
||||
if transferParts:
|
||||
semester.transferPartsFrom(oldSemester)
|
||||
|
@ -513,21 +501,18 @@ class ExperimentMark(db.Model):
|
|||
|
||||
oral_mark = db.Column(
|
||||
db.Integer,
|
||||
db.CheckConstraint(f"oral_mark >= {MIN_MARK}"),
|
||||
db.CheckConstraint(f"oral_mark <= {MAX_MARK}"),
|
||||
db.CheckConstraint(f"oral_mark BETWEEN {MIN_MARK} AND {MAX_MARK}"),
|
||||
nullable=True,
|
||||
)
|
||||
protocol_mark = db.Column(
|
||||
db.Integer,
|
||||
db.CheckConstraint(f"oral_mark >= {MIN_MARK}"),
|
||||
db.CheckConstraint(f"oral_mark <= {MAX_MARK}"),
|
||||
db.CheckConstraint(f"oral_mark BETWEEN {MIN_MARK} AND {MAX_MARK}"),
|
||||
nullable=True,
|
||||
)
|
||||
|
||||
final_experiment_mark = db.Column(
|
||||
db.Integer,
|
||||
db.CheckConstraint(f"oral_mark >= {MIN_MARK}"),
|
||||
db.CheckConstraint(f"oral_mark <= {MAX_MARK}"),
|
||||
db.CheckConstraint(f"oral_mark BETWEEN {MIN_MARK} AND {MAX_MARK}"),
|
||||
onupdate=final_experiment_mark_update,
|
||||
nullable=True,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue