diff options
author | kimsoungryoul <kimsoungryoul@gmail.com> | 2022-10-16 14:59:39 +0900 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-12-28 06:28:07 +0100 |
commit | 78f163a4fb3937aca2e71786fbdd51a0ef39629e (patch) | |
tree | 7e61c2f8d96b9dab60e317d3483460064327d701 /django/db/backends/postgresql/introspection.py | |
parent | 68ef274bc505cd44f305c03cbf84cf08826200a8 (diff) | |
download | django-78f163a4fb3937aca2e71786fbdd51a0ef39629e.tar.gz |
Fixed #18468 -- Added support for comments on columns and tables.
Thanks Jared Chung, Tom Carrick, David Smith, Nick Pope, and Mariusz
Felisiak for reviews.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Co-authored-by: Nick Pope <nick@nickpope.me.uk>
Diffstat (limited to 'django/db/backends/postgresql/introspection.py')
-rw-r--r-- | django/db/backends/postgresql/introspection.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index a08ac2d039..d649b6fd4f 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -2,10 +2,11 @@ from collections import namedtuple from django.db.backends.base.introspection import BaseDatabaseIntrospection from django.db.backends.base.introspection import FieldInfo as BaseFieldInfo -from django.db.backends.base.introspection import TableInfo +from django.db.backends.base.introspection import TableInfo as BaseTableInfo from django.db.models import Index -FieldInfo = namedtuple("FieldInfo", BaseFieldInfo._fields + ("is_autofield",)) +FieldInfo = namedtuple("FieldInfo", BaseFieldInfo._fields + ("is_autofield", "comment")) +TableInfo = namedtuple("TableInfo", BaseTableInfo._fields + ("comment",)) class DatabaseIntrospection(BaseDatabaseIntrospection): @@ -62,7 +63,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): WHEN c.relispartition THEN 'p' WHEN c.relkind IN ('m', 'v') THEN 'v' ELSE 't' - END + END, + obj_description(c.oid) FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v') @@ -91,7 +93,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): NOT (a.attnotnull OR (t.typtype = 'd' AND t.typnotnull)) AS is_nullable, pg_get_expr(ad.adbin, ad.adrelid) AS column_default, CASE WHEN collname = 'default' THEN NULL ELSE collname END AS collation, - a.attidentity != '' AS is_autofield + a.attidentity != '' AS is_autofield, + col_description(a.attrelid, a.attnum) AS column_comment FROM pg_attribute a LEFT JOIN pg_attrdef ad ON a.attrelid = ad.adrelid AND a.attnum = ad.adnum LEFT JOIN pg_collation co ON a.attcollation = co.oid |