Skip to content

Commit

Permalink
enable DatabaseFeatures.supports_expression_indexes on CockroachDB 21.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Oct 27, 2021
1 parent bf17857 commit eba0d82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ using back to Cockroach Labs. To disable this, set

- [changing column type if it's part of an index](https://go.crdb.dev/issue/47636)
- dropping or changing a table's primary key
- [indexes on expressions](https://github.com/cockroachdb/cockroach/issues/9682) (Django's [`Index.expressions`](https://docs.djangoproject.com/en/stable/ref/models/indexes/#django.db.models.Index.expressions))
- CockroachDB executes `ALTER COLUMN` queries asynchronously which is at
odds with Django's assumption that the database is altered before the next
migration operation begins. CockroachDB will give an error like
Expand Down Expand Up @@ -137,6 +136,12 @@ using back to Cockroach Labs. To disable this, set
overlaps_below (&>|)](https://github.com/cockroachdb/cockroach/issues/57098)
- [strictly_above (|>>), strictly_below (<<|)](https://github.com/cockroachdb/cockroach/issues/57095)

## Known issues and limitations in CockroachDB 21.1.x and earlier

- [Indexes on expressions](https://github.com/cockroachdb/cockroach/issues/9682)
(Django's [`Index.expressions`](https://docs.djangoproject.com/en/stable/ref/models/indexes/#django.db.models.Index.expressions))
aren't supported.

## Known issues and limitations in CockroachDB 20.2.x and earlier

- Changing a column's type isn't supported.
Expand Down
15 changes: 14 additions & 1 deletion django_cockroachdb/features.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import operator

from django.db.backends.postgresql.features import (
DatabaseFeatures as PostgresDatabaseFeatures,
)
Expand Down Expand Up @@ -74,7 +76,7 @@ def introspected_field_types(self):
}

# Not supported: https://github.com/cockroachdb/cockroach/issues/9682
supports_expression_indexes = False
supports_expression_indexes = property(operator.attrgetter('is_cockroachdb_21_2'))

@cached_property
def is_cockroachdb_21_1(self):
Expand Down Expand Up @@ -184,9 +186,20 @@ def django_test_expected_failures(self):
'model_fields.test_jsonfield.TestQuerying.test_order_grouping_custom_decoder',
'model_fields.test_jsonfield.TestQuerying.test_ordering_by_transform',
'model_fields.test_jsonfield.TestQuerying.test_ordering_grouping_by_key_transform',
# cannot index a json element:
# https://github.com/cockroachdb/cockroach/issues/30690
'schema.tests.SchemaTests.test_func_index_json_key_transform',
# unexpected partial unique index in pg_constraint query:
# https://github.com/cockroachdb/cockroach/issues/61098
'introspection.tests.IntrospectionTests.test_get_constraints_unique_indexes_orders',
# COLLATE expressions in index elements not supported:
# https://github.com/cockroachdb/cockroach/issues/71240
'schema.tests.SchemaTests.test_func_index_collate',
'schema.tests.SchemaTests.test_func_index_collate_f_ordered',
# ALTER COLUMN ... SET NOT NULL crashes with "validate check
# constraint: column "crdb_internal_idx_expr" does not exist":
# https://github.com/cockroachdb/cockroach/issues/72012
'migrations.test_operations.OperationTests.test_alter_field_with_func_index',
})
if not self.connection.features.is_cockroachdb_21_1:
expected_failures.update({
Expand Down

0 comments on commit eba0d82

Please sign in to comment.