From 7f2392981dab255286b2b042c758c098ec8582e2 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 15 Sep 2020 01:38:50 -0400 Subject: [PATCH] Added DatabaseIntrospection.index_default_access_method hook on the PostgreSQL backend. This hook is for the CockroachDB backend where the name is 'prefix'. --- django/db/backends/postgresql/introspection.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index dee305cc06..b7952eaed7 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -28,6 +28,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): 2950: 'UUIDField', 3802: 'JSONField', } + # A hook for subclasses. + index_default_access_method = 'btree' ignored_tables = [] @@ -189,7 +191,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): pg_get_indexdef(idx.indexrelid) END AS exprdef, CASE am.amname - WHEN 'btree' THEN + WHEN %s THEN CASE (option & 1) WHEN 1 THEN 'DESC' ELSE 'ASC' END @@ -206,10 +208,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): WHERE c.relname = %s AND pg_catalog.pg_table_is_visible(c.oid) ) s2 GROUP BY indexname, indisunique, indisprimary, amname, exprdef, attoptions; - """, [table_name]) + """, [self.index_default_access_method, table_name]) for index, columns, unique, primary, orders, type_, definition, options in cursor.fetchall(): if index not in constraints: - basic_index = type_ == 'btree' and not index.endswith('_btree') and options is None + basic_index = ( + type_ == self.index_default_access_method and + # '_btree' references + # django.contrib.postgres.indexes.BTreeIndex.suffix. + not index.endswith('_btree') and options is None + ) constraints[index] = { "columns": columns if columns != [None] else [], "orders": orders if orders != [None] else [],