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 ( // FilesColumns holds the columns for the "files" table. FilesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString, Size: 64}, {Name: "uuid", Type: field.TypeString, Unique: true, Size: 64}, {Name: "size", Type: field.TypeInt}, {Name: "created_at", Type: field.TypeTime, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, {Name: "type", Type: field.TypeString, Size: 64}, {Name: "user_id", Type: field.TypeInt}, } // FilesTable holds the schema information for the "files" table. FilesTable = &schema.Table{ Name: "files", Columns: FilesColumns, PrimaryKey: []*schema.Column{FilesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "files_filetypes_files", Columns: []*schema.Column{FilesColumns[7]}, RefColumns: []*schema.Column{FiletypesColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "files_users_files", Columns: []*schema.Column{FilesColumns[8]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.NoAction, }, }, } // FiletypesColumns holds the columns for the "filetypes" table. FiletypesColumns = []*schema.Column{ {Name: "type", Type: field.TypeString, Size: 64}, {Name: "allowed_size", Type: field.TypeInt, Default: 10000000}, {Name: "is_banned", Type: field.TypeBool, Default: false}, {Name: "created_at", Type: field.TypeTime, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, } // FiletypesTable holds the schema information for the "filetypes" table. FiletypesTable = &schema.Table{ Name: "filetypes", Columns: FiletypesColumns, PrimaryKey: []*schema.Column{FiletypesColumns[0]}, } // TagsColumns holds the columns for the "tags" table. TagsColumns = []*schema.Column{ {Name: "name", Type: field.TypeString, Size: 64}, {Name: "created_at", Type: field.TypeTime, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, } // 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: "first_name", Type: field.TypeString, Size: 64}, {Name: "last_name", Type: field.TypeString, Size: 64}, {Name: "email", Type: field.TypeString, Unique: true, Nullable: true}, {Name: "password", Type: field.TypeString}, {Name: "access_type", Type: field.TypeEnum, Enums: []string{"Admin", "Customer"}, Default: "Customer"}, {Name: "created_at", Type: field.TypeTime, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, {Name: "last_login_at", Type: field.TypeTime, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, } // FileTagsColumns holds the columns for the "file_tags" table. FileTagsColumns = []*schema.Column{ {Name: "file_id", Type: field.TypeInt}, {Name: "tag_id", Type: field.TypeString, Size: 64}, } // FileTagsTable holds the schema information for the "file_tags" table. FileTagsTable = &schema.Table{ Name: "file_tags", Columns: FileTagsColumns, PrimaryKey: []*schema.Column{FileTagsColumns[0], FileTagsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "file_tags_file_id", Columns: []*schema.Column{FileTagsColumns[0]}, RefColumns: []*schema.Column{FilesColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "file_tags_tag_id", Columns: []*schema.Column{FileTagsColumns[1]}, RefColumns: []*schema.Column{TagsColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ FilesTable, FiletypesTable, TagsTable, UsersTable, FileTagsTable, } )
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.