mirror of
https://github.com/ent/ent.git
synced 2026-05-03 16:10:59 +03:00
dialect/sql/schema: initial support for postgres net-types (#964)
This commit is contained in:
@@ -83,6 +83,7 @@ func TestPostgres_Create(t *testing.T) {
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "inet", Type: field.TypeString, Unique: true, SchemaType: map[string]string{dialect.Postgres: "inet"}},
|
||||
}
|
||||
c2 = []*Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@@ -114,7 +115,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, "created_at" timestamp with time zone 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, "created_at" timestamp with time zone NOT NULL, "inet" inet UNIQUE NOT NULL, PRIMARY KEY("id"))`)).
|
||||
WillReturnResult(sqlmock.NewResult(0, 1))
|
||||
mock.tableExists("pets", false)
|
||||
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "pets"("id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, "name" varchar NOT NULL, "owner_id" bigint NULL, PRIMARY KEY("id"))`)).
|
||||
@@ -215,6 +216,10 @@ func TestPostgres_Create(t *testing.T) {
|
||||
{Name: "created_at", Type: field.TypeTime, SchemaType: map[string]string{dialect.Postgres: "date"}},
|
||||
{Name: "updated_at", Type: field.TypeTime, SchemaType: map[string]string{dialect.MySQL: "date"}, Nullable: true},
|
||||
{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "cidr", Type: field.TypeString, SchemaType: map[string]string{dialect.Postgres: "cidr"}},
|
||||
{Name: "inet", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{dialect.Postgres: "inet"}},
|
||||
{Name: "macaddr", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{dialect.Postgres: "macaddr"}},
|
||||
{Name: "macaddr8", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{dialect.Postgres: "macaddr8"}},
|
||||
},
|
||||
PrimaryKey: []*Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@@ -233,7 +238,11 @@ func TestPostgres_Create(t *testing.T) {
|
||||
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("text", "text", "YES", "NULL").
|
||||
AddRow("cidr", "cidr", "NO", "NULL").
|
||||
AddRow("inet", "inet", "YES", "NULL").
|
||||
AddRow("macaddr", "macaddr", "YES", "NULL").
|
||||
AddRow("macaddr8", "macaddr8", "YES", "NULL"))
|
||||
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