From a0195780824fecf5c90efbca411eb4975b466a31 Mon Sep 17 00:00:00 2001 From: Burathar Date: Wed, 1 Jul 2020 15:16:53 +0200 Subject: [PATCH] implement game and player in models.py, document gamestate --- app/models.py | 32 ++++++++++++++++++++++++++++++++ documentation/gamestate.txt | 8 ++++++++ 2 files changed, 40 insertions(+) create mode 100644 documentation/gamestate.txt diff --git a/app/models.py b/app/models.py index 44fe957..efbcda5 100644 --- a/app/models.py +++ b/app/models.py @@ -1,3 +1,35 @@ from app import app, db +from sqlalchemy.sql import func +game_player = db.Table('game_player', + db.Column('game_id', db.Integer, db.ForeignKey('game.id')), + db.Column('player_id', db.Integer, db.ForeignKey('player.id')), + db.Column('role', db.String(16)) + ) +class Game(db.Model): + __tablename__ = 'game' + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(64), index=True, unique=True, nullable=False) + password_hash = db.Column(db.String(128), nullable=False) + state = db.Column(db.Integer, default='1') + start_time = db.Column(db.DateTime) + end_time = db.Column(db.DateTime) + players = relationship( + 'player', + secondary=game_player, + back_populates='games') + +class Player(db.Model): + __tablename = 'player' + id = db.Column(db.Integer, primary_key=True) + name = db.Column(db.String(64), unique=True, nullable=False) + auth_hash = db.Column(db.String(128), unique=True, nullable=False) + password_hash = db.Column(db.String(128)) + games = relationship( + 'game', + secondary=game_player, + back_populates='players') + + +#start_time = db.Column(db.DateTime, server_default=func.now()) diff --git a/documentation/gamestate.txt b/documentation/gamestate.txt new file mode 100644 index 0000000..906518a --- /dev/null +++ b/documentation/gamestate.txt @@ -0,0 +1,8 @@ +Gamestate + +This is an attribute of the Game class. It will be implemented as an enum containing the following values: +initiated = 1 +published = 2 +started = 3 +interrupted = 4 +finished = 5