entc/gen: add support for default annotation to PKs as well (#1492)

This commit is contained in:
Vojtěch Káně
2021-04-22 13:16:53 +02:00
committed by GitHub
parent de150626fc
commit 43ef74b8a8
2 changed files with 7 additions and 3 deletions

View File

@@ -57,12 +57,11 @@ func TestPostgres_Create(t *testing.T) {
{Name: "id", Type: field.TypeInt, Increment: true},
},
Columns: []*Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "id", Type: field.TypeUUID, Default: "uuid_generate_v4()"},
{Name: "name", Type: field.TypeString, Nullable: true},
{Name: "age", Type: field.TypeInt},
{Name: "doc", Type: field.TypeJSON, Nullable: true},
{Name: "enums", Type: field.TypeEnum, Enums: []string{"a", "b"}, Default: "a"},
{Name: "uuid", Type: field.TypeUUID, Default: "uuid_generate_v4()"},
{Name: "price", Type: field.TypeFloat64, SchemaType: map[string]string{dialect.Postgres: "numeric(5,2)"}},
{Name: "strings", Type: field.TypeOther, SchemaType: map[string]string{dialect.Postgres: "text[]"}, Nullable: true},
},
@@ -71,7 +70,7 @@ func TestPostgres_Create(t *testing.T) {
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 DEFAULT 'a', "uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "price" numeric(5,2) NOT NULL, "strings" text[] NULL, PRIMARY KEY("id"))`)).
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "users"("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" varchar NULL, "age" bigint NOT NULL, "doc" jsonb NULL, "enums" varchar NOT NULL DEFAULT 'a', "price" numeric(5,2) NOT NULL, "strings" text[] NULL, PRIMARY KEY("id"))`)).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectCommit()
},