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 // WithFixture sets the foreign-key renaming option to the migration when upgrading // ent from v0.1.0 (issue-#285). Defaults to false. WithFixture = schema.WithFixture // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. WithForeignKeys = schema.WithForeignKeys )
View Source
var ( // CategoriesColumns holds the columns for the "categories" table. CategoriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, } // CategoriesTable holds the schema information for the "categories" table. CategoriesTable = &schema.Table{ Name: "categories", Columns: CategoriesColumns, PrimaryKey: []*schema.Column{CategoriesColumns[0]}, } // IngredientsColumns holds the columns for the "ingredients" table. IngredientsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, } // IngredientsTable holds the schema information for the "ingredients" table. IngredientsTable = &schema.Table{ Name: "ingredients", Columns: IngredientsColumns, PrimaryKey: []*schema.Column{IngredientsColumns[0]}, } // RecipesColumns holds the columns for the "recipes" table. RecipesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, {Name: "servings", Type: field.TypeInt}, {Name: "user_recipes", Type: field.TypeInt, Nullable: true}, } // RecipesTable holds the schema information for the "recipes" table. RecipesTable = &schema.Table{ Name: "recipes", Columns: RecipesColumns, PrimaryKey: []*schema.Column{RecipesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "recipes_users_recipes", Columns: []*schema.Column{RecipesColumns[3]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, }, } // RecipeIngredientsColumns holds the columns for the "recipe_ingredients" table. RecipeIngredientsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "quantity", Type: field.TypeFloat32}, {Name: "unit", Type: field.TypeString}, {Name: "ingredient_recipe_ingredients", Type: field.TypeInt, Nullable: true}, {Name: "recipe_recipe_ingredients", Type: field.TypeInt, Nullable: true}, } // RecipeIngredientsTable holds the schema information for the "recipe_ingredients" table. RecipeIngredientsTable = &schema.Table{ Name: "recipe_ingredients", Columns: RecipeIngredientsColumns, PrimaryKey: []*schema.Column{RecipeIngredientsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "recipe_ingredients_ingredients_recipe_ingredients", Columns: []*schema.Column{RecipeIngredientsColumns[3]}, RefColumns: []*schema.Column{IngredientsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "recipe_ingredients_recipes_recipe_ingredients", Columns: []*schema.Column{RecipeIngredientsColumns[4]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.SetNull, }, }, } // StepsColumns holds the columns for the "steps" table. StepsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "text", Type: field.TypeString}, {Name: "recipe_steps", Type: field.TypeInt, Nullable: true}, } // StepsTable holds the schema information for the "steps" table. StepsTable = &schema.Table{ Name: "steps", Columns: StepsColumns, PrimaryKey: []*schema.Column{StepsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "steps_recipes_steps", Columns: []*schema.Column{StepsColumns[2]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.SetNull, }, }, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, } // RecipeTagsColumns holds the columns for the "recipe_tags" table. RecipeTagsColumns = []*schema.Column{ {Name: "recipe_id", Type: field.TypeInt}, {Name: "category_id", Type: field.TypeInt}, } // RecipeTagsTable holds the schema information for the "recipe_tags" table. RecipeTagsTable = &schema.Table{ Name: "recipe_tags", Columns: RecipeTagsColumns, PrimaryKey: []*schema.Column{RecipeTagsColumns[0], RecipeTagsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "recipe_tags_recipe_id", Columns: []*schema.Column{RecipeTagsColumns[0]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "recipe_tags_category_id", Columns: []*schema.Column{RecipeTagsColumns[1]}, RefColumns: []*schema.Column{CategoriesColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ CategoriesTable, IngredientsTable, RecipesTable, RecipeIngredientsTable, StepsTable, UsersTable, RecipeTagsTable, } )
Functions ¶
This section is empty.
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.