summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-07-12 17:50:17 -0700
committerTim Graham <timograham@gmail.com>2016-07-13 22:15:43 -0400
commit8edfdddbc8d6a4e39c4bf175075822ca3751b054 (patch)
tree7d7a4f0efae8fc4dea91956c5247dbedb6d679ae
parent3e562cf7a2fab31b4f129661ba9411710d24c5e7 (diff)
[1.8.x] Fixed #26889 -- Fixed missing PostgreSQL index in SchemaEditor.add_field().
Backport of 2e4cfcd2b9a0984ad6c4087a5deebbf33413835c from master
-rw-r--r--django/db/backends/postgresql_psycopg2/schema.py6
-rw-r--r--docs/releases/1.8.14.txt14
-rw-r--r--docs/releases/index.txt1
-rw-r--r--tests/schema/tests.py27
4 files changed, 48 insertions, 0 deletions
diff --git a/django/db/backends/postgresql_psycopg2/schema.py b/django/db/backends/postgresql_psycopg2/schema.py
index 884ac44dee..e3b642bd36 100644
--- a/django/db/backends/postgresql_psycopg2/schema.py
+++ b/django/db/backends/postgresql_psycopg2/schema.py
@@ -14,6 +14,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def quote_value(self, value):
return psycopg2.extensions.adapt(value)
+ def add_field(self, model, field):
+ super(DatabaseSchemaEditor, self).add_field(model, field)
+ like_index_statement = self._create_like_index_sql(model, field)
+ if like_index_statement is not None:
+ self.deferred_sql.append(like_index_statement)
+
def _model_indexes_sql(self, model):
output = super(DatabaseSchemaEditor, self)._model_indexes_sql(model)
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
diff --git a/docs/releases/1.8.14.txt b/docs/releases/1.8.14.txt
new file mode 100644
index 0000000000..6311172abc
--- /dev/null
+++ b/docs/releases/1.8.14.txt
@@ -0,0 +1,14 @@
+===========================
+Django 1.8.14 release notes
+===========================
+
+*Under development*
+
+Django 1.8.14 fixes several bugs in 1.8.13.
+
+Bugfixes
+========
+
+* Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and
+ ``TextField`` respectively when using ``AddField`` on PostgreSQL
+ (:ticket:`26889`).
diff --git a/docs/releases/index.txt b/docs/releases/index.txt
index 1a40bc48be..070d815ec1 100644
--- a/docs/releases/index.txt
+++ b/docs/releases/index.txt
@@ -25,6 +25,7 @@ versions of the documentation contain the release notes for any later releases.
.. toctree::
:maxdepth: 1
+ 1.8.14
1.8.13
1.8.12
1.8.11
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 439a59f0f9..8682f703ec 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1552,6 +1552,33 @@ class SchemaTests(TransactionTestCase):
editor.add_field(Author, new_field)
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
+ def test_add_indexed_charfield(self):
+ field = CharField(max_length=255, db_index=True)
+ field.set_attributes_from_name('nom_de_plume')
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.add_field(Author, field)
+ indexes = self.get_constraints_for_column(Author, 'nom_de_plume')
+ # Should create two indexes; one for like operator.
+ self.assertEqual(len(indexes), 2)
+ # Check that one of the indexes ends with `_like`
+ like_index = [x for x in indexes if x.endswith('_like')]
+ self.assertEqual(1, len(like_index), 'Index with the operator class is missing')
+
+ @unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
+ def test_add_unique_charfield(self):
+ field = CharField(max_length=255, unique=True)
+ field.set_attributes_from_name('nom_de_plume')
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.add_field(Author, field)
+ indexes = self.get_constraints_for_column(Author, 'nom_de_plume')
+ # Should create two indexes; one for like operator.
+ self.assertEqual(len(indexes), 2)
+ like_index = [x for x in indexes if x.endswith('_like')]
+ self.assertEqual(1, len(like_index), 'Index with the operator class is missing')
+
+ @unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
def test_alter_field_add_index_to_charfield(self):
# Create the table and verify no initial indexes.
with connection.schema_editor() as editor: