easyeat/backend/API/Migrations/20250430091216_RecipeModelAdded.cs
2025-04-30 11:36:05 +02:00

159 lines
6.3 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: "ShoppingList",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
Amount = table.Column<double>(type: "double", nullable: false),
Unit = table.Column<string>(type: "longtext", nullable: false),
Name = table.Column<string>(type: "longtext", nullable: false),
Checked = table.Column<bool>(type: "tinyint(1)", nullable: false),
UserId = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ShoppingList", x => x.Id);
table.ForeignKey(
name: "FK_ShoppingList_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "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),
Name = 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.CreateIndex(
name: "IX_ShoppingList_UserId",
table: "ShoppingList",
column: "UserId");
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: "ShoppingList");
migrationBuilder.DropTable(
name: "Recipes");
migrationBuilder.DropTable(
name: "PrefereredRecipes");
migrationBuilder.DropIndex(
name: "IX_Users_PrefereredRecipesId",
table: "Users");
migrationBuilder.DropColumn(
name: "PrefereredRecipesId",
table: "Users");
}
}
}