Commit 4bfb1691 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch 'disable-makemigrations' into 'master'

Fix #685: Disable makemigrations in production and misleading message when running migrate

See merge request funkwhale/funkwhale!568
parents 264aa20d 78546232
import os
from import CommandError
from import Command as BaseCommand
class Command(BaseCommand):
def handle(self, *apps_label, **options):
Running makemigrations in production can have desastrous consequences.
We ensure the command is disabled, unless a specific env var is provided.
force = os.environ.get("FORCE") == "1"
if not force:
raise CommandError(
"Running makemigrations on your Funkwhale instance can have desastrous"
" consequences. This command is disabled, and should only be run in "
"development environments."
return super().handle(*apps_label, **options)
from import Command as BaseCommand
def patch_write(buffer):
Django is trying to help us when running migrate, by checking we don't have
model changes not included in migrations. Unfortunately, running makemigrations
on production instances create unwanted migrations and corrupt the database.
So we disabled the makemigrations command, and we're patching the
write method to ensure misleading messages are never shown to the user,
does not leave an easy way to disable them.
unpatched = buffer.write
def p(message, *args, **kwargs):
if "' makemigrations'" in message or "not yet reflected" in message:
return unpatched(message, *args, **kwargs)
setattr(buffer, "write", p)
class Command(BaseCommand):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Disable makemigrations in production and misleading message when running migrate (#685)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment