class MatchResultModel(Model): __tablename__ = "match_result" id = fields.Integer(primary_key=True) match = fields.ForeignKey(MatchModel) side = fields.ForeignKey(SideModel) score = fields.Integer(default=0)
class GameModel(Model): __tablename__ = "game" id = fields.Integer(primary_key=True) name = fields.String(max_length=64, unique=True) side_size_min = fields.Integer(default=1) side_size_max = fields.Integer(default=2) side_count_min = fields.Integer(default=2) side_count_max = fields.Integer(default=2)
class SideModel(Model): __tablename__ = "side" id = fields.Integer(primary_key=True) name = fields.String(max_length=64) member_key = fields.String(unique=True, max_length=64) stats_key = fields.ForeignKey(StatsKeyModel)
class VisitorModel(Model): __tablename__ = "visitor" id = fields.Integer(primary_key=True) name = fields.String(index=True, max_length=64) ip_addr = fields.String(index=True, max_length=15) location = fields.String(allow_null=True, max_length=64)
class VisitModel(Model): __tablename__ = "visit" id = fields.Integer(primary_key=True) visited_on = fields.DateTime(default=datetime.datetime.utcnow) message = fields.String(max_length=64) visitor = fields.ForeignKey(VisitorModel)
class MatchModel(Model): __tablename__ = "match" id = fields.Integer(primary_key=True) game = fields.ForeignKey(GameModel) created_at = fields.DateTime(default=datetime.datetime.utcnow) updated_at = fields.DateTime(default=datetime.datetime.utcnow)
class StatsModel(Model): __tablename__ = "stats" id = fields.Integer(primary_key=True) stats_key = fields.ForeignKey(StatsKeyModel) game = fields.ForeignKey(GameModel) score_for = fields.Integer(default=0) score_against = fields.Integer(default=0) matches_played = fields.Integer(default=0) matches_won = fields.Integer(default=0) matches_lost = fields.Integer(default=0)
class StatsKeyModel(Model): __tablename__ = "stats_key" id = fields.Integer(primary_key=True)
class PlayerModel(Model): __tablename__ = "player" id = fields.Integer(primary_key=True) name = fields.String(max_length=64, unique=True) stats_key = fields.ForeignKey(StatsKeyModel)
class SidePlayerModel(Model): __tablename__ = "side_player" id = fields.Integer(primary_key=True) side = fields.ForeignKey(SideModel) player = fields.ForeignKey(PlayerModel)