Add check_migrations command

this way, at least in the Docker setup, you'll get a meaningful error when you
try to start up a half-baked server
This commit is contained in:
Klaas van Schelven
2024-09-09 15:31:14 +02:00
parent 67cfbb58d7
commit 2e70197825
2 changed files with 25 additions and 1 deletions

View File

@@ -32,4 +32,4 @@ RUN ["bugsink-manage", "migrate", "snappea", "--database=snappea"]
EXPOSE 8000
CMD [ "monofy", "bugsink-manage", "check", "--deploy", "--fail-level", "WARNING", "&&", "gunicorn", "--bind=0.0.0.0:8000", "--workers=10", "--access-logfile", "-", "bugsink.wsgi", "|||", "bugsink-runsnappea"]
CMD [ "monofy", "bugsink-manage", "check_migrations", "&&", "bugsink-manage", "check", "--deploy", "--fail-level", "WARNING", "&&", "gunicorn", "--bind=0.0.0.0:8000", "--workers=10", "--access-logfile", "-", "bugsink.wsgi", "|||", "bugsink-runsnappea"]

View File

@@ -0,0 +1,24 @@
from django.core.management import call_command
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = "Calls `migrate` with `check_unapplied=True` to check for unapplied migrations (2 DBs, adds error message)"
def handle(self, *args, **options):
try:
call_command('migrate', check_unapplied=True)
except SystemExit:
self.stdout.write(self.style.ERROR(
"You have unapplied migrations. Make sure to call `bugsink-manage migrate` before running the server."
))
raise
try:
call_command('migrate', "snappea", check_unapplied=True, database="snappea")
except SystemExit:
self.stdout.write(self.style.ERROR(
"You have unapplied migrations. Make sure to call `bugsink-manage migrate snappea --database=snappea` "
"before running the server."
))
raise