Skip to content

Commit 2e9cf79

Browse files
committed
Hide the migrations when not using the database store.
This is a bit of a hack as we're adjusting the project's settings and it hides all migrations.
1 parent 24e9065 commit 2e9cf79

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

debug_toolbar/apps.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def ready(self):
2424
# allows panels like CachePanel to enable their instrumentation immediately.
2525
for cls in DebugToolbar.get_panel_classes():
2626
cls.ready()
27+
_manage_migrations_visibility(self.name)
28+
29+
30+
def _manage_migrations_visibility(app_name):
31+
"""
32+
Adjust the toolbar's migration visibility by manipulating the
33+
project's settings.
34+
35+
This is a hack since it's manipulating settings.
36+
"""
37+
if (
38+
dt_settings.get_config()["TOOLBAR_STORE_CLASS"]
39+
!= "debug_toolbar.store.DatabaseStore"
40+
):
41+
# This effectively hides the migrations by telling Django they don't exist.
42+
settings.MIGRATION_MODULES.setdefault(app_name, None)
2743

2844

2945
def check_template_config(config):

docs/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Pending
1616
* Upgraded CI ``postgis`` version to 17-3.5.
1717
* Added how to generate the documentation locally to the contributing
1818
documentation.
19+
* Hide the toolbar's migrations unless the database store is being used. This
20+
may change in the future.
1921

2022
6.0.0 (2025-07-22)
2123
------------------

docs/configuration.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ Toolbar options
196196
The DatabaseStore provides persistence and automatically cleans up old
197197
entries based on the ``RESULTS_CACHE_SIZE`` setting.
198198

199-
Note: For full functionality, DatabaseStore requires migrations for
200-
the debug_toolbar app:
199+
Note: When using ``DatabaseStore`` migrations are required for
200+
the ``debug_toolbar`` app:
201201

202202
.. code-block:: bash
203203
204204
python manage.py migrate debug_toolbar
205205
206-
For the DatabaseStore to work properly, you need to run migrations for the
207-
debug_toolbar app. The migrations create the necessary database table to store
206+
For the ``DatabaseStore`` to work properly, you need to run migrations for the
207+
``debug_toolbar`` app. The migrations create the necessary database table to store
208208
toolbar data.
209209

210210
.. _TOOLBAR_LANGUAGE:

tests/test_apps.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from unittest.mock import patch
2+
3+
from django.test import SimpleTestCase, override_settings
4+
5+
from debug_toolbar.apps import _manage_migrations_visibility
6+
7+
8+
class AppsTestCase(SimpleTestCase):
9+
@override_settings(
10+
DEBUG_TOOLBAR_CONFIG={
11+
"TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore"
12+
}
13+
)
14+
@patch("debug_toolbar.apps.settings.MIGRATION_MODULES")
15+
def test_migrations_are_visible(self, mocked_migration_modules):
16+
_manage_migrations_visibility("debug_toolbar")
17+
self.assertFalse(mocked_migration_modules.setdefault.called)
18+
19+
@override_settings(
20+
DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore"}
21+
)
22+
@patch("debug_toolbar.apps.settings.MIGRATION_MODULES")
23+
def test_migrations_are_hidden(self, mocked_migration_modules):
24+
_manage_migrations_visibility("debug_toolbar")
25+
mocked_migration_modules.setdefault.assert_called_once_with(
26+
"debug_toolbar", None
27+
)

0 commit comments

Comments
 (0)