Skip to content

Commit

Permalink
fix regexp for numeric type
Browse files Browse the repository at this point in the history
  • Loading branch information
aj0strow committed Dec 22, 2017
1 parent cdd35a5 commit cee4ad0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
27 changes: 27 additions & 0 deletions regtest/t006/numeric_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package t001

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

func TestArray(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())
}
}
8 changes: 8 additions & 0 deletions regtest/t006/schema.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

schema "_schema_" {
table "currency_pairs" {
column "tick_size" {
type = "numeric(24, 16)"
}
}
}
4 changes: 4 additions & 0 deletions regtest/t006/setup.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

CREATE TABLE currency_pairs (
tick_size numeric(24, 16)
);
14 changes: 14 additions & 0 deletions source/hcl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ func TestConvertColumn(t *testing.T) {
},
},
},
Test{
"tick_size",
Column{
Type: "numeric(24, 16)",
},
db.ColumnNode{
Column: db.Column{
ColumnName: "tick_size",
DataType: "numeric",
NumericPrecision: 24,
NumericScale: 16,
},
},
},
Test{
"upper4",
Column{
Expand Down
2 changes: 1 addition & 1 deletion source/hcl/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func convertTable(tableName string, v Table) db.TableNode {
}
}

var numericRe = regexp.MustCompile(`numeric\((\d+),(\d+)\)`)
var numericRe = regexp.MustCompile(`numeric\((\d+),\s*(\d+)\)`)
var arrayRe = regexp.MustCompile(`^(.+)(?:\[\d*\])+$`)

func convertColumn(k string, v Column) db.ColumnNode {
Expand Down

0 comments on commit cee4ad0

Please sign in to comment.