diff --git a/CHANGELOG.md b/CHANGELOG.md index 34896ac..6999fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Debug environment variable flag. - Command to build player data from existing log files. -- Database migration management with the aerich package. ### Changed diff --git a/Dockerfile b/Dockerfile index 9397202..f0e2f8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,4 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . /app/ -CMD ["sh", "-c", "aerich upgrade && python bot.py"] \ No newline at end of file +CMD ["python", "bot.py"] \ No newline at end of file diff --git a/bot.py b/bot.py index 60bb677..59a7f4e 100644 --- a/bot.py +++ b/bot.py @@ -25,7 +25,7 @@ TORTOISE_ORM = { "connections": { "default": f"sqlite://{str(DATA_DIR)}/db.sqlite" }, "apps": { "models": { - "models": ["utils.models", "aerich.models"], + "models": ["utils.models"], "default_connection": "default" } } diff --git a/migrations/models/0_20241211195324_init.py b/migrations/models/0_20241211214800_init.py similarity index 61% rename from migrations/models/0_20241211195324_init.py rename to migrations/models/0_20241211214800_init.py index 4ee23ba..d35ecb2 100644 --- a/migrations/models/0_20241211195324_init.py +++ b/migrations/models/0_20241211214800_init.py @@ -3,21 +3,30 @@ from tortoise import BaseDBAsyncClient async def upgrade(db: BaseDBAsyncClient) -> str: return """ - CREATE TABLE IF NOT EXISTS "players" ( + CREATE TABLE IF NOT EXISTS "ingame_coordinates" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "x" INT NOT NULL, + "y" INT NOT NULL, + "z" INT NOT NULL +); +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, + "coordinates_id" INT NOT NULL REFERENCES "ingame_coordinates" ("id") ON DELETE CASCADE, + "player_id" INT NOT NULL REFERENCES "players" ("id") ON DELETE CASCADE +); +CREATE TABLE IF NOT EXISTS "player_session" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "connected_at" TIMESTAMP NOT NULL, + "disconnected_at" TIMESTAMP NOT NULL, + "connected_coords_id" INT NOT NULL REFERENCES "ingame_coordinates" ("id") ON DELETE CASCADE, + "disconnected_coords_id" INT REFERENCES "ingame_coordinates" ("id") ON DELETE CASCADE, "player_id" INT NOT NULL REFERENCES "players" ("id") ON DELETE CASCADE ); CREATE TABLE IF NOT EXISTS "steam_profile_summary" ( diff --git a/requirements.txt b/requirements.txt index 805a5c5..a60c0be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -aerich==0.8.0 aiofiles==24.1.0 aiohappyeyeballs==2.4.4 aiohttp==3.11.9