1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Add appointment date check constraint

This commit is contained in:
Mo 2022-06-20 03:06:33 +02:00
parent 39a66727ee
commit 787504c7a1
3 changed files with 6 additions and 4 deletions

View file

@ -378,7 +378,9 @@ class Admin(db.Model):
class Appointment(db.Model):
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.Date, nullable=False) # To be specified with the python package "datetime"
date = db.Column(
db.Date, db.CheckConstraint(f"date BETWEEN '20{MIN_YEAR}-01-01' AND '20{MAX_YEAR}-01-01'"), nullable=False
) # To be specified with the python package "datetime"
special = db.Column(db.Boolean, default=False, nullable=False) # In the break or not
group_experiment_id = db.Column(db.Integer, db.ForeignKey("group_experiment.id"), nullable=False)

View file

@ -142,8 +142,8 @@ def main():
db.session.add(as1)
db.session.add(as2)
ap1 = Appointment(date=date(2021, 3, 21), special=True, group_experiment=gx1, assistant=as1)
ap2 = Appointment(date=date(2021, 3, 22), special=True, group_experiment=gx2, assistant=as2)
ap1 = Appointment(date=date(2022, 3, 21), special=True, group_experiment=gx1, assistant=as1)
ap2 = Appointment(date=date(2022, 3, 22), special=True, group_experiment=gx2, assistant=as2)
db.session.add(ap1)
db.session.add(ap2)

View file

@ -71,7 +71,7 @@ The type of the attributes can be seen in the drawio file link:DB.drawio[] which
* group_id
=== Appointment
* date -> 21.08.2021
* date -> 21.08.2022
* special -> 1 / 0
* group_experiment_id
* assistant_email