PIAPS_CW/DatabaseImplement/Migrations/20240718212855_purchaseitems.cs

89 lines
3.1 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class purchaseitems : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PurchaseProducts");
migrationBuilder.AddColumn<Guid>(
name: "PurchaseId",
table: "CartItems",
type: "uuid",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_CartItems_PurchaseId",
table: "CartItems",
column: "PurchaseId");
migrationBuilder.AddForeignKey(
name: "FK_CartItems_Purchases_PurchaseId",
table: "CartItems",
column: "PurchaseId",
principalTable: "Purchases",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CartItems_Purchases_PurchaseId",
table: "CartItems");
migrationBuilder.DropIndex(
name: "IX_CartItems_PurchaseId",
table: "CartItems");
migrationBuilder.DropColumn(
name: "PurchaseId",
table: "CartItems");
migrationBuilder.CreateTable(
name: "PurchaseProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
PurchaseId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchaseProducts", x => x.Id);
table.ForeignKey(
name: "FK_PurchaseProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchaseProducts_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_ProductId",
table: "PurchaseProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_PurchaseId",
table: "PurchaseProducts",
column: "PurchaseId");
}
}
}