dialect/sql/schema: add optional schema-type to column spec (#461)

This commit is contained in:
Ariel Mashraki
2020-05-04 20:16:43 +03:00
committed by GitHub
parent b456251154
commit 51cdda421f
7 changed files with 34 additions and 17 deletions

View File

@@ -11,10 +11,11 @@ import (
"strings"
"testing"
"github.com/facebookincubator/ent/dialect"
"github.com/facebookincubator/ent/dialect/sql"
"github.com/facebookincubator/ent/schema/field"
"github.com/DATA-DOG/go-sqlmock"
"github.com/facebookincubator/ent/dialect/sql"
"github.com/stretchr/testify/require"
)
@@ -62,13 +63,14 @@ func TestPostgres_Create(t *testing.T) {
{Name: "doc", Type: field.TypeJSON, Nullable: true},
{Name: "enums", Type: field.TypeEnum, Enums: []string{"a", "b"}},
{Name: "uuid", Type: field.TypeUUID},
{Name: "price", Type: field.TypeFloat64, SchemaType: map[string]string{dialect.Postgres: "numeric(5,2)"}},
},
},
},
before: func(mock pgMock) {
mock.start("120000")
mock.tableExists("users", false)
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "users"("id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, "name" varchar NULL, "age" bigint NOT NULL, "doc" jsonb NULL, "enums" varchar NOT NULL, "uuid" uuid NOT NULL, PRIMARY KEY("id"))`)).
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "users"("id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, "name" varchar NULL, "age" bigint NOT NULL, "doc" jsonb NULL, "enums" varchar NOT NULL, "uuid" uuid NOT NULL, "price" numeric(5,2) NOT NULL, PRIMARY KEY("id"))`)).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectCommit()
},