diff options
author | Tim Graham <timograham@gmail.com> | 2020-09-15 01:38:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 07:38:50 +0200 |
commit | 7f2392981dab255286b2b042c758c098ec8582e2 (patch) | |
tree | f6daadbaca0cc1c8c5f0349987060d13927a1a05 /django/db/backends/postgresql/introspection.py | |
parent | e11d05e0b488a3ff2b3c9d8f2e1e50f471750d6e (diff) | |
download | django-7f2392981dab255286b2b042c758c098ec8582e2.tar.gz |
Added DatabaseIntrospection.index_default_access_method hook on the PostgreSQL backend.
This hook is for the CockroachDB backend where the name is 'prefix'.
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r-- | django/db/backends/postgresql/introspection.py | 13 |
1 files 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 [], |