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 ( // ChatsColumns holds the columns for the "chats" table. ChatsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "chat_id", Type: field.TypeInt64}, {Name: "type", Type: field.TypeString, Default: ""}, {Name: "is_forum", Type: field.TypeBool, Default: false}, {Name: "title", Type: field.TypeString, Default: ""}, {Name: "user_name", Type: field.TypeString, Default: ""}, {Name: "first_name", Type: field.TypeString, Default: ""}, {Name: "last_name", Type: field.TypeString, Default: ""}, {Name: "description", Type: field.TypeString, Size: 2147483647, Default: "", SchemaType: map[string]string{"mysql": "text"}}, {Name: "create_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "update_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, } // ChatsTable holds the schema information for the "chats" table. ChatsTable = &schema.Table{ Name: "chats", Columns: ChatsColumns, PrimaryKey: []*schema.Column{ChatsColumns[0]}, Indexes: []*schema.Index{ { Name: "chat_chat_id", Unique: true, Columns: []*schema.Column{ChatsColumns[1]}, }, }, } // ChatOptionsColumns holds the columns for the "chat_options" table. ChatOptionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "chat_id", Type: field.TypeInt64}, {Name: "key", Type: field.TypeString, Size: 50}, {Name: "value", Type: field.TypeString, Default: ""}, {Name: "create_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "update_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, } // ChatOptionsTable holds the schema information for the "chat_options" table. ChatOptionsTable = &schema.Table{ Name: "chat_options", Columns: ChatOptionsColumns, PrimaryKey: []*schema.Column{ChatOptionsColumns[0]}, Indexes: []*schema.Index{ { Name: "chatoption_chat_id_key", Unique: true, Columns: []*schema.Column{ChatOptionsColumns[1], ChatOptionsColumns[2]}, }, }, } // GameAccountsColumns holds the columns for the "game_accounts" table. GameAccountsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "user_id", Type: field.TypeInt64}, {Name: "account_id", Type: field.TypeString, Size: 30}, {Name: "game_token", Type: field.TypeString, Size: 100, Default: ""}, {Name: "cookie_token", Type: field.TypeString, Size: 100, Default: ""}, {Name: "stoken", Type: field.TypeString, Default: ""}, {Name: "mid", Type: field.TypeString, Size: 50, Default: ""}, {Name: "create_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "update_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, } // GameAccountsTable holds the schema information for the "game_accounts" table. GameAccountsTable = &schema.Table{ Name: "game_accounts", Columns: GameAccountsColumns, PrimaryKey: []*schema.Column{GameAccountsColumns[0]}, Indexes: []*schema.Index{ { Name: "gameaccount_user_id_account_id", Unique: true, Columns: []*schema.Column{GameAccountsColumns[1], GameAccountsColumns[2]}, }, { Name: "gameaccount_account_id", Unique: false, Columns: []*schema.Column{GameAccountsColumns[2]}, }, }, } // GameRolesColumns holds the columns for the "game_roles" table. GameRolesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "user_id", Type: field.TypeInt64}, {Name: "account_id", Type: field.TypeString, Size: 30}, {Name: "role_id", Type: field.TypeString, Size: 30}, {Name: "level", Type: field.TypeInt, Default: 0}, {Name: "region", Type: field.TypeString, Size: 30, Default: ""}, {Name: "region_name", Type: field.TypeString, Size: 30, Default: ""}, {Name: "nick_name", Type: field.TypeString, Size: 100, Default: ""}, {Name: "create_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "update_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, } // GameRolesTable holds the schema information for the "game_roles" table. GameRolesTable = &schema.Table{ Name: "game_roles", Columns: GameRolesColumns, PrimaryKey: []*schema.Column{GameRolesColumns[0]}, Indexes: []*schema.Index{ { Name: "gamerole_user_id_account_id_role_id", Unique: true, Columns: []*schema.Column{GameRolesColumns[1], GameRolesColumns[2], GameRolesColumns[3]}, }, { Name: "gamerole_account_id", Unique: false, Columns: []*schema.Column{GameRolesColumns[2]}, }, { Name: "gamerole_role_id", Unique: false, Columns: []*schema.Column{GameRolesColumns[3]}, }, { Name: "gamerole_region", Unique: false, Columns: []*schema.Column{GameRolesColumns[5]}, }, }, } // GameRoleAttributesColumns holds the columns for the "game_role_attributes" table. GameRoleAttributesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "user_id", Type: field.TypeInt64}, {Name: "account_id", Type: field.TypeString, Size: 30}, {Name: "role_id", Type: field.TypeString, Size: 30}, {Name: "name", Type: field.TypeString, Size: 100}, {Name: "type", Type: field.TypeInt, Default: 0}, {Name: "value", Type: field.TypeString, Default: ""}, {Name: "create_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "update_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, } // GameRoleAttributesTable holds the schema information for the "game_role_attributes" table. GameRoleAttributesTable = &schema.Table{ Name: "game_role_attributes", Columns: GameRoleAttributesColumns, PrimaryKey: []*schema.Column{GameRoleAttributesColumns[0]}, Indexes: []*schema.Index{ { Name: "gameroleattribute_user_id_account_id_role_id_name", Unique: true, Columns: []*schema.Column{GameRoleAttributesColumns[1], GameRoleAttributesColumns[2], GameRoleAttributesColumns[3], GameRoleAttributesColumns[4]}, }, { Name: "gameroleattribute_account_id", Unique: false, Columns: []*schema.Column{GameRoleAttributesColumns[2]}, }, { Name: "gameroleattribute_role_id", Unique: false, Columns: []*schema.Column{GameRoleAttributesColumns[3]}, }, { Name: "gameroleattribute_name", Unique: false, Columns: []*schema.Column{GameRoleAttributesColumns[4]}, }, }, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "user_id", Type: field.TypeInt64}, {Name: "is_bot", Type: field.TypeBool, Default: false}, {Name: "user_name", Type: field.TypeString, Default: ""}, {Name: "first_name", Type: field.TypeString, Default: ""}, {Name: "last_name", Type: field.TypeString, Default: ""}, {Name: "create_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, {Name: "update_at", Type: field.TypeTime, SchemaType: map[string]string{"mysql": "datetime"}}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, Indexes: []*schema.Index{ { Name: "user_user_id", Unique: true, Columns: []*schema.Column{UsersColumns[1]}, }, { Name: "user_user_name", Unique: false, Columns: []*schema.Column{UsersColumns[3]}, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ ChatsTable, ChatOptionsTable, GameAccountsTable, GameRolesTable, GameRoleAttributesTable, UsersTable, } )
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.