Skip to content

Commit

Permalink
fix user-defined types
Browse files Browse the repository at this point in the history
  • Loading branch information
aj0strow committed Jan 9, 2017
1 parent fcf72bc commit 448c55f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cli

const Version = "0.0.3"
const Version = "0.0.4"
3 changes: 2 additions & 1 deletion regtest/regtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func (r *RegressionTest) Run() ([]order.Change, error) {
if err != nil {
return nil, err
}
if _, err := r.Conn.Exec(string(f1)); err != nil {
setup := bytes.Replace(f1, []byte("_schema_"), []byte(r.Conn.SchemaName), 1)
if _, err := r.Conn.Exec(string(setup)); err != nil {
return nil, err
}
f2, err := ioutil.ReadFile(r.SourceFile)
Expand Down
28 changes: 28 additions & 0 deletions regtest/t003/citext_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package t001

import (
"github.com/aj0strow/pgschema/regtest"
"github.com/aj0strow/pgschema/temp"
"testing"
)

func TestCitext(t *testing.T) {
conn, err := temp.Connect("pgschema")
if err != nil {
t.Fatal(err)
}
defer conn.Close()

rt := regtest.RegressionTest{
Conn: conn,
SetupFile: "./setup.sql",
SourceFile: "./schema.hcl",
}
have, err := rt.Run()
if err != nil {
t.Fatal(err)
}
for _, c := range have {
t.Errorf(c.String())
}
}
9 changes: 9 additions & 0 deletions regtest/t003/schema.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

schema "_schema_" {
table "users" {
column "user_name" {
type = "citext"
not_null = true
}
}
}
4 changes: 4 additions & 0 deletions regtest/t003/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

CREATE TABLE users (
user_name public.citext not null
);
8 changes: 7 additions & 1 deletion source/psql/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func LoadColumns(conn Conn, schemaName, tableName string) ([]db.Column, error) {
column_default,
numeric_precision,
numeric_scale,
numeric_precision_radix
numeric_precision_radix,
udt_name
FROM information_schema.columns
WHERE table_schema = '%s'
AND table_name = '%s'
Expand All @@ -49,6 +50,7 @@ func LoadColumns(conn Conn, schemaName, tableName string) ([]db.Column, error) {
numericPrecision pgx.NullInt32
numericScale pgx.NullInt32
numericRadix pgx.NullInt32
udtName string
)
err := rows.Scan(
&column.ColumnName,
Expand All @@ -58,10 +60,14 @@ func LoadColumns(conn Conn, schemaName, tableName string) ([]db.Column, error) {
&numericPrecision,
&numericScale,
&numericRadix,
&udtName,
)
if err != nil {
return nil, err
}
if column.DataType == "USER-DEFINED" {
column.DataType = udtName
}
column.NotNull = isNullable == "NO"
column.Default = colDefault.String
if numericRadix.Valid {
Expand Down

0 comments on commit 448c55f

Please sign in to comment.