Skip to content

Commit

Permalink
CLI runs custom runserver_migrate command
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Jan 4, 2025
1 parent c0ffaff commit e268a3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 1 addition & 7 deletions app/app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def main():
"""CLI entry point for running the development server."""
try:
from django.core.management import execute_from_command_line
from django.db import connections
from django.apps import apps
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Make sure it's installed and "
Expand All @@ -29,11 +27,7 @@ def main():
sys.path.insert(0, str(BASE_DIR))
if len(sys.argv) > 2:
os.environ["LAB_CONTENT_ENTRYPOINT"] = sys.argv[2]
execute_from_command_line(["manage.py", "migrate"])
for conn in connections.all():
conn.close()
apps.clear_cache()
execute_from_command_line(["manage.py", "runserver"])
execute_from_command_line(["manage.py", "runserver_migrate"])
else:
print(f"Unknown command: {sys.argv[1]}")

Expand Down
Empty file.
12 changes: 12 additions & 0 deletions app/app/management/commands/runserver_migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.core.management.commands.runserver import (
Command as RunserverCommand,
)
from django.core.management import call_command


class Command(RunserverCommand):
def handle(self, *args, **options):
self.stdout.write("Applying migrations...")
call_command("migrate")
self.stdout.write("Migrations applied successfully.")
super().handle(*args, **options)

0 comments on commit e268a3f

Please sign in to comment.