diff --git a/Dockerfile b/Dockerfile index f0e2f8b..9397202 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,4 +13,4 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . /app/ -CMD ["python", "bot.py"] \ No newline at end of file +CMD ["sh", "-c", "aerich upgrade && python bot.py"] \ No newline at end of file diff --git a/bot.py b/bot.py index 3e2e9a0..60bb677 100644 --- a/bot.py +++ b/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: diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7f669ab --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[tool.aerich] +tortoise_orm = "bot.TORTOISE_ORM" +location = "./migrations" +src_folder = "./." diff --git a/requirements.txt b/requirements.txt index 8f37e38..805a5c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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