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 ( // EquipmentColumns holds the columns for the "equipment" table. EquipmentColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "name", Type: field.TypeString, Unique: true, Size: 256}, {Name: "slug", Type: field.TypeString, Unique: true}, } // EquipmentTable holds the schema information for the "equipment" table. EquipmentTable = &schema.Table{ Name: "equipment", Columns: EquipmentColumns, PrimaryKey: []*schema.Column{EquipmentColumns[0]}, } // IdeasColumns holds the columns for the "ideas" table. IdeasColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "text", Type: field.TypeString}, {Name: "recipe_ideas", Type: field.TypeUUID, Nullable: true}, } // IdeasTable holds the schema information for the "ideas" table. IdeasTable = &schema.Table{ Name: "ideas", Columns: IdeasColumns, PrimaryKey: []*schema.Column{IdeasColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "ideas_recipes_ideas", Columns: []*schema.Column{IdeasColumns[2]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.SetNull, }, }, } // IngredientsColumns holds the columns for the "ingredients" table. IngredientsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "create_time", Type: field.TypeTime}, {Name: "update_time", Type: field.TypeTime}, {Name: "quantity", Type: field.TypeString, Nullable: true}, {Name: "unit", Type: field.TypeString, Nullable: true}, {Name: "optional", Type: field.TypeBool, Default: false}, {Name: "recipe_id", Type: field.TypeUUID}, {Name: "product_id", Type: field.TypeUUID}, } // IngredientsTable holds the schema information for the "ingredients" table. IngredientsTable = &schema.Table{ Name: "ingredients", Columns: IngredientsColumns, PrimaryKey: []*schema.Column{IngredientsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "ingredients_recipes_recipe", Columns: []*schema.Column{IngredientsColumns[6]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "ingredients_products_product", Columns: []*schema.Column{IngredientsColumns[7]}, RefColumns: []*schema.Column{ProductsColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "ingredient_recipe_id_product_id", Unique: true, Columns: []*schema.Column{IngredientsColumns[6], IngredientsColumns[7]}, }, }, } // InstructionsColumns holds the columns for the "instructions" table. InstructionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "text", Type: field.TypeString}, {Name: "order", Type: field.TypeInt}, {Name: "recipe_instructions", Type: field.TypeUUID, Nullable: true}, } // InstructionsTable holds the schema information for the "instructions" table. InstructionsTable = &schema.Table{ Name: "instructions", Columns: InstructionsColumns, PrimaryKey: []*schema.Column{InstructionsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "instructions_recipes_instructions", Columns: []*schema.Column{InstructionsColumns[3]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.SetNull, }, }, Indexes: []*schema.Index{ { Name: "instruction_order_recipe_instructions", Unique: true, Columns: []*schema.Column{InstructionsColumns[2], InstructionsColumns[3]}, }, }, } // NutritionsColumns holds the columns for the "nutritions" table. NutritionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "calories", Type: field.TypeInt, Nullable: true}, {Name: "fat", Type: field.TypeInt, Nullable: true}, {Name: "carbs", Type: field.TypeInt, Nullable: true}, {Name: "protein", Type: field.TypeInt, Nullable: true}, {Name: "precision", Type: field.TypeString, Nullable: true}, {Name: "benefits", Type: field.TypeJSON, Nullable: true}, {Name: "recipe_nutrition", Type: field.TypeUUID, Unique: true, Nullable: true}, } // NutritionsTable holds the schema information for the "nutritions" table. NutritionsTable = &schema.Table{ Name: "nutritions", Columns: NutritionsColumns, PrimaryKey: []*schema.Column{NutritionsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "nutritions_recipes_nutrition", Columns: []*schema.Column{NutritionsColumns[7]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.SetNull, }, }, } // ProductsColumns holds the columns for the "products" table. ProductsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "create_time", Type: field.TypeTime}, {Name: "update_time", Type: field.TypeTime}, {Name: "locale", Type: field.TypeEnum, Enums: []string{"en", "ru"}, Default: "ru"}, {Name: "name", Type: field.TypeString, Unique: true, Size: 256}, {Name: "slug", Type: field.TypeString, Unique: true}, } // ProductsTable holds the schema information for the "products" table. ProductsTable = &schema.Table{ Name: "products", Columns: ProductsColumns, PrimaryKey: []*schema.Column{ProductsColumns[0]}, } // RecipesColumns holds the columns for the "recipes" table. RecipesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "create_time", Type: field.TypeTime}, {Name: "update_time", Type: field.TypeTime}, {Name: "locale", Type: field.TypeEnum, Enums: []string{"en", "ru"}, Default: "ru"}, {Name: "name", Type: field.TypeString, Unique: true}, {Name: "slug", Type: field.TypeString, Unique: true}, {Name: "description", Type: field.TypeString}, {Name: "text", Type: field.TypeString}, {Name: "rating", Type: field.TypeFloat32, Nullable: true}, {Name: "servings", Type: field.TypeInt, Nullable: true}, {Name: "time", Type: field.TypeInt64, Nullable: true}, {Name: "published", Type: field.TypeBool, Default: false}, } // RecipesTable holds the schema information for the "recipes" table. RecipesTable = &schema.Table{ Name: "recipes", Columns: RecipesColumns, PrimaryKey: []*schema.Column{RecipesColumns[0]}, Indexes: []*schema.Index{ { Name: "recipe_create_time", Unique: false, Columns: []*schema.Column{RecipesColumns[1]}, }, }, } // SourcesColumns holds the columns for the "sources" table. SourcesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "description", Type: field.TypeString, Nullable: true}, {Name: "url", Type: field.TypeString, Nullable: true}, {Name: "recipe_sources", Type: field.TypeUUID, Nullable: true}, } // SourcesTable holds the schema information for the "sources" table. SourcesTable = &schema.Table{ Name: "sources", Columns: SourcesColumns, PrimaryKey: []*schema.Column{SourcesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "sources_recipes_sources", Columns: []*schema.Column{SourcesColumns[4]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.SetNull, }, }, } // TagsColumns holds the columns for the "tags" table. TagsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "name", Type: field.TypeString, Unique: true, Size: 128}, {Name: "group", Type: field.TypeString, Size: 128}, {Name: "slug", Type: field.TypeString, Unique: true}, } // TagsTable holds the schema information for the "tags" table. TagsTable = &schema.Table{ Name: "tags", Columns: TagsColumns, PrimaryKey: []*schema.Column{TagsColumns[0]}, Indexes: []*schema.Index{ { Name: "tag_name_group", Unique: true, Columns: []*schema.Column{TagsColumns[1], TagsColumns[2]}, }, }, } // RecipeTagsColumns holds the columns for the "recipe_tags" table. RecipeTagsColumns = []*schema.Column{ {Name: "recipe_id", Type: field.TypeUUID}, {Name: "tag_id", Type: field.TypeUUID}, } // 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_tag_id", Columns: []*schema.Column{RecipeTagsColumns[1]}, RefColumns: []*schema.Column{TagsColumns[0]}, OnDelete: schema.Cascade, }, }, } // RecipeEquipmentColumns holds the columns for the "recipe_equipment" table. RecipeEquipmentColumns = []*schema.Column{ {Name: "recipe_id", Type: field.TypeUUID}, {Name: "equipment_id", Type: field.TypeUUID}, } // RecipeEquipmentTable holds the schema information for the "recipe_equipment" table. RecipeEquipmentTable = &schema.Table{ Name: "recipe_equipment", Columns: RecipeEquipmentColumns, PrimaryKey: []*schema.Column{RecipeEquipmentColumns[0], RecipeEquipmentColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "recipe_equipment_recipe_id", Columns: []*schema.Column{RecipeEquipmentColumns[0]}, RefColumns: []*schema.Column{RecipesColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "recipe_equipment_equipment_id", Columns: []*schema.Column{RecipeEquipmentColumns[1]}, RefColumns: []*schema.Column{EquipmentColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ EquipmentTable, IdeasTable, IngredientsTable, InstructionsTable, NutritionsTable, ProductsTable, RecipesTable, SourcesTable, TagsTable, RecipeTagsTable, RecipeEquipmentTable, } )
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.