mirror of
https://github.com/ent/ent.git
synced 2026-05-04 00:20:58 +03:00
dialect/sql/schema: add pg user defined type for schema introspect (#994)
* Added user defined fields * pr feedback * added integration test * run generate * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> * Update dialect/sql/schema/postgres_test.go Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
@@ -192,10 +192,38 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "nextval('users_colname_seq'::regclass)"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "nextval('users_colname_seq'::regclass)", "int4"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
mock.ExpectCommit()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "scan table with custom type",
|
||||
tables: []*Table{
|
||||
{
|
||||
Name: "users",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "custom", Type: field.TypeOther, SchemaType: map[string]string{dialect.Postgres: "customtype"}},
|
||||
},
|
||||
PrimaryKey: []*Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "nextval('users_colname_seq'::regclass)", "NULL").
|
||||
AddRow("custom", "USER-DEFINED", "NO", "NULL", "customtype"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -229,20 +257,20 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character varying", "YES", "NULL").
|
||||
AddRow("uuid", "uuid", "YES", "NULL").
|
||||
AddRow("created_at", "date", "NO", "CURRENT_DATE").
|
||||
AddRow("updated_at", "timestamp", "YES", "NULL").
|
||||
AddRow("deleted_at", "date", "YES", "NULL").
|
||||
AddRow("text", "text", "YES", "NULL").
|
||||
AddRow("cidr", "cidr", "NO", "NULL").
|
||||
AddRow("inet", "inet", "YES", "NULL").
|
||||
AddRow("macaddr", "macaddr", "YES", "NULL").
|
||||
AddRow("macaddr8", "macaddr8", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character varying", "YES", "NULL", "varchar").
|
||||
AddRow("uuid", "uuid", "YES", "NULL", "uuid").
|
||||
AddRow("created_at", "date", "NO", "CURRENT_DATE", "date").
|
||||
AddRow("updated_at", "timestamp", "YES", "NULL", "timestamptz").
|
||||
AddRow("deleted_at", "date", "YES", "NULL", "date").
|
||||
AddRow("text", "text", "YES", "NULL", "text").
|
||||
AddRow("cidr", "cidr", "NO", "NULL", "cidr").
|
||||
AddRow("inet", "inet", "YES", "NULL", "inet").
|
||||
AddRow("macaddr", "macaddr", "YES", "NULL", "macaddr").
|
||||
AddRow("macaddr8", "macaddr8", "YES", "NULL", "macaddr8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -270,12 +298,12 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL").
|
||||
AddRow("doc", "jsonb", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar").
|
||||
AddRow("doc", "jsonb", "YES", "NULL", "jsonb"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -304,12 +332,12 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL").
|
||||
AddRow("doc", "jsonb", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar").
|
||||
AddRow("doc", "jsonb", "YES", "NULL", "jsonb"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -336,11 +364,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -367,11 +395,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -398,11 +426,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -428,11 +456,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -458,11 +486,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("name", "character", "NO", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("name", "character", "NO", "NULL", "bpchar"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -488,11 +516,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("age", "bigint", "NO", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("age", "bigint", "NO", "NULL", "int8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -518,11 +546,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("age", "bigint", "NO", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("age", "bigint", "NO", "NULL", "int8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0).
|
||||
@@ -548,11 +576,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("age", "bigint", "NO", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("age", "bigint", "NO", "NULL", "int8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0).
|
||||
@@ -602,12 +630,12 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("age", "bigint", "NO", "NULL").
|
||||
AddRow("score", "bigint", "NO", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("age", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("score", "bigint", "NO", "NULL", "int8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0).
|
||||
@@ -623,11 +651,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
mock.ExpectExec(escape(`CREATE UNIQUE INDEX "user_score" ON "users"("score")`)).
|
||||
WillReturnResult(sqlmock.NewResult(0, 1))
|
||||
mock.tableExists("equipment", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("equipment").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "NO", "NULL").
|
||||
AddRow("score", "bigint", "NO", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "NO", "NULL", "int8").
|
||||
AddRow("score", "bigint", "NO", "NULL", "int8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "equipment"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0).
|
||||
@@ -664,11 +692,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
before: func(mock pgMock) {
|
||||
mock.start("120000")
|
||||
mock.tableExists("users", true)
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "YES", "NULL").
|
||||
AddRow("name", "character", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "YES", "NULL", "int8").
|
||||
AddRow("name", "character", "YES", "NULL", "bpchar"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
@@ -730,10 +758,10 @@ func TestPostgres_Create(t *testing.T) {
|
||||
// query users table.
|
||||
mock.tableExists("users", true)
|
||||
// users table has no changes.
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
mock.ExpectQuery(escape(`SELECT "column_name", "data_type", "is_nullable", "column_default", "udt_name" FROM "information_schema"."columns" WHERE "table_schema" = CURRENT_SCHEMA() AND "table_name" = $1`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default"}).
|
||||
AddRow("id", "bigint", "YES", "NULL"))
|
||||
WillReturnRows(sqlmock.NewRows([]string{"column_name", "data_type", "is_nullable", "column_default", "udt_name"}).
|
||||
AddRow("id", "bigint", "YES", "NULL", "int8"))
|
||||
mock.ExpectQuery(escape(fmt.Sprintf(indexesQuery, "users"))).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"index_name", "column_name", "primary", "unique", "seq_in_index"}).
|
||||
AddRow("users_pkey", "id", "t", "t", 0))
|
||||
|
||||
Reference in New Issue
Block a user