diff --git a/database.py b/database.py index 20872c5555ea2b3f26c5a1010db3faba573fd85c..c612137bc448d9859fd466f9efbf12f888bb119e 100644 --- a/database.py +++ b/database.py @@ -36,19 +36,32 @@ def get_schedules_for_user(user_id): ) for row in rows] def insert_schedule(schedule): - connection.execute(''' - INSERT INTO schedule - (time, day_week, location, meal, user_id, created_at) - VALUES - (?, ?, ?, ?, ?, ?) + cur = connection.execute(''' + SELECT created_at + FROM schedule + WHERE time = ? and day_week = ? and location = ? and meal = ? and user_id = ? ''', ( schedule.time, schedule.day_week, schedule.location.name, schedule.meal.name, - schedule.user_id, - schedule.created_at + schedule.user_id )) + row = cur.fetchone() + if not row: + connection.execute(''' + INSERT INTO schedule + (time, day_week, location, meal, user_id, created_at) + VALUES + (?, ?, ?, ?, ?, ?) + ''', ( + schedule.time, + schedule.day_week, + schedule.location.name, + schedule.meal.name, + schedule.user_id, + schedule.created_at + )) def get_schedules_matching_time(time): cur = connection.execute('''