Files
ent/entc/integration/migrate/entv2/schema/user.go
Ariel Mashraki c16d3c8e25 ent/schema: explicitly defines non-null fields in schema
Reviewed By: alexsn

Differential Revision: D16791620

fbshipit-source-id: bad3ac7b2349d2f483c804eb3623c6dfa8b06313
2019-08-15 03:37:17 -07:00

50 lines
1015 B
Go

package schema
import (
"fbc/ent"
"fbc/ent/schema/field"
"fbc/ent/schema/index"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
// changing the type of the field.
field.Int("age"),
// extending name field to longtext.
field.Text("name"),
// adding new columns.
field.String("phone"),
field.Bytes("buffer").
Default([]byte("{}")),
// adding new column with supported default value
// in the database side, will append this value to
// all existing rows.
field.String("title").
Default("SWE"),
// deleting the `address` column.
}
}
func (User) Indexes() []ent.Index {
return []ent.Index{
// deleting old indexes (name, address),
// and defining a new one.
index.Fields("phone", "age").
Unique(),
}
}
// Additional types to be added to the schema.
type (
// Pet schema.
Pet struct{ ent.Schema }
// Group schema.
Group struct{ ent.Schema }
)