summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-12-24 15:55:57 +0100
committerClaude Paroz <claude@2xlibre.net>2014-12-27 12:52:44 +0100
commit2ceb10f3b02cbebad6ed908880f49a7c3e901d12 (patch)
treed79a50705b32da2fa33c37b8c54e99ce9108b599 /tests
parent47182965465f47657cbab6858a6a8637cc32b2df (diff)
Fixed #14180 -- Prevented unneeded index creation on MySQL-InnoDB
Thanks zimnyx for the report and Simon Charette, Tim Graham for the reviews.
Diffstat (limited to 'tests')
-rw-r--r--tests/commands_sql/tests.py12
-rw-r--r--tests/indexes/tests.py16
2 files changed, 21 insertions, 7 deletions
diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py
index e1d4272616..10f0404776 100644
--- a/tests/commands_sql/tests.py
+++ b/tests/commands_sql/tests.py
@@ -72,14 +72,14 @@ class SQLCommandsTestCase(TestCase):
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=RemovedInDjango20Warning)
output = sql_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
- # PostgreSQL creates one additional index for CharField
- self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4])
+ # Number of indexes is backend-dependent
+ self.assertTrue(1 <= self.count_ddl(output, 'CREATE INDEX') <= 4)
def test_sql_destroy_indexes(self):
app_config = apps.get_app_config('commands_sql')
output = sql_destroy_indexes(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
- # PostgreSQL creates one additional index for CharField
- self.assertIn(self.count_ddl(output, 'DROP INDEX'), [3, 4])
+ # Number of indexes is backend-dependent
+ self.assertTrue(1 <= self.count_ddl(output, 'DROP INDEX') <= 4)
def test_sql_all(self):
app_config = apps.get_app_config('commands_sql')
@@ -88,8 +88,8 @@ class SQLCommandsTestCase(TestCase):
output = sql_all(app_config, no_style(), connections[DEFAULT_DB_ALIAS])
self.assertEqual(self.count_ddl(output, 'CREATE TABLE'), 3)
- # PostgreSQL creates one additional index for CharField
- self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4])
+ # Number of indexes is backend-dependent
+ self.assertTrue(1 <= self.count_ddl(output, 'CREATE INDEX') <= 4)
class TestRouter(object):
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py
index 86000bb94c..0710446245 100644
--- a/tests/indexes/tests.py
+++ b/tests/indexes/tests.py
@@ -5,7 +5,7 @@ from django.db import connection
from django.test import TestCase
from django.test.utils import IgnorePendingDeprecationWarningsMixin
-from .models import Article, IndexTogetherSingleList
+from .models import Article, ArticleTranslation, IndexTogetherSingleList
class CreationIndexesTests(IgnorePendingDeprecationWarningsMixin, TestCase):
@@ -82,3 +82,17 @@ class SchemaIndexesTests(TestCase):
"""Test indexes are not created for related objects"""
index_sql = connection.schema_editor()._model_indexes_sql(Article)
self.assertEqual(len(index_sql), 1)
+
+ @skipUnless(connection.vendor == 'mysql', "This is a mysql-specific issue")
+ def test_no_index_for_foreignkey(self):
+ """
+ MySQL on InnoDB already creates indexes automatically for foreign keys.
+ (#14180).
+ """
+ storage = connection.introspection.get_storage_engine(
+ connection.cursor(), ArticleTranslation._meta.db_table
+ )
+ if storage != "InnoDB":
+ self.skip("This test only applies to the InnoDB storage engine")
+ index_sql = connection.schema_editor()._model_indexes_sql(ArticleTranslation)
+ self.assertEqual(index_sql, [])