From 882b4311b50a212c4d1e3906fbfbd05b9d1a0113 Mon Sep 17 00:00:00 2001 From: Mike Nelson Date: Wed, 28 Aug 2024 11:09:16 -0600 Subject: [PATCH 1/3] Fix Postgres column array detection --- generator/postgres/query_set.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/generator/postgres/query_set.go b/generator/postgres/query_set.go index d61bd34..329741a 100644 --- a/generator/postgres/query_set.go +++ b/generator/postgres/query_set.go @@ -65,11 +65,12 @@ select not attr.attnotnull as "column.isNullable", attr.attgenerated = 's' as "column.isGenerated", attr.atthasdef as "column.hasDefault", - (case tp.typtype - when 'b' then 'base' - when 'd' then 'base' - when 'e' then 'enum' - when 'r' then 'range' + (case + when tp.typtype = 'b' AND tp.typcategory <> 'A' then 'base' + when tp.typtype = 'b' AND tp.typcategory = 'A' then 'array' + when tp.typtype = 'd' then 'base' + when tp.typtype = 'e' then 'enum' + when tp.typtype = 'r' then 'range' end) as "dataType.Kind", (case when tp.typtype = 'd' then (select pg_type.typname from pg_catalog.pg_type where pg_type.oid = tp.typbasetype) when tp.typcategory = 'A' then pg_catalog.format_type(attr.atttypid, attr.atttypmod) From 52df6593185632b31e908c172c82b856437b485c Mon Sep 17 00:00:00 2001 From: Mike Nelson Date: Wed, 28 Aug 2024 11:45:44 -0600 Subject: [PATCH 2/3] test --- tests/postgres/generator_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/postgres/generator_test.go b/tests/postgres/generator_test.go index a1ea307..fe1407f 100644 --- a/tests/postgres/generator_test.go +++ b/tests/postgres/generator_test.go @@ -222,10 +222,18 @@ func TestGenerator_TableMetadata(t *testing.T) { // Spot check the actor table and assert that the emitted // properties are as expected. var got metadata.Table + var specialFeatures metadata.Column for _, table := range schema.TablesMetaData { if table.Name == "actor" { got = table } + if table.Name == "film" { + for _, column := range table.Columns { + if column.Name == "special_features" { + specialFeatures = column + } + } + } } want := metadata.Table{ @@ -238,6 +246,7 @@ func TestGenerator_TableMetadata(t *testing.T) { }, } require.Equal(t, want, got) + require.Equal(t, metadata.ArrayType, specialFeatures.DataType.Kind) } func TestGeneratorSpecialCharacters(t *testing.T) { From cf08bcd6f725c98d1749b2dc3654e1dc52bea7d9 Mon Sep 17 00:00:00 2001 From: Mike Nelson Date: Wed, 28 Aug 2024 11:46:35 -0600 Subject: [PATCH 3/3] spacing --- generator/postgres/query_set.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/postgres/query_set.go b/generator/postgres/query_set.go index 329741a..abb21ba 100644 --- a/generator/postgres/query_set.go +++ b/generator/postgres/query_set.go @@ -67,7 +67,7 @@ select attr.atthasdef as "column.hasDefault", (case when tp.typtype = 'b' AND tp.typcategory <> 'A' then 'base' - when tp.typtype = 'b' AND tp.typcategory = 'A' then 'array' + when tp.typtype = 'b' AND tp.typcategory = 'A' then 'array' when tp.typtype = 'd' then 'base' when tp.typtype = 'e' then 'enum' when tp.typtype = 'r' then 'range'