mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #24442 -- Improved SchemaEditor's index name truncation.
This commit is contained in:
@@ -18,10 +18,34 @@ class SchemaIndexesTests(TestCase):
|
||||
with connection.schema_editor() as editor:
|
||||
index_name = editor._create_index_name(
|
||||
model=Article,
|
||||
column_names=("c1", "c2", "c3"),
|
||||
column_names=("c1",),
|
||||
suffix="123",
|
||||
)
|
||||
self.assertEqual(index_name, "indexes_article_c1_7ce4cc86123")
|
||||
self.assertEqual(index_name, "indexes_article_c1_a52bd80b123")
|
||||
|
||||
def test_index_name(self):
|
||||
"""
|
||||
Index names on the built-in database backends::
|
||||
* Are truncated as needed.
|
||||
* Include all the column names.
|
||||
* Include a deterministic hash.
|
||||
"""
|
||||
long_name = 'l%sng' % ('o' * 100)
|
||||
with connection.schema_editor() as editor:
|
||||
index_name = editor._create_index_name(
|
||||
model=Article,
|
||||
column_names=('c1', 'c2', long_name),
|
||||
suffix='ix',
|
||||
)
|
||||
expected = {
|
||||
'mysql': 'indexes_article_c1_c2_looooooooooooooooooo_255179b2ix',
|
||||
'oracle': 'indexes_a_c1_c2_loo_255179b2ix',
|
||||
'postgresql': 'indexes_article_c1_c2_loooooooooooooooooo_255179b2ix',
|
||||
'sqlite': 'indexes_article_c1_c2_l%sng_255179b2ix' % ('o' * 100),
|
||||
}
|
||||
if connection.vendor not in expected:
|
||||
self.skipTest('This test is only supported on the built-in database backends.')
|
||||
self.assertEqual(index_name, expected[connection.vendor])
|
||||
|
||||
def test_index_together(self):
|
||||
editor = connection.schema_editor()
|
||||
@@ -71,6 +95,6 @@ class SchemaIndexesTests(TestCase):
|
||||
self.skip("This test only applies to the InnoDB storage engine")
|
||||
index_sql = connection.schema_editor()._model_indexes_sql(ArticleTranslation)
|
||||
self.assertEqual(index_sql, [
|
||||
'CREATE INDEX `indexes_articletranslation_99fb53c2` '
|
||||
'CREATE INDEX `indexes_articletranslation_article_no_constraint_id_d6c0806b` '
|
||||
'ON `indexes_articletranslation` (`article_no_constraint_id`)'
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user