using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace backend.Migrations
{
///
public partial class InitialCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "CheckedShoppingItems",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
MealPlanId = table.Column(type: "uuid", nullable: false),
ItemName = table.Column(type: "text", nullable: false),
UserId = table.Column(type: "text", nullable: false),
IsChecked = table.Column(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CheckedShoppingItems", x => x.Id);
});
migrationBuilder.CreateTable(
name: "MealPlans",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
UserId = table.Column(type: "text", nullable: false),
WeekStart = table.Column(type: "date", nullable: false),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MealPlans", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Recipes",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
UserId = table.Column(type: "text", nullable: true),
ExternalId = table.Column(type: "text", nullable: true),
Title = table.Column(type: "text", nullable: false),
Instructions = table.Column(type: "text", nullable: false),
ImageUrl = table.Column(type: "text", nullable: true),
Source = table.Column(type: "integer", nullable: false),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Recipes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "UserSettings",
columns: table => new
{
UserId = table.Column(type: "text", nullable: false),
HouseholdSize = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserSettings", x => x.UserId);
});
migrationBuilder.CreateTable(
name: "MealPlanEntries",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
MealPlanId = table.Column(type: "uuid", nullable: false),
Date = table.Column(type: "date", nullable: false),
RecipeId = table.Column(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MealPlanEntries", x => x.Id);
table.ForeignKey(
name: "FK_MealPlanEntries_MealPlans_MealPlanId",
column: x => x.MealPlanId,
principalTable: "MealPlans",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MealPlanEntries_Recipes_RecipeId",
column: x => x.RecipeId,
principalTable: "Recipes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "RecipeIngredients",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
RecipeId = table.Column(type: "uuid", nullable: false),
Name = table.Column(type: "text", nullable: false),
Amount = table.Column(type: "numeric", nullable: true),
Unit = table.Column(type: "text", nullable: true),
Category = table.Column(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RecipeIngredients", x => x.Id);
table.ForeignKey(
name: "FK_RecipeIngredients_Recipes_RecipeId",
column: x => x.RecipeId,
principalTable: "Recipes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_CheckedShoppingItems_MealPlanId_UserId_ItemName",
table: "CheckedShoppingItems",
columns: new[] { "MealPlanId", "UserId", "ItemName" });
migrationBuilder.CreateIndex(
name: "IX_MealPlanEntries_MealPlanId",
table: "MealPlanEntries",
column: "MealPlanId");
migrationBuilder.CreateIndex(
name: "IX_MealPlanEntries_RecipeId",
table: "MealPlanEntries",
column: "RecipeId");
migrationBuilder.CreateIndex(
name: "IX_MealPlans_UserId_WeekStart",
table: "MealPlans",
columns: new[] { "UserId", "WeekStart" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_RecipeIngredients_RecipeId",
table: "RecipeIngredients",
column: "RecipeId");
migrationBuilder.CreateIndex(
name: "IX_Recipes_ExternalId",
table: "Recipes",
column: "ExternalId");
migrationBuilder.CreateIndex(
name: "IX_Recipes_UserId",
table: "Recipes",
column: "UserId");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CheckedShoppingItems");
migrationBuilder.DropTable(
name: "MealPlanEntries");
migrationBuilder.DropTable(
name: "RecipeIngredients");
migrationBuilder.DropTable(
name: "UserSettings");
migrationBuilder.DropTable(
name: "MealPlans");
migrationBuilder.DropTable(
name: "Recipes");
}
}
}