dialect/sql/schema: fix bug when using multiple table CHECK constraints (#2188)

Fixed https://github.com/ent/ent/issues/2185
This commit is contained in:
Ariel Mashraki
2021-12-01 12:00:06 +02:00
committed by GitHub
parent d432d880c7
commit 475e237937
3 changed files with 5 additions and 2 deletions

View File

@@ -71,6 +71,7 @@ func TestPostgres_Create(t *testing.T) {
Annotation: &entsql.Annotation{
Check: "price > 0",
Checks: map[string]string{
"valid_age": "age > 0",
"valid_name": "name <> ''",
},
},
@@ -79,7 +80,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" uuid NOT NULL DEFAULT uuid_generate_v4(), "block_size" bigint NOT NULL DEFAULT current_setting('block_size')::bigint, "name" varchar NULL COLLATE "he_IL", "age" bigint NOT NULL, "doc" jsonb NULL, "enums" varchar NOT NULL DEFAULT 'a', "price" numeric(5,2) NOT NULL, "strings" text[] NULL, "fixed_string" varchar(100) NOT NULL, PRIMARY KEY("id"), CHECK (price > 0), CONSTRAINT "valid_name" CHECK (name <> ''))`)).
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "users"("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "block_size" bigint NOT NULL DEFAULT current_setting('block_size')::bigint, "name" varchar NULL COLLATE "he_IL", "age" bigint NOT NULL, "doc" jsonb NULL, "enums" varchar NOT NULL DEFAULT 'a', "price" numeric(5,2) NOT NULL, "strings" text[] NULL, "fixed_string" varchar(100) NOT NULL, PRIMARY KEY("id"), CHECK (price > 0), CONSTRAINT "valid_age" CHECK (age > 0), CONSTRAINT "valid_name" CHECK (name <> ''))`)).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectCommit()
},