💄 — Use an argos server command to do alembic migrations

This commit is contained in:
Luc Didry 2024-03-14 14:57:17 +01:00
parent f976905433
commit 8875c704ee
No known key found for this signature in database
GPG key ID: EA868E12D0257E3C
2 changed files with 18 additions and 1 deletions

View file

@ -4,6 +4,8 @@ from functools import wraps
import click import click
import uvicorn import uvicorn
from alembic import command
from alembic.config import Config
from argos import logging from argos import logging
from argos.agent import ArgosAgent from argos.agent import ArgosAgent
@ -152,5 +154,20 @@ async def reload_config():
click.echo(f"{changed['vanished']} tasks deleted") 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__": if __name__ == "__main__":
cli() cli()

View file

@ -8,7 +8,7 @@ PartOf=postgresql.service
[Service] [Service]
User=www-data User=www-data
WorkingDirectory=/var/www/argos/ 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 ExecStartPre=/var/www/argos/venv/bin/argos server reload-config
ExecStart=/var/www/argos/venv/bin/argos server start ExecStart=/var/www/argos/venv/bin/argos server start
ExecReload=/var/www/argos/venv/bin/argos server reload ExecReload=/var/www/argos/venv/bin/argos server reload