mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Add constants for constraints
This commit is contained in:
parent
ef4c46d535
commit
8ab38f11e2
1 changed files with 19 additions and 6 deletions
|
@ -18,6 +18,13 @@ from advlabdb.exceptions import DataBaseException
|
|||
|
||||
MIN_MARK = 0
|
||||
MAX_MARK = 15
|
||||
MIN_YEAR = 22
|
||||
MAX_YEAR = 99
|
||||
MIN_STUDENT_NUMBER = 0
|
||||
MIN_EXPERIMENT_NUMBER = 1
|
||||
MIN_GROUP_NUMBER = 1
|
||||
MIN_DURATION_IN_DAYS = 1
|
||||
MIN_PART_NUMBER = 1
|
||||
|
||||
|
||||
def roundHalfUpToInt(number):
|
||||
|
@ -26,7 +33,9 @@ def roundHalfUpToInt(number):
|
|||
|
||||
class Student(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
student_number = db.Column(db.Integer, db.CheckConstraint("student_number > -1"), nullable=False, unique=True)
|
||||
student_number = db.Column(
|
||||
db.Integer, db.CheckConstraint(f"student_number >= {MIN_STUDENT_NUMBER}"), nullable=False, unique=True
|
||||
)
|
||||
first_name = db.Column(db.String(100), nullable=False)
|
||||
last_name = db.Column(db.String(100), nullable=False)
|
||||
uni_email = db.Column(db.String(200), nullable=False, unique=True)
|
||||
|
@ -137,7 +146,7 @@ class PartStudent(db.Model):
|
|||
|
||||
class Group(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
number = db.Column(db.Integer, db.CheckConstraint("number > 0"), nullable=False)
|
||||
number = db.Column(db.Integer, db.CheckConstraint(f"number > {MIN_GROUP_NUMBER}"), nullable=False)
|
||||
|
||||
semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=False)
|
||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=False)
|
||||
|
@ -227,14 +236,16 @@ class GroupExperiment(db.Model):
|
|||
|
||||
class Experiment(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
number = db.Column(db.Integer, db.CheckConstraint("number > 0"), nullable=False)
|
||||
number = db.Column(db.Integer, db.CheckConstraint(f"number > {MIN_EXPERIMENT_NUMBER}"), nullable=False)
|
||||
title = db.Column(db.String(200), nullable=False)
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
wiki_link = db.Column(db.String(300), nullable=True)
|
||||
building = db.Column(db.String(100), nullable=False)
|
||||
room = db.Column(db.String(100), nullable=False)
|
||||
responsibility = db.Column(db.String(200), nullable=True)
|
||||
duration_in_days = db.Column(db.Integer, db.CheckConstraint("duration_in_days > 0"), nullable=False)
|
||||
duration_in_days = db.Column(
|
||||
db.Integer, db.CheckConstraint(f"duration_in_days >= {MIN_DURATION_IN_DAYS}"), nullable=False
|
||||
)
|
||||
active = db.Column(db.Boolean, default=True, nullable=False)
|
||||
|
||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=False)
|
||||
|
@ -407,7 +418,7 @@ class Appointment(db.Model):
|
|||
|
||||
class Part(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
number = db.Column(db.Integer, db.CheckConstraint("number > 0"), nullable=False)
|
||||
number = db.Column(db.Integer, db.CheckConstraint(f"number > {MIN_PART_NUMBER}"), nullable=False)
|
||||
|
||||
program_id = db.Column(db.Integer, db.ForeignKey("program.id"), nullable=False)
|
||||
semester_id = db.Column(db.Integer, db.ForeignKey("semester.id"), nullable=False)
|
||||
|
@ -426,7 +437,9 @@ 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("year > 0"), db.CheckConstraint("year < 100"), nullable=False)
|
||||
year = db.Column(
|
||||
db.Integer, db.CheckConstraint(f"year >= {MIN_YEAR}"), db.CheckConstraint(f"year <= {MAX_YEAR}"), nullable=False
|
||||
)
|
||||
|
||||
parts = db.relationship("Part", backref="semester", lazy=True)
|
||||
semester_experiments = db.relationship("SemesterExperiment", backref="semester", lazy=True)
|
||||
|
|
Loading…
Reference in a new issue