Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
2f19306a
Kaydet (Commit)
2f19306a
authored
Agu 08, 2016
tarafından
Akshesh
Kaydeden (comit)
Tim Graham
Agu 12, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27030 -- Added index type introspection on PostgreSQL.
üst
72d541b6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
6 deletions
+21
-6
introspection.py
django/contrib/gis/db/backends/postgis/introspection.py
+6
-4
features.py
django/db/backends/base/features.py
+3
-0
features.py
django/db/backends/postgresql/features.py
+1
-0
introspection.py
django/db/backends/postgresql/introspection.py
+6
-2
tests.py
tests/introspection/tests.py
+5
-0
No files found.
django/contrib/gis/db/backends/postgis/introspection.py
Dosyayı görüntüle @
2f19306a
...
...
@@ -24,14 +24,16 @@ class PostGISIntrospection(DatabaseIntrospection):
# expression over the raster column through the ST_ConvexHull function.
# So the default query has to be adapted to include raster indices.
_get_indexes_query
=
"""
SELECT DISTINCT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
pg_catalog.pg_index idx, pg_catalog.pg_attribute attr
LEFT JOIN pg_catalog.pg_type t ON t.oid = attr.atttypid
SELECT DISTINCT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary
,
am.amname
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index idx,
pg_catalog.pg_attribute attr, pg_catalog.pg_type t, pg_catalog.pg_am am
WHERE
c.oid = idx.indrelid
AND idx.indexrelid = c2.oid
AND attr.attrelid = c.oid
AND t.oid = attr.atttypid
AND c2.relam = am.oid
AND (
attr.attnum = idx.indkey[0] OR
(t.typname LIKE 'raster' AND idx.indkey = '0')
...
...
django/db/backends/base/features.py
Dosyayı görüntüle @
2f19306a
...
...
@@ -163,6 +163,9 @@ class BaseDatabaseFeatures(object):
# Can the backend introspect the column order (ASC/DESC) for indexes?
supports_index_column_ordering
=
True
# Can the backend introspect the type of index created?
can_introspect_index_type
=
False
# Support for the DISTINCT ON clause
can_distinct_on_fields
=
False
...
...
django/db/backends/postgresql/features.py
Dosyayı görüntüle @
2f19306a
...
...
@@ -22,6 +22,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
can_introspect_autofield
=
True
can_introspect_ip_address_field
=
True
can_introspect_small_integer_field
=
True
can_introspect_index_type
=
True
can_distinct_on_fields
=
True
can_rollback_ddl
=
True
supports_combined_alters
=
True
...
...
django/db/backends/postgresql/introspection.py
Dosyayı görüntüle @
2f19306a
...
...
@@ -36,13 +36,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
ignored_tables
=
[]
_get_indexes_query
=
"""
SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary
SELECT attr.attname, idx.indkey, idx.indisunique, idx.indisprimary,
am.amname
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
pg_catalog.pg_index idx, pg_catalog.pg_attribute attr
pg_catalog.pg_index idx, pg_catalog.pg_attribute attr
, pg_catalog.pg_am am
WHERE c.oid = idx.indrelid
AND idx.indexrelid = c2.oid
AND attr.attrelid = c.oid
AND attr.attnum = idx.indkey[0]
AND c2.relam = am.oid
AND c.relname =
%
s"""
def
get_field_type
(
self
,
data_type
,
description
):
...
...
@@ -132,6 +134,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
# row[1] (idx.indkey) is stored in the DB as an array. It comes out as
# a string of space-separated integers. This designates the field
# indexes (1-based) of the fields that have indexes on the table.
# row[4] is the type of index, e.g. btree, hash, etc.
# Here, we skip any indexes across multiple fields.
if
' '
in
row
[
1
]:
continue
...
...
@@ -142,6 +145,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
indexes
[
row
[
0
]][
'primary_key'
]
=
True
if
row
[
2
]:
indexes
[
row
[
0
]][
'unique'
]
=
True
indexes
[
row
[
0
]][
'type'
]
=
row
[
4
]
return
indexes
def
get_constraints
(
self
,
cursor
,
table_name
):
...
...
tests/introspection/tests.py
Dosyayı görüntüle @
2f19306a
...
...
@@ -170,6 +170,11 @@ class IntrospectionTests(TransactionTestCase):
def
test_get_indexes
(
self
):
with
connection
.
cursor
()
as
cursor
:
indexes
=
connection
.
introspection
.
get_indexes
(
cursor
,
Article
.
_meta
.
db_table
)
if
connection
.
features
.
can_introspect_index_type
:
index_type
=
indexes
[
'reporter_id'
]
.
pop
(
'type'
,
None
)
self
.
assertIsNotNone
(
index_type
)
if
connection
.
vendor
==
'postgresql'
:
self
.
assertEqual
(
index_type
,
'btree'
)
self
.
assertEqual
(
indexes
[
'reporter_id'
],
{
'unique'
:
False
,
'primary_key'
:
False
})
def
test_get_indexes_multicol
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment