Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // WithGlobalUniqueID sets the universal ids options to the migration. // If this option is enabled, ent migration will allocate a 1<<32 range // for the ids of each entity (table). // Note that this option cannot be applied on tables that already exist. WithGlobalUniqueID = schema.WithGlobalUniqueID // WithDropColumn sets the drop column option to the migration. // If this option is enabled, ent migration will drop old columns // that were used for both fields and edges. This defaults to false. WithDropColumn = schema.WithDropColumn // WithDropIndex sets the drop index option to the migration. // If this option is enabled, ent migration will drop old indexes // that were defined in the schema. This defaults to false. // Note that unique constraints are defined using `UNIQUE INDEX`, // and therefore, it's recommended to enable this option to get more // flexibility in the schema changes. WithDropIndex = schema.WithDropIndex // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. WithForeignKeys = schema.WithForeignKeys )
View Source
var ( // PostsColumns holds the columns for the "posts" table. PostsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "title", Type: field.TypeString}, {Name: "published", Type: field.TypeBool, Default: false}, {Name: "user_posts", Type: field.TypeInt, Nullable: true}, } // PostsTable holds the schema information for the "posts" table. PostsTable = &schema.Table{ Name: "posts", Columns: PostsColumns, PrimaryKey: []*schema.Column{PostsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "posts_users_posts", Columns: []*schema.Column{PostsColumns[3]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, }, } // TagsColumns holds the columns for the "tags" table. TagsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, } // TagsTable holds the schema information for the "tags" table. TagsTable = &schema.Table{ Name: "tags", Columns: TagsColumns, PrimaryKey: []*schema.Column{TagsColumns[0]}, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, {Name: "bio", Type: field.TypeString, Nullable: true}, {Name: "status", Type: field.TypeEnum, Enums: []string{"active", "inactive"}, Default: "active"}, {Name: "created_at", Type: field.TypeTime}, {Name: "username", Type: field.TypeString}, {Name: "score", Type: field.TypeInt, Nullable: true}, {Name: "external_id", Type: field.TypeUUID}, {Name: "updated_at", Type: field.TypeTime, Nullable: true}, {Name: "settings", Type: field.TypeJSON, Nullable: true}, {Name: "labels", Type: field.TypeJSON}, {Name: "tag_names", Type: field.TypeJSON}, {Name: "metadata", Type: field.TypeJSON}, {Name: "user_pinned_post", Type: field.TypeInt, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "users_posts_pinned_post", Columns: []*schema.Column{UsersColumns[13]}, RefColumns: []*schema.Column{PostsColumns[0]}, OnDelete: schema.SetNull, }, }, } // UserTagsColumns holds the columns for the "user_tags" table. UserTagsColumns = []*schema.Column{ {Name: "user_id", Type: field.TypeInt}, {Name: "tag_id", Type: field.TypeInt}, } // UserTagsTable holds the schema information for the "user_tags" table. UserTagsTable = &schema.Table{ Name: "user_tags", Columns: UserTagsColumns, PrimaryKey: []*schema.Column{UserTagsColumns[0], UserTagsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "user_tags_user_id", Columns: []*schema.Column{UserTagsColumns[0]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "user_tags_tag_id", Columns: []*schema.Column{UserTagsColumns[1]}, RefColumns: []*schema.Column{TagsColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ PostsTable, TagsTable, UsersTable, UserTagsTable, } )
Functions ¶
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
Click to show internal directories.
Click to hide internal directories.