| 1 |
from typing import Any |
| 2 |
|
| 3 |
from django.core.checks import Tags, run_checks |
| 4 |
from django.core.management.base import BaseCommand, CommandParser |
| 5 |
from django.core.management.commands.migrate import Command as MigrateCommand |
| 6 |
from django.db.migrations.autodetector import MigrationAutodetector |
| 7 |
|
| 8 |
from . import WrappedSchemaOption |
| 9 |
from .runschema import Command as RunSchemaCommand |
| 10 |
|
| 11 |
|
| 12 |
class NonInteractiveRunSchemaCommand(RunSchemaCommand): |
| 13 |
allow_interactive = False |
| 14 |
|
| 15 |
|
| 16 |
class MigrateSchemaCommand(WrappedSchemaOption, BaseCommand): |
| 17 |
autodetector = MigrationAutodetector |
| 18 |
allow_interactive = False |
| 19 |
requires_system_checks: list[str] = [] |
| 20 |
|
| 21 |
def _run_checks(self, **kwargs: Any) -> list[Any]: # pragma: no cover |
| 22 |
issues = run_checks(tags=[Tags.database]) |
| 23 |
issues.extend(super()._run_checks(**kwargs)) |
| 24 |
return issues |
| 25 |
|
| 26 |
def add_arguments(self, parser: CommandParser) -> None: |
| 27 |
super().add_arguments(parser) |
| 28 |
MigrateCommand.add_arguments(self, parser) |
| 29 |
|
| 30 |
def handle(self, *args: Any, **options: Any) -> None: |
| 31 |
runschema = NonInteractiveRunSchemaCommand() |
| 32 |
options.pop("run_syncdb", False) |
| 33 |
if "skip_checks" not in options: |
| 34 |
options["skip_checks"] = True |
| 35 |
runschema.execute(command_name="django.core.migrate", *args, **options) |
| 36 |
|
| 37 |
|
| 38 |
Command = MigrateSchemaCommand |