Skip to content

Commit

Permalink
Merge pull request #81 from computas/SP24-485-Fix-multiplayer-backend…
Browse files Browse the repository at this point in the history
…-error-messages-upon-deleting-old-data

Fix multiplayer deletion errors
  • Loading branch information
ComputasAlex authored Jul 11, 2024
2 parents 701e0a5 + e20703a commit dd7e0a9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/webapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class Scores(db.Model):
"""

score_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
player_id = db.Column(db.NVARCHAR(32), db.ForeignKey("players.player_id"))
player_id = db.Column(db.NVARCHAR(32), db.ForeignKey(
"players.player_id", ondelete='CASCADE'))
score = db.Column(db.Integer, nullable=False)
date = db.Column(db.Date)
difficulty_id = db.Column(
Expand All @@ -69,6 +70,7 @@ class Players(db.Model):
state = db.Column(db.String(32), nullable=False)

game = db.relationship("Games", back_populates="players")
scores = db.relationship("Scores", backref="Players", passive_deletes=True)


class MulitPlayer(db.Model):
Expand Down Expand Up @@ -382,14 +384,14 @@ def delete_session_from_game(game_id):

def delete_old_games():
"""
Delete records in games older than one hour.
Delete records in games older than one day.
"""
try:
games = (
db.session.query(Games)
.filter(
Games.date
< (datetime.datetime.today() - datetime.timedelta(hours=1))
< (datetime.datetime.today() - datetime.timedelta(days=1))
)
.all()
)
Expand Down

0 comments on commit dd7e0a9

Please sign in to comment.