-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathchecks.py
32 lines (26 loc) · 1 KB
/
checks.py
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
32
from itertools import chain
from django.apps import apps
from django.core.checks import Tags, register
from django.db import connections, router
def check_indexes(app_configs, databases=None, **kwargs): # noqa: ARG001
"""
Call Index.check() on all model indexes.
This function will be obsolete when Django calls Index.check() after
https://code.djangoproject.com/ticket/36273.
"""
errors = []
if app_configs is None:
models = apps.get_models()
else:
models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
for model in models:
for db in databases or ():
if not router.allow_migrate_model(db, model):
continue
connection = connections[db]
for model_index in model._meta.indexes:
if hasattr(model_index, "check"):
errors.extend(model_index.check(model, connection))
return errors
def register_checks():
register(check_indexes, Tags.models)