Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enforce --name/-n argument in makemigrations management command #5107

Merged
merged 7 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/core/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.core.management import CommandError
from django.core.management.commands.makemigrations import (
Command as MakeMigrationsCommand,
)


class Command(MakeMigrationsCommand):
"""
Customise the makemigrations command to enforce use of `--name/-n` argument.
"""

def handle(self, *app_labels, **options):
if not options.get("name") and not (
options.get("check_changes") or options.get("dry_run")
):
raise CommandError("--name/-n is a required argument")

return super().handle(*app_labels, **options)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from django.core.management import CommandError, call_command


def test_makemigrations_without_name_raises_error():
with pytest.raises(CommandError, match="--name/-n is a required argument"):
call_command('makemigrations')


@pytest.mark.django_db(databases=["default", "analytics"])
def test_makemigrations_with_check_changes_runs_without_error():
call_command('makemigrations', check_changes=True)


@pytest.mark.django_db(databases=["default", "analytics"])
def test_makemigrations_with_dry_run_runs_without_error():
call_command('makemigrations', dry_run=True)


@pytest.mark.django_db(databases=["default", "analytics"])
def test_makemigrations_with_name_runs_without_error():
call_command('makemigrations', name="some_useful_name")
Loading