mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Summary: Used addlicense to generate this: addlicense -c "Facebook Inc" -f license_header . example was taken from: https://github.com/facebook/litho/blob/master/lib/soloader/BUCK Reviewed By: alexsn Differential Revision: D17070152 fbshipit-source-id: e7b91398d7f6181727be3400c1872ad5f28e38ed
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
package schema
|
|
|
|
import (
|
|
"github.com/facebookincubator/ent"
|
|
"github.com/facebookincubator/ent/schema/field"
|
|
"github.com/facebookincubator/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 }
|
|
)
|