easyeat/backend/API/Migrations/20250428070005_RecipeModelAdded.cs
2025-04-28 09:00:30 +02:00

128 lines
4.9 KiB
C#

using Microsoft.EntityFrameworkCore.Migrations;
using MySql.EntityFrameworkCore.Metadata;
#nullable disable
namespace API.Migrations
{
/// <inheritdoc />
public partial class RecipeModelAdded : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "PrefereredRecipesId",
table: "Users",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "PrefereredRecipes",
columns: table => new
{
Id = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(type: "longtext", nullable: false),
Description = table.Column<string>(type: "longtext", nullable: false),
Directions = table.Column<string>(type: "longtext", nullable: false),
PrefereredRecipesId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
Amount = table.Column<int>(type: "int", nullable: false),
Unit = table.Column<string>(type: "longtext", nullable: false),
Element = table.Column<string>(type: "longtext", nullable: false),
RecipeId = table.Column<int>(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);
}
/// <inheritdoc />
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");
}
}
}