mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Refs #25530 -- Tracked references of deferred SQL statements.
This commit is contained in:
parent
ea91ad4c13
commit
3b429c9673
6 changed files with 302 additions and 32 deletions
|
@ -51,7 +51,7 @@ class SchemaIndexesTests(TestCase):
|
|||
|
||||
def test_index_together(self):
|
||||
editor = connection.schema_editor()
|
||||
index_sql = editor._model_indexes_sql(Article)
|
||||
index_sql = [str(statement) for statement in editor._model_indexes_sql(Article)]
|
||||
self.assertEqual(len(index_sql), 1)
|
||||
# Ensure the index name is properly quoted
|
||||
self.assertIn(
|
||||
|
@ -70,7 +70,7 @@ class SchemaIndexesTests(TestCase):
|
|||
def test_postgresql_text_indexes(self):
|
||||
"""Test creation of PostgreSQL-specific text indexes (#12234)"""
|
||||
from .models import IndexedArticle
|
||||
index_sql = connection.schema_editor()._model_indexes_sql(IndexedArticle)
|
||||
index_sql = [str(statement) for statement in connection.schema_editor()._model_indexes_sql(IndexedArticle)]
|
||||
self.assertEqual(len(index_sql), 5)
|
||||
self.assertIn('("headline" varchar_pattern_ops)', index_sql[1])
|
||||
self.assertIn('("body" text_pattern_ops)', index_sql[3])
|
||||
|
@ -99,7 +99,7 @@ class SchemaIndexesMySQLTests(TransactionTestCase):
|
|||
)
|
||||
if storage != "InnoDB":
|
||||
self.skip("This test only applies to the InnoDB storage engine")
|
||||
index_sql = connection.schema_editor()._model_indexes_sql(ArticleTranslation)
|
||||
index_sql = [str(statement) for statement in connection.schema_editor()._model_indexes_sql(ArticleTranslation)]
|
||||
self.assertEqual(index_sql, [
|
||||
'CREATE INDEX `indexes_articletranslation_article_no_constraint_id_d6c0806b` '
|
||||
'ON `indexes_articletranslation` (`article_no_constraint_id`)'
|
||||
|
@ -114,7 +114,7 @@ class SchemaIndexesMySQLTests(TransactionTestCase):
|
|||
new_field.set_attributes_from_name('new_foreign_key')
|
||||
editor.add_field(ArticleTranslation, new_field)
|
||||
field_created = True
|
||||
self.assertEqual(editor.deferred_sql, [
|
||||
self.assertEqual([str(statement) for statement in editor.deferred_sql], [
|
||||
'ALTER TABLE `indexes_articletranslation` '
|
||||
'ADD CONSTRAINT `indexes_articletrans_new_foreign_key_id_d27a9146_fk_indexes_a` '
|
||||
'FOREIGN KEY (`new_foreign_key_id`) REFERENCES `indexes_article` (`id`)'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue