using Microsoft.EntityFrameworkCore.Migrations; using MySql.EntityFrameworkCore.Metadata; #nullable disable namespace API.Migrations { /// public partial class RecipeModelAdded : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "PrefereredRecipesId", table: "Users", type: "int", nullable: false, defaultValue: 0); migrationBuilder.CreateTable( name: "PrefereredRecipes", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn) }, constraints: table => { table.PrimaryKey("PK_PrefereredRecipes", x => x.Id); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Recipes", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), Name = table.Column(type: "longtext", nullable: false), Description = table.Column(type: "longtext", nullable: false), Directions = table.Column(type: "longtext", nullable: false), PrefereredRecipesId = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Recipes", x => x.Id); table.ForeignKey( name: "FK_Recipes_PrefereredRecipes_PrefereredRecipesId", column: x => x.PrefereredRecipesId, principalTable: "PrefereredRecipes", principalColumn: "Id"); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateTable( name: "Ingredient", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), Amount = table.Column(type: "int", nullable: false), Unit = table.Column(type: "longtext", nullable: false), Element = table.Column(type: "longtext", nullable: false), RecipeId = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Ingredient", x => x.Id); table.ForeignKey( name: "FK_Ingredient_Recipes_RecipeId", column: x => x.RecipeId, principalTable: "Recipes", principalColumn: "Id"); }) .Annotation("MySQL:Charset", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Users_PrefereredRecipesId", table: "Users", column: "PrefereredRecipesId"); migrationBuilder.CreateIndex( name: "IX_Ingredient_RecipeId", table: "Ingredient", column: "RecipeId"); migrationBuilder.CreateIndex( name: "IX_Recipes_PrefereredRecipesId", table: "Recipes", column: "PrefereredRecipesId"); migrationBuilder.AddForeignKey( name: "FK_Users_PrefereredRecipes_PrefereredRecipesId", table: "Users", column: "PrefereredRecipesId", principalTable: "PrefereredRecipes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Users_PrefereredRecipes_PrefereredRecipesId", table: "Users"); migrationBuilder.DropTable( name: "Ingredient"); migrationBuilder.DropTable( name: "Recipes"); migrationBuilder.DropTable( name: "PrefereredRecipes"); migrationBuilder.DropIndex( name: "IX_Users_PrefereredRecipesId", table: "Users"); migrationBuilder.DropColumn( name: "PrefereredRecipesId", table: "Users"); } } }