summaryrefslogtreecommitdiff
path: root/scripts/check_migrations.py
blob: 70d187e14433068b6b0e36390bf58911b9a32b38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
from pathlib import Path


def main():
    repo_root = Path(__file__).resolve().parent.parent
    sys.path[:0] = [str(repo_root / "tests"), str(repo_root)]

    from runtests import ALWAYS_INSTALLED_APPS, get_apps_to_install, get_test_modules

    import django
    from django.apps import apps
    from django.core.management import call_command

    django.setup()

    test_modules = list(get_test_modules(gis_enabled=False))
    installed_apps = list(ALWAYS_INSTALLED_APPS)
    for app in get_apps_to_install(test_modules):
        # Check against the list to prevent duplicate errors.
        if app not in installed_apps:
            installed_apps.append(app)
    apps.set_installed_apps(installed_apps)

    # Note: We don't use check=True here because --check calls sys.exit(1)
    # instead of raising CommandError when migrations are missing.
    call_command("makemigrations", "--check", verbosity=3)


if __name__ == "__main__":
    main()