Documentation
¶
Index ¶
- Variables
- func Create(ctx context.Context, s *Schema, tables []*schema.Table, ...) error
- func Diff(ctx context.Context, url string, opts ...schema.MigrateOption) error
- func NamedDiff(ctx context.Context, url, name string, opts ...schema.MigrateOption) error
- type Schema
- func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error
- func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error
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 ( // AdminsColumns holds the columns for the "admins" table. AdminsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "is_enable", Type: field.TypeBool, Default: true}, {Name: "deleted_at", Type: field.TypeInt, Default: "0"}, {Name: "username", Type: field.TypeString, Unique: true}, {Name: "password", Type: field.TypeString}, {Name: "whitelist_ips", Type: field.TypeJSON}, {Name: "display_name", Type: field.TypeString, Nullable: true}, } // AdminsTable holds the schema information for the "admins" table. AdminsTable = &schema.Table{ Name: "admins", Columns: AdminsColumns, PrimaryKey: []*schema.Column{AdminsColumns[0]}, Indexes: []*schema.Index{ { Name: "admin_deleted_at", Unique: false, Columns: []*schema.Column{AdminsColumns[4]}, }, { Name: "admin_username_deleted_at", Unique: true, Columns: []*schema.Column{AdminsColumns[5], AdminsColumns[4]}, }, }, } // PermissionsColumns holds the columns for the "permissions" table. PermissionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "group", Type: field.TypeString}, {Name: "name", Type: field.TypeString}, {Name: "key", Type: field.TypeString}, {Name: "order", Type: field.TypeInt}, } // PermissionsTable holds the schema information for the "permissions" table. PermissionsTable = &schema.Table{ Name: "permissions", Columns: PermissionsColumns, PrimaryKey: []*schema.Column{PermissionsColumns[0]}, } // RolesColumns holds the columns for the "roles" table. RolesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "is_enable", Type: field.TypeBool, Default: true}, {Name: "deleted_at", Type: field.TypeInt, Default: "0"}, {Name: "name", Type: field.TypeString}, {Name: "description", Type: field.TypeString}, {Name: "order", Type: field.TypeInt}, {Name: "is_changeable", Type: field.TypeBool}, } // RolesTable holds the schema information for the "roles" table. RolesTable = &schema.Table{ Name: "roles", Columns: RolesColumns, PrimaryKey: []*schema.Column{RolesColumns[0]}, Indexes: []*schema.Index{ { Name: "role_deleted_at", Unique: false, Columns: []*schema.Column{RolesColumns[4]}, }, }, } // RoutesColumns holds the columns for the "routes" table. RoutesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "is_enable", Type: field.TypeBool, Default: true}, {Name: "deleted_at", Type: field.TypeInt, Default: "0"}, {Name: "path", Type: field.TypeString}, {Name: "component", Type: field.TypeString}, {Name: "redirect", Type: field.TypeString, Nullable: true}, {Name: "name", Type: field.TypeString}, {Name: "type", Type: field.TypeEnum, Enums: []string{"cata_log", "menu", "button", "external_link"}, Default: "cata_log"}, {Name: "meta", Type: field.TypeJSON}, {Name: "parent_id", Type: field.TypeInt, Nullable: true}, } // RoutesTable holds the schema information for the "routes" table. RoutesTable = &schema.Table{ Name: "routes", Columns: RoutesColumns, PrimaryKey: []*schema.Column{RoutesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "routes_routes_children", Columns: []*schema.Column{RoutesColumns[11]}, RefColumns: []*schema.Column{RoutesColumns[0]}, OnDelete: schema.SetNull, }, }, Indexes: []*schema.Index{ { Name: "route_deleted_at", Unique: false, Columns: []*schema.Column{RoutesColumns[4]}, }, }, } // AdminRolesColumns holds the columns for the "admin_roles" table. AdminRolesColumns = []*schema.Column{ {Name: "admin_id", Type: field.TypeInt}, {Name: "role_id", Type: field.TypeInt}, } // AdminRolesTable holds the schema information for the "admin_roles" table. AdminRolesTable = &schema.Table{ Name: "admin_roles", Columns: AdminRolesColumns, PrimaryKey: []*schema.Column{AdminRolesColumns[0], AdminRolesColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "admin_roles_admin_id", Columns: []*schema.Column{AdminRolesColumns[0]}, RefColumns: []*schema.Column{AdminsColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "admin_roles_role_id", Columns: []*schema.Column{AdminRolesColumns[1]}, RefColumns: []*schema.Column{RolesColumns[0]}, OnDelete: schema.Cascade, }, }, } // RolePermissionsColumns holds the columns for the "role_permissions" table. RolePermissionsColumns = []*schema.Column{ {Name: "role_id", Type: field.TypeInt}, {Name: "permission_id", Type: field.TypeInt}, } // RolePermissionsTable holds the schema information for the "role_permissions" table. RolePermissionsTable = &schema.Table{ Name: "role_permissions", Columns: RolePermissionsColumns, PrimaryKey: []*schema.Column{RolePermissionsColumns[0], RolePermissionsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "role_permissions_role_id", Columns: []*schema.Column{RolePermissionsColumns[0]}, RefColumns: []*schema.Column{RolesColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "role_permissions_permission_id", Columns: []*schema.Column{RolePermissionsColumns[1]}, RefColumns: []*schema.Column{PermissionsColumns[0]}, OnDelete: schema.Cascade, }, }, } // RoleRoutesColumns holds the columns for the "role_routes" table. RoleRoutesColumns = []*schema.Column{ {Name: "role_id", Type: field.TypeInt}, {Name: "route_id", Type: field.TypeInt}, } // RoleRoutesTable holds the schema information for the "role_routes" table. RoleRoutesTable = &schema.Table{ Name: "role_routes", Columns: RoleRoutesColumns, PrimaryKey: []*schema.Column{RoleRoutesColumns[0], RoleRoutesColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "role_routes_role_id", Columns: []*schema.Column{RoleRoutesColumns[0]}, RefColumns: []*schema.Column{RolesColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "role_routes_route_id", Columns: []*schema.Column{RoleRoutesColumns[1]}, RefColumns: []*schema.Column{RoutesColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ AdminsTable, PermissionsTable, RolesTable, RoutesTable, AdminRolesTable, RolePermissionsTable, RoleRoutesTable, } )
Functions ¶
func Create ¶
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error
Create creates all table resources using the given schema driver.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
func (*Schema) Diff ¶
Diff creates a migration file containing the statements to resolve the diff between the Ent schema and the connected database.
func (*Schema) NamedDiff ¶
NamedDiff creates a named migration file containing the statements to resolve the diff between the Ent schema and the connected database.
Click to show internal directories.
Click to hide internal directories.