using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Francesco.Recipes.World.Migrations { /// public partial class InitialMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { if (migrationBuilder == null) { throw new ArgumentNullException(nameof(migrationBuilder)); } migrationBuilder.CreateTable( name: "Categories", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.Id); }); migrationBuilder.CreateTable( name: "Unit", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Unit", x => x.Id); }); migrationBuilder.CreateTable( name: "Recipes", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: false), Difficulty = table.Column(type: "nvarchar(max)", nullable: false), Servings = table.Column(type: "int", nullable: false), PreparationTime = table.Column(type: "time", nullable: false), CookingTime = table.Column(type: "time", nullable: false), CategoryId = table.Column(type: "uniqueidentifier", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Recipes", x => x.Id); table.ForeignKey( name: "FK_Recipes_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Ingredients", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Name = table.Column(type: "nvarchar(max)", nullable: false), UnitId = table.Column(type: "uniqueidentifier", nullable: false), Quantity = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Ingredients", x => x.Id); table.ForeignKey( name: "FK_Ingredients_Unit_UnitId", column: x => x.UnitId, principalTable: "Unit", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Instructions", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), Description = table.Column(type: "nvarchar(max)", nullable: false), Number = table.Column(type: "nvarchar(max)", nullable: false), RecipeId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Instructions", x => x.Id); table.ForeignKey( name: "FK_Instructions_Recipes_RecipeId", column: x => x.RecipeId, principalTable: "Recipes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RecipeIngredients", columns: table => new { Id = table.Column(type: "uniqueidentifier", nullable: false), RecipeId = table.Column(type: "uniqueidentifier", nullable: false), IngredientId = table.Column(type: "uniqueidentifier", nullable: false) }, constraints: table => { table.PrimaryKey("PK_RecipeIngredients", x => x.Id); table.ForeignKey( name: "FK_RecipeIngredients_Ingredients_IngredientId", column: x => x.IngredientId, principalTable: "Ingredients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_RecipeIngredients_Recipes_RecipeId", column: x => x.RecipeId, principalTable: "Recipes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Ingredients_UnitId", table: "Ingredients", column: "UnitId"); migrationBuilder.CreateIndex( name: "IX_Instructions_RecipeId", table: "Instructions", column: "RecipeId"); migrationBuilder.CreateIndex( name: "IX_RecipeIngredients_IngredientId", table: "RecipeIngredients", column: "IngredientId"); migrationBuilder.CreateIndex( name: "IX_RecipeIngredients_RecipeId", table: "RecipeIngredients", column: "RecipeId"); migrationBuilder.CreateIndex( name: "IX_Recipes_CategoryId", table: "Recipes", column: "CategoryId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { if (migrationBuilder == null) { throw new ArgumentNullException(nameof(migrationBuilder)); } migrationBuilder.DropTable( name: "Instructions"); migrationBuilder.DropTable( name: "RecipeIngredients"); migrationBuilder.DropTable( name: "Ingredients"); migrationBuilder.DropTable( name: "Recipes"); migrationBuilder.DropTable( name: "Unit"); migrationBuilder.DropTable( name: "Categories"); } } }