File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ def ready(self) -> None:
4747 """
4848 from django .conf import settings
4949
50+ from .checks import validate_has_pgviews_autodetector # noqa
51+
5052 sync_enabled = getattr (settings , "MATERIALIZED_VIEWS_DISABLE_SYNC_ON_MIGRATE" , False ) is False
5153
5254 if sync_enabled :
Original file line number Diff line number Diff line change 1+ from typing import Any
2+
3+ from django .core .checks import CheckMessage , Tags , register
4+ from django .core .checks import Warning as CheckWarning
5+
6+ from django_pgviews .db .migrations .autodetector import PGViewsAutodetector
7+
8+
9+ @register (Tags .database ) # type: ignore[not-callable]
10+ def validate_has_pgviews_autodetector (** kwargs : Any ) -> list [CheckMessage ]:
11+ from django .core .management import get_commands , load_command_class
12+
13+ commands = get_commands ()
14+
15+ make_migrations = load_command_class (commands ["makemigrations" ], "makemigrations" )
16+ migrate = load_command_class (commands ["migrate" ], "migrate" )
17+
18+ if not issubclass (
19+ migrate .autodetector , # type: ignore[missing-attribute]
20+ PGViewsAutodetector ,
21+ ) or not issubclass (
22+ make_migrations .autodetector , # type: ignore[missing-attribute]
23+ PGViewsAutodetector ,
24+ ):
25+ return [
26+ CheckWarning (
27+ (
28+ "If you don't use PGViewsAutodetector on your migrate and makemigrations commands, "
29+ "django_pgviews will not detect and delete that views have been removed. "
30+ "You are seeing this because you or some other dependency has overwritten the commands "
31+ "from django_pgviews. "
32+ ),
33+ hint = (
34+ f"The makemigrations.Command.autodetector is { make_migrations .autodetector .__name__ } , " # type: ignore[missing-attribute]
35+ f"the migrate.Command.autodetector is { migrate .autodetector .__name__ } ." # type: ignore[missing-attribute]
36+ ),
37+ id = "django_pgviews.W001" ,
38+ )
39+ ]
40+
41+ return []
You can’t perform that action at this time.
0 commit comments