Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.EntityFrameworkCore.Migrations;
- #nullable disable
- namespace MVC_Project.Migrations
- {
- /// <inheritdoc />
- public partial class AddedOrderAndInvoiceEntities : Migration
- {
- /// <inheritdoc />
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "Invoices",
- columns: table => new
- {
- Id = table.Column<int>(type: "int", nullable: false)
- .Annotation("SqlServer:Identity", "1, 1"),
- InvoiceNumber = table.Column<string>(type: "nvarchar(max)", nullable: false),
- OrderId = table.Column<int>(type: "int", nullable: true),
- TotalPaid = table.Column<decimal>(type: "money", nullable: false),
- Currency = table.Column<string>(type: "nvarchar(max)", nullable: false),
- AddedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Invoices", x => x.Id);
- });
- migrationBuilder.CreateTable(
- name: "Orders",
- columns: table => new
- {
- Id = table.Column<int>(type: "int", nullable: false)
- .Annotation("SqlServer:Identity", "1, 1"),
- CustomerId = table.Column<int>(type: "int", nullable: false),
- AddressId = table.Column<int>(type: "int", nullable: false),
- CartId = table.Column<int>(type: "int", nullable: false),
- OrderStatus = table.Column<int>(type: "int", nullable: true),
- TotalPaid = table.Column<double>(type: "float", nullable: false),
- PaymentMethod = table.Column<int>(type: "int", nullable: false),
- InvoiceId = table.Column<int>(type: "int", nullable: true)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Orders", x => x.Id);
- table.ForeignKey(
- name: "FK_Orders_Accounts_CustomerId",
- column: x => x.CustomerId,
- principalTable: "Accounts",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_Orders_Addresses_AddressId",
- column: x => x.AddressId,
- principalTable: "Addresses",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_Orders_Carts_CartId",
- column: x => x.CartId,
- principalTable: "Carts",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_Orders_Invoices_InvoiceId",
- column: x => x.InvoiceId,
- principalTable: "Invoices",
- principalColumn: "Id");
- });
- migrationBuilder.CreateIndex(
- name: "IX_Invoices_OrderId",
- table: "Invoices",
- column: "OrderId");
- migrationBuilder.CreateIndex(
- name: "IX_Orders_AddressId",
- table: "Orders",
- column: "AddressId");
- migrationBuilder.CreateIndex(
- name: "IX_Orders_CartId",
- table: "Orders",
- column: "CartId");
- migrationBuilder.CreateIndex(
- name: "IX_Orders_CustomerId",
- table: "Orders",
- column: "CustomerId");
- migrationBuilder.CreateIndex(
- name: "IX_Orders_InvoiceId",
- table: "Orders",
- column: "InvoiceId");
- migrationBuilder.AddForeignKey(
- name: "FK_Invoices_Orders_OrderId",
- table: "Invoices",
- column: "OrderId",
- principalTable: "Orders",
- principalColumn: "Id");
- }
- /// <inheritdoc />
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropForeignKey(
- name: "FK_Invoices_Orders_OrderId",
- table: "Invoices");
- migrationBuilder.DropTable(
- name: "Orders");
- migrationBuilder.DropTable(
- name: "Invoices");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment