Compare commits
2 Commits
5d551b3dd8
...
07cf930328
Author | SHA1 | Date | |
---|---|---|---|
07cf930328 | |||
91d96d1bcb |
@ -13,4 +13,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . /app/
|
||||
|
||||
CMD ["python", "bot.py"]
|
||||
CMD ["sh", "-c", "aerich upgrade && python bot.py"]
|
14
bot.py
14
bot.py
@ -21,6 +21,15 @@ log = logging.getLogger(__name__)
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
DATA_DIR = getenv("SPIFFO__DATA_FOLDER_PATH")
|
||||
TORTOISE_ORM = {
|
||||
"connections": { "default": f"sqlite://{str(DATA_DIR)}/db.sqlite" },
|
||||
"apps": {
|
||||
"models": {
|
||||
"models": ["utils.models", "aerich.models"],
|
||||
"default_connection": "default"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DiscordBot(commands.Bot):
|
||||
@ -117,10 +126,7 @@ async def main():
|
||||
bot_token = get_bot_token()
|
||||
|
||||
# Open database connection
|
||||
await Tortoise.init(
|
||||
db_url= f"sqlite://{str(DATA_DIR)}/db.sqlite",
|
||||
modules={"models": ["utils.models"]}
|
||||
)
|
||||
await Tortoise.init(config=TORTOISE_ORM)
|
||||
await Tortoise.generate_schemas()
|
||||
|
||||
async with DiscordBot(debug_mode) as bot:
|
||||
|
42
migrations/models/0_20241211195324_init.py
Normal file
42
migrations/models/0_20241211195324_init.py
Normal file
@ -0,0 +1,42 @@
|
||||
from tortoise import BaseDBAsyncClient
|
||||
|
||||
|
||||
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
CREATE TABLE IF NOT EXISTS "players" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"username" VARCHAR(20) NOT NULL UNIQUE,
|
||||
"last_connection" TIMESTAMP,
|
||||
"last_disconnection" TIMESTAMP,
|
||||
"play_time_seconds" INT NOT NULL DEFAULT 0,
|
||||
"is_dead" INT NOT NULL DEFAULT 0
|
||||
) /* */;
|
||||
CREATE TABLE IF NOT EXISTS "player_deaths" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"coordinate_x" INT NOT NULL,
|
||||
"coordinate_y" INT NOT NULL,
|
||||
"coordinate_z" INT NOT NULL,
|
||||
"cause" VARCHAR(32) NOT NULL,
|
||||
"timestamp" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"player_id" INT NOT NULL REFERENCES "players" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "steam_profile_summary" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"steam_id" VARCHAR(20) NOT NULL UNIQUE,
|
||||
"profile_name" VARCHAR(32) NOT NULL,
|
||||
"url" VARCHAR(128) NOT NULL,
|
||||
"avatar_url" VARCHAR(128) NOT NULL,
|
||||
"last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"player_id" INT NOT NULL REFERENCES "players" ("id") ON DELETE CASCADE
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "aerich" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"version" VARCHAR(255) NOT NULL,
|
||||
"app" VARCHAR(100) NOT NULL,
|
||||
"content" JSON NOT NULL
|
||||
);"""
|
||||
|
||||
|
||||
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||
return """
|
||||
"""
|
4
pyproject.toml
Normal file
4
pyproject.toml
Normal file
@ -0,0 +1,4 @@
|
||||
[tool.aerich]
|
||||
tortoise_orm = "bot.TORTOISE_ORM"
|
||||
location = "./migrations"
|
||||
src_folder = "./."
|
@ -1,3 +1,4 @@
|
||||
aerich==0.8.0
|
||||
aiofiles==24.1.0
|
||||
aiohappyeyeballs==2.4.4
|
||||
aiohttp==3.11.9
|
||||
@ -5,9 +6,11 @@ aiosignal==1.3.1
|
||||
aiosqlite==0.20.0
|
||||
annotated-types==0.7.0
|
||||
anyio==4.7.0
|
||||
asyncclick==8.1.7.2
|
||||
attrs==24.2.0
|
||||
bump2version==1.0.1
|
||||
certifi==2024.8.30
|
||||
dictdiffer==0.9.0
|
||||
discord.py==2.4.0
|
||||
frozenlist==1.5.0
|
||||
h11==0.14.0
|
||||
@ -24,6 +27,7 @@ python-dotenv==1.0.1
|
||||
pytz==2024.2
|
||||
rcon==2.4.9
|
||||
sniffio==1.3.1
|
||||
tomlkit==0.13.2
|
||||
tortoise-orm==0.22.1
|
||||
typing_extensions==4.12.2
|
||||
yarl==1.18.3
|
||||
|
Reference in New Issue
Block a user