2022-09-24 02:40:18 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright 2022 - c0de <c0de@c0de.dev>
|
|
|
|
# Licensed under the MIT License (https://opensource.org/licenses/MIT)
|
|
|
|
|
|
|
|
import os
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
from peewee import *
|
|
|
|
|
2022-10-25 00:55:50 +00:00
|
|
|
# User can provide path to database, or it will be put next to main.py
|
2022-09-24 02:40:18 +00:00
|
|
|
DATABASE = os.environ.get('database_path', os.getcwd() + '/ghostball.db')
|
|
|
|
database = SqliteDatabase(DATABASE)
|
|
|
|
|
|
|
|
class BaseModel(Model):
|
|
|
|
"""All of our models will inherit this class
|
|
|
|
and use the same database connection"""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
database = database
|
|
|
|
|
|
|
|
class GameModel(BaseModel):
|
|
|
|
|
|
|
|
game_id = UUIDField(primary_key=True)
|
2022-10-24 23:43:38 +00:00
|
|
|
server_id = IntegerField()
|
2022-09-24 02:40:18 +00:00
|
|
|
|
|
|
|
pitch_value = IntegerField(null=True)
|
|
|
|
date_created = DateTimeField(default=datetime.datetime.now)
|
2022-10-25 00:12:48 +00:00
|
|
|
date_ended = DateTimeField(null=True)
|
2022-09-24 02:40:18 +00:00
|
|
|
|
|
|
|
class GuessModel(BaseModel):
|
|
|
|
|
|
|
|
player_id = IntegerField(primary_key=True)
|
2022-10-04 01:08:42 +00:00
|
|
|
game_id = ForeignKeyField(GameModel, backref="guesses")
|
2022-09-24 02:40:18 +00:00
|
|
|
|
|
|
|
player_name = CharField()
|
|
|
|
guess = IntegerField()
|
|
|
|
difference = IntegerField(null=True)
|
2022-10-25 00:12:48 +00:00
|
|
|
date_guessed = DateTimeField(null=True)
|
2022-09-24 02:40:18 +00:00
|
|
|
|
|
|
|
# TODO: Add unique constraint for player_id and game_id
|
|
|
|
# ie: one guess per player allowed per game
|
|
|
|
|
|
|
|
|
|
|
|
def create_models():
|
|
|
|
with database:
|
2022-10-24 23:49:26 +00:00
|
|
|
database.create_tables([GameModel, GuessModel])
|