using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace API.Migrations { /// public partial class RecipeModelAdded : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterColumn( name: "UserName", table: "Users", type: "TEXT", nullable: false, oldClrType: typeof(string), oldType: "longtext"); migrationBuilder.AlterColumn( name: "Salt", table: "Users", type: "TEXT", nullable: true, oldClrType: typeof(string), oldType: "longtext", oldNullable: true); migrationBuilder.AlterColumn( name: "RefreshTokenExpireAt", table: "Users", type: "TEXT", nullable: false, oldClrType: typeof(DateTime), oldType: "datetime(6)"); migrationBuilder.AlterColumn( name: "RefreshToken", table: "Users", type: "TEXT", nullable: true, oldClrType: typeof(string), oldType: "longtext", oldNullable: true); migrationBuilder.AlterColumn( name: "Password", table: "Users", type: "TEXT", nullable: false, oldClrType: typeof(string), oldType: "longtext"); migrationBuilder.AlterColumn( name: "Email", table: "Users", type: "TEXT", nullable: false, oldClrType: typeof(string), oldType: "longtext"); migrationBuilder.AlterColumn( name: "Id", table: "Users", type: "INTEGER", nullable: false, oldClrType: typeof(int), oldType: "int") .Annotation("Sqlite:Autoincrement", true) .OldAnnotation("Sqlite:Autoincrement", true); migrationBuilder.AddColumn( name: "PrefereredRecipesId", table: "Users", type: "INTEGER", nullable: false, defaultValue: 0); migrationBuilder.CreateTable( name: "PrefereredRecipes", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true) }, constraints: table => { table.PrimaryKey("PK_PrefereredRecipes", x => x.Id); }); migrationBuilder.CreateTable( name: "ShoppingList", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Amount = table.Column(type: "REAL", nullable: false), Unit = table.Column(type: "TEXT", nullable: false), Name = table.Column(type: "TEXT", nullable: false), Checked = table.Column(type: "INTEGER", nullable: false), UserId = table.Column(type: "INTEGER", 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"); }); migrationBuilder.CreateTable( name: "Recipes", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Name = table.Column(type: "TEXT", nullable: false), Description = table.Column(type: "TEXT", nullable: false), Directions = table.Column(type: "TEXT", nullable: false), PrefereredRecipesId = table.Column(type: "INTEGER", 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"); }); migrationBuilder.CreateTable( name: "Ingredient", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Amount = table.Column(type: "INTEGER", nullable: false), Unit = table.Column(type: "TEXT", nullable: false), Element = table.Column(type: "TEXT", nullable: false), RecipeId = table.Column(type: "INTEGER", 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"); }); 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); } /// 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"); migrationBuilder.AlterColumn( name: "UserName", table: "Users", type: "longtext", nullable: false, oldClrType: typeof(string), oldType: "TEXT"); migrationBuilder.AlterColumn( name: "Salt", table: "Users", type: "longtext", nullable: true, oldClrType: typeof(string), oldType: "TEXT", oldNullable: true); migrationBuilder.AlterColumn( name: "RefreshTokenExpireAt", table: "Users", type: "datetime(6)", nullable: false, oldClrType: typeof(DateTime), oldType: "TEXT"); migrationBuilder.AlterColumn( name: "RefreshToken", table: "Users", type: "longtext", nullable: true, oldClrType: typeof(string), oldType: "TEXT", oldNullable: true); migrationBuilder.AlterColumn( name: "Password", table: "Users", type: "longtext", nullable: false, oldClrType: typeof(string), oldType: "TEXT"); migrationBuilder.AlterColumn( name: "Email", table: "Users", type: "longtext", nullable: false, oldClrType: typeof(string), oldType: "TEXT"); migrationBuilder.AlterColumn( name: "Id", table: "Users", type: "int", nullable: false, oldClrType: typeof(int), oldType: "INTEGER") .Annotation("Sqlite:Autoincrement", true) .OldAnnotation("Sqlite:Autoincrement", true); } } }