Skip to content

Commit c0dcdb9

Browse files
committed
Rename db_performance to migrations
1 parent 5f0fef4 commit c0dcdb9

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

README.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,21 @@ Features
7575
Additional plugins
7676
------------------
7777

78-
``pylint_django.checkers.db_performance`` looks for migrations which add new
79-
model fields and these fields have a default value. According to
80-
`Django docs <https://docs.djangoproject.com/en/2.0/topics/migrations/#postgresql>`__
81-
this may have performance penalties especially on large tables. The prefered way
82-
is to add a new DB column with ``null=True`` because it will be created instantly
83-
and then possibly populate the table with the desired default values.
78+
``pylint_django.checkers.migrations`` looks for migrations which:
79+
80+
- add new model fields and these fields have a default value. According to
81+
`Django docs <https://docs.djangoproject.com/en/2.0/topics/migrations/#postgresql>`_
82+
this may have performance penalties especially on large tables. The prefered way
83+
is to add a new DB column with ``null=True`` because it will be created instantly
84+
and then possibly populate the table with the desired default values.
85+
Only the last migration from a sub-directory will be examined;
86+
- are ``migrations.RunPython()`` without a reverse callable - these will result in
87+
non reversible data migrations;
8488

85-
Only the last migration from a sub-directory will be examined!
8689

8790
This plugin is disabled by default! To enable it::
8891

89-
pylint --load-plugins pylint_django --load-plugins pylint_django.checkers.db_performance
92+
pylint --load-plugins pylint_django --load-plugins pylint_django.checkers.migrations
9093

9194

9295
Known issues

pylint_django/checkers/db_performance.py renamed to pylint_django/checkers/migrations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Copyright (c) 2018 Alexander Todorov <atodorov@MrSenko.com>
1+
# Copyright (c) 2018, 2020 Alexander Todorov <atodorov@MrSenko.com>
2+
# Copyright (c) 2020 Bryan Mutai <mutaiwork@gmail.com>
23

34
# Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
45
# For details: https://github.com/PyCQA/pylint-django/blob/master/LICENSE
56
"""
6-
Various DB performance suggestions. Disabled by default! Enable with
7-
pylint --load-plugins=pylint_django.checkers.db_performance
7+
Various suggestions around migrations. Disabled by default! Enable with
8+
pylint --load-plugins=pylint_django.checkers.migrations
89
"""
910

1011
import astroid

pylint_django/tests/test_func.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ def __init__(self, test_file):
5151
self._linter.load_plugin_configuration()
5252

5353

54-
class PylintDjangoDbPerformanceTest(PylintDjangoLintModuleTest):
54+
class PylintDjangoMigrationsTest(PylintDjangoLintModuleTest):
5555
"""
5656
Only used so that we can load
57-
pylint_django.checkers.db_performance into the linter!
57+
pylint_django.checkers.migrations into the linter!
5858
"""
5959
def __init__(self, test_file):
60-
super(PylintDjangoDbPerformanceTest, self).__init__(test_file)
61-
self._linter.load_plugin_modules(['pylint_django.checkers.db_performance'])
60+
super().__init__(test_file)
61+
self._linter.load_plugin_modules(['pylint_django.checkers.migrations'])
6262
self._linter.load_plugin_configuration()
6363

6464

@@ -74,7 +74,7 @@ def _file_name(test):
7474
if fname != '__init__.py' and fname.endswith('.py'):
7575
suite.append(FunctionalTestFile(input_dir, fname))
7676

77-
# when testing the db_performance plugin we need to sort by input file name
77+
# when testing the migrations plugin we need to sort by input file name
7878
# because the plugin reports the errors in close() which appends them to the
7979
# report for the last file in the list
8080
if sort:
@@ -96,14 +96,14 @@ def test_everything(test_file):
9696
LintTest._runTest()
9797

9898

99-
# NOTE: define tests for the db_performance checker!
100-
DB_PERFORMANCE_TESTS = get_tests('input/migrations', True)
101-
DB_PERFORMANCE_TESTS_NAMES = [t.base for t in DB_PERFORMANCE_TESTS]
99+
# NOTE: define tests for the migrations checker!
100+
MIGRATIONS_TESTS = get_tests('input/migrations', True)
101+
MIGRATIONS_TESTS_NAMES = [t.base for t in MIGRATIONS_TESTS]
102102

103103

104-
@pytest.mark.parametrize("test_file", DB_PERFORMANCE_TESTS, ids=DB_PERFORMANCE_TESTS_NAMES)
105-
def test_db_performance_plugin(test_file):
106-
LintTest = PylintDjangoDbPerformanceTest(test_file)
104+
@pytest.mark.parametrize("test_file", MIGRATIONS_TESTS, ids=MIGRATIONS_TESTS_NAMES)
105+
def test_migrations_plugin(test_file):
106+
LintTest = PylintDjangoMigrationsTest(test_file)
107107
LintTest.setUp()
108108
LintTest._runTest()
109109

0 commit comments

Comments
 (0)