diff options
| author | Caio Ariede <caio.ariede@gmail.com> | 2015-08-08 09:44:27 -0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-15 10:02:08 -0400 |
| commit | dad8434d6ff5da10959672726dc9b397296d380b (patch) | |
| tree | 035a70f167985e8f79d69d67c1b514604beb2f0b /tests/postgres_tests/test_array.py | |
| parent | 7a40fef17ab7918cbb1ddc3ba080f42b420f7a48 (diff) | |
Fixed #25180 -- Prevented varchar_patterns_ops and text_patterns_ops indexes for ArrayField.
Diffstat (limited to 'tests/postgres_tests/test_array.py')
| -rw-r--r-- | tests/postgres_tests/test_array.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 626a879b77..09ae4e8546 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -312,6 +312,33 @@ class TestMigrations(TransactionTestCase): with connection.cursor() as cursor: self.assertNotIn(table_name, connection.introspection.table_names(cursor)) + @override_settings(MIGRATION_MODULES={ + "postgres_tests": "postgres_tests.array_index_migrations", + }) + def test_adding_arrayfield_with_index(self): + """ + ArrayField shouldn't have varchar_patterns_ops or text_patterns_ops indexes. + """ + table_name = 'postgres_tests_chartextarrayindexmodel' + call_command('migrate', 'postgres_tests', verbosity=0) + with connection.cursor() as cursor: + like_constraint_field_names = [ + c.rsplit('_', 2)[0][len(table_name) + 1:] + for c in connection.introspection.get_constraints(cursor, table_name) + if c.endswith('_like') + ] + # Only the CharField should have a LIKE index. + self.assertEqual(like_constraint_field_names, ['char2']) + with connection.cursor() as cursor: + indexes = connection.introspection.get_indexes(cursor, table_name) + # All fields should have regular indexes. + self.assertIn('char', indexes) + self.assertIn('char2', indexes) + self.assertIn('text', indexes) + call_command('migrate', 'postgres_tests', 'zero', verbosity=0) + with connection.cursor() as cursor: + self.assertNotIn(table_name, connection.introspection.table_names(cursor)) + class TestSerialization(PostgreSQLTestCase): test_data = '[{"fields": {"field": "[\\"1\\", \\"2\\"]"}, "model": "postgres_tests.integerarraymodel", "pk": null}]' |
