From 8875c704ee1166c7be87e8dfab12c970312c4e98 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 14 Mar 2024 14:57:17 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20=E2=80=94=20Use=20an=20argos=20s?= =?UTF-8?q?erver=20command=20to=20do=20alembic=20migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- argos/commands.py | 17 +++++++++++++++++ conf/systemd-server.service | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/argos/commands.py b/argos/commands.py index e53a93d..b90057a 100644 --- a/argos/commands.py +++ b/argos/commands.py @@ -4,6 +4,8 @@ from functools import wraps import click import uvicorn +from alembic import command +from alembic.config import Config from argos import logging from argos.agent import ArgosAgent @@ -152,5 +154,20 @@ async def reload_config(): click.echo(f"{changed['vanished']} tasks deleted") +@server.command() +@coroutine +async def migrate(): + """Run database migrations + """ + # The imports are made here otherwise the agent will need server configuration files. + from argos.server.settings import get_app_settings + + settings = get_app_settings() + + alembic_cfg = Config("alembic.ini") + alembic_cfg.set_main_option("sqlalchemy.url", settings.database_url) + command.upgrade(alembic_cfg, "head") + + if __name__ == "__main__": cli() diff --git a/conf/systemd-server.service b/conf/systemd-server.service index 0c69536..f5116a9 100644 --- a/conf/systemd-server.service +++ b/conf/systemd-server.service @@ -8,7 +8,7 @@ PartOf=postgresql.service [Service] User=www-data WorkingDirectory=/var/www/argos/ -ExecStartPre=/var/www/argos/venv/bin/alembic upgrade head +ExecStartPre=/var/www/argos/venv/bin/argos server migrate ExecStartPre=/var/www/argos/venv/bin/argos server reload-config ExecStart=/var/www/argos/venv/bin/argos server start ExecReload=/var/www/argos/venv/bin/argos server reload