Skip to content

Commit

Permalink
cov: remove unused fields from type Column
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangwalther committed Jan 2, 2021
1 parent c76c51a commit 3a70e70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
42 changes: 15 additions & 27 deletions src/PostgREST/DbStructure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ decodeColumns tables =
mapMaybe (columnFromRow tables) <$> HD.rowList colRow
where
colRow =
(,,,,,,,,,,,)
<$> column HD.text <*> column HD.text
<*> column HD.text <*> nullableColumn HD.text
<*> column HD.int4 <*> column HD.bool
<*> column HD.text <*> column HD.bool
<*> nullableColumn HD.int4
(,,,,,,,,)
<$> column HD.text
<*> column HD.text
<*> column HD.text
<*> nullableColumn HD.text
<*> column HD.bool
<*> column HD.text
<*> nullableColumn HD.int4
<*> nullableColumn HD.text
<*> nullableColumn HD.text
Expand Down Expand Up @@ -433,14 +434,12 @@ allColumns tabs =
info.table_name AS table_name,
info.column_name AS name,
info.description AS description,
info.ordinal_position AS position,
info.is_nullable::boolean AS nullable,
info.data_type AS col_type,
info.is_updatable::boolean AS updatable,
info.character_maximum_length AS max_len,
info.numeric_precision AS precision,
info.column_default AS default_value,
array_to_string(enum_info.vals, ',') AS enum
array_to_string(enum_info.vals, ',') AS enum,
info.position
FROM (
-- CTE based on pg_catalog to get PRIMARY/FOREIGN key and UNIQUE columns outside api schema
WITH key_columns AS (
Expand Down Expand Up @@ -475,7 +474,6 @@ allColumns tabs =
c.relname::name AS table_name,
a.attname::name AS column_name,
d.description AS description,
a.attnum::integer AS ordinal_position,
pg_get_expr(ad.adbin, ad.adrelid)::text AS column_default,
not (a.attnotnull OR t.typtype = 'd' AND t.typnotnull) AS is_nullable,
CASE
Expand All @@ -496,15 +494,8 @@ allColumns tabs =
information_schema._pg_truetypid(a.*, t.*),
information_schema._pg_truetypmod(a.*, t.*)
)::integer AS character_maximum_length,
information_schema._pg_numeric_precision(
information_schema._pg_truetypid(a.*, t.*),
information_schema._pg_truetypmod(a.*, t.*)
)::integer AS numeric_precision,
COALESCE(bt.typname, t.typname)::name AS udt_name,
(
c.relkind in ('r', 'v', 'f')
AND pg_column_is_updatable(c.oid::regclass, a.attnum, false)
)::bool is_updatable
a.attnum::integer AS position
FROM pg_attribute a
LEFT JOIN key_columns kc
ON kc.conkey = a.attnum AND kc.c_oid = a.attrelid
Expand Down Expand Up @@ -533,14 +524,12 @@ allColumns tabs =
table_name,
column_name,
description,
ordinal_position,
is_nullable,
data_type,
is_updatable,
character_maximum_length,
numeric_precision,
column_default,
udt_name
udt_name,
position
FROM columns
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
) AS info
Expand All @@ -558,13 +547,12 @@ allColumns tabs =

columnFromRow :: [Table] ->
(Text, Text, Text,
Maybe Text, Int32, Bool,
Text, Bool, Maybe Int32,
Maybe Text, Bool, Text,
Maybe Int32, Maybe Text, Maybe Text)
-> Maybe Column
columnFromRow tabs (s, t, n, desc, pos, nul, typ, u, l, p, d, e) = buildColumn <$> table
columnFromRow tabs (s, t, n, desc, nul, typ, l, d, e) = buildColumn <$> table
where
buildColumn tbl = Column tbl n desc pos nul typ u l p d (parseEnum e) Nothing
buildColumn tbl = Column tbl n desc nul typ l d (parseEnum e) Nothing
table = find (\tbl -> tableSchema tbl == s && tableName tbl == t) tabs
parseEnum :: Maybe Text -> [Text]
parseEnum = maybe [] (split (==','))
Expand Down
3 changes: 0 additions & 3 deletions src/PostgREST/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,9 @@ data Column =
colTable :: Table
, colName :: FieldName
, colDescription :: Maybe Text
, colPosition :: Int32
, colNullable :: Bool
, colType :: Text
, colUpdatable :: Bool
, colMaxLen :: Maybe Int32
, colPrecision :: Maybe Int32
, colDefault :: Maybe Text
, colEnum :: [Text]
, colFK :: Maybe ForeignKey
Expand Down

0 comments on commit 3a70e70

Please sign in to comment.