|
|
|
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'), nullable=False),
|
|
|
|
db.Column('player_id', db.Integer, db.ForeignKey('player.id'), nullable=False),
|
|
|
|
db.PrimaryKeyConstraint('game_id', 'player_id'),
|
|
|
|
db.Column('role', db.String(16))
|
|
|
|
)
|
|
|
|
|
|
|
|
player_found_objective = db.Table('player_found_objective',
|
|
|
|
db.Column('game_id', db.Integer, db.ForeignKey('game.id'), nullable=False),
|
|
|
|
db.Column('player_id', db.Integer, db.ForeignKey('player.id'), nullable=False),
|
|
|
|
db.PrimaryKeyConstraint('game_id', 'player_id'),
|
|
|
|
db.Column('timestamp', db.DateTime, server_default=func.now(), nullable=False)
|
|
|
|
)
|
|
|
|
|
|
|
|
player_caught_player = db.Table('player_caught_player',
|
|
|
|
db.Column('catching_player_id', db.Integer, db.ForeignKey('player.id')),
|
|
|
|
db.Column('caught_player_id', db.Integer, db.ForeignKey('player.id')),
|
|
|
|
db.Column('photo_reference', db.String(128), unique=True, nullable=False),
|
|
|
|
db.Column('timestamp', db.DateTime, server_default=func.now(), nullable=False)
|
|
|
|
)
|
|
|
|
|
|
|
|
notification_player = db.Table('notification_player',
|
|
|
|
db.Column('notification_id', db.Integer, db.ForeignKey('notification.id')),
|
|
|
|
db.Column('player_id', db.Integer, db.ForeignKey('player.id')),
|
|
|
|
db.PrimaryKeyConstraint('notification_id', 'player_id'),
|
|
|
|
db.Column('been_shown', db.Boolean, server_default='True', nullable=False)
|
|
|
|
)
|
|
|
|
|
|
|
|
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, server_default='1')
|
|
|
|
start_time = db.Column(db.DateTime)
|
|
|
|
end_time = db.Column(db.DateTime)
|
|
|
|
players = db.relationship(
|
|
|
|
'Player',
|
|
|
|
secondary=game_player,
|
|
|
|
back_populates='games')
|
|
|
|
objectives = db.relationship(
|
|
|
|
'Objective',
|
|
|
|
lazy='select',
|
|
|
|
backref=db.backref('game', lazy='joined'))
|
|
|
|
notifications = db.relationship(
|
|
|
|
'Notification',
|
|
|
|
lazy='select',
|
|
|
|
backref=db.backref('game', lazy='joined'))
|
|
|
|
|
|
|
|
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 = db.relationship(
|
|
|
|
'Game',
|
|
|
|
secondary=game_player,
|
|
|
|
back_populates='players')
|
|
|
|
objectives_found = db.relationship(
|
|
|
|
'Objective',
|
|
|
|
secondary=player_found_objective,
|
|
|
|
back_populates='players')
|
|
|
|
caught_players = db.relationship(
|
|
|
|
'Player',
|
|
|
|
secondary=player_caught_player,
|
|
|
|
primaryjoin=(player_caught_player.c.catching_player_id == id),
|
|
|
|
secondaryjoin=(player_caught_player.c.caught_player_id == id),
|
|
|
|
backref=db.backref('caught_by', lazy='dynamic'), lazy='dynamic')
|
|
|
|
locations = db.relationship(
|
|
|
|
'Location',
|
|
|
|
lazy='select',
|
|
|
|
backref=db.backref('player', lazy='joined'))
|
|
|
|
notifications = db.relationship(
|
|
|
|
'Notification',
|
|
|
|
secondary=notification_player,
|
|
|
|
back_populates='recipients')
|
|
|
|
|
|
|
|
class Objective(db.Model):
|
|
|
|
__tablename = 'objective'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.String(64), nullable=False)
|
|
|
|
game_id = db.Column(db.Integer, db.ForeignKey('game.id'), nullable=False)
|
|
|
|
hash = db.Column(db.String(128), unique=True, nullable=False)
|
|
|
|
longitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None)) # maybe check asdecimal and decimal_return_scale later?
|
|
|
|
latitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None))
|
|
|
|
players = db.relationship(
|
|
|
|
'Player',
|
|
|
|
secondary=player_found_objective,
|
|
|
|
back_populates='objectives_found')
|
|
|
|
|
|
|
|
class Location(db.Model):
|
|
|
|
__tablename = 'location'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
player_id = db.Column(db.Integer, db.ForeignKey('player.id'), nullable=False)
|
|
|
|
longitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None),nullable=False) # maybe check asdecimal and decimal_return_scale later?
|
|
|
|
latitude = db.Column(db.Numeric(precision=15, scale=10, asdecimal=False, decimal_return_scale=None),nullable=False)
|
|
|
|
timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False)
|
|
|
|
|
|
|
|
class Notification(db.Model):
|
|
|
|
__tablename = 'notification'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
game_id = db.Column(db.Integer, db.ForeignKey('game.id'), nullable=False)
|
|
|
|
message = db.Column(db.Text, nullable=False)
|
|
|
|
type = db.Column(db.String(64), nullable=False, default='General')
|
|
|
|
timestamp = db.Column(db.DateTime, server_default=func.now(), nullable=False)
|
|
|
|
recipients = db.relationship(
|
|
|
|
'Player',
|
|
|
|
secondary=notification_player,
|
|
|
|
back_populates='notifications')
|
|
|
|
|
|
|
|
#start_time = db.Column(db.DateTime, server_default=func.now())
|