Files
Francescos.Recipes.World/Francesco.Recipes.World/Migrations/20250114131454_InitialMigration.cs
T

185 lines
7.3 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Francesco.Recipes.World.Migrations
{
/// <inheritdoc />
public partial class InitialMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
if (migrationBuilder == null)
{
throw new ArgumentNullException(nameof(migrationBuilder));
}
migrationBuilder.CreateTable(
name: "Categories",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Categories", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Unit",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Unit", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Recipes",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Difficulty = table.Column<string>(type: "nvarchar(max)", nullable: false),
Servings = table.Column<int>(type: "int", nullable: false),
PreparationTime = table.Column<TimeSpan>(type: "time", nullable: false),
CookingTime = table.Column<TimeSpan>(type: "time", nullable: false),
CategoryId = table.Column<Guid>(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<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Quantity = table.Column<int>(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<Guid>(type: "uniqueidentifier", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Number = table.Column<string>(type: "nvarchar(max)", nullable: false),
RecipeId = table.Column<Guid>(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<Guid>(type: "uniqueidentifier", nullable: false),
RecipeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
IngredientId = table.Column<Guid>(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");
}
/// <inheritdoc />
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");
}
}
}