using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace GadgetsOnline.Migrations { public partial class InitialCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Categories", columns: table => new { CategoryId = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), Name = table.Column(type: "nvarchar(max)", nullable: true), Description = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Categories", x => x.CategoryId); }); migrationBuilder.CreateTable( name: "Orders", columns: table => new { OrderId = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderDate = table.Column(type: "datetime2", nullable: false), Username = table.Column(type: "nvarchar(max)", nullable: true), FirstName = table.Column(type: "nvarchar(160)", maxLength: 160, nullable: false), LastName = table.Column(type: "nvarchar(160)", maxLength: 160, nullable: false), Address = table.Column(type: "nvarchar(70)", maxLength: 70, nullable: false), City = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), State = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), PostalCode = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false), Country = table.Column(type: "nvarchar(40)", maxLength: 40, nullable: false), Phone = table.Column(type: "nvarchar(24)", maxLength: 24, nullable: false), Email = table.Column(type: "nvarchar(max)", nullable: false), Total = table.Column(type: "decimal(18,2)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Orders", x => x.OrderId); }); migrationBuilder.CreateTable( name: "Products", columns: table => new { ProductId = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CategoryId = table.Column(type: "int", nullable: false), Name = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: false), Price = table.Column(type: "decimal(18,2)", nullable: false), ProductArtUrl = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: true) }, constraints: table => { table.PrimaryKey("PK_Products", x => x.ProductId); table.ForeignKey( name: "FK_Products_Categories_CategoryId", column: x => x.CategoryId, principalTable: "Categories", principalColumn: "CategoryId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Carts", columns: table => new { RecordId = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), CartId = table.Column(type: "nvarchar(max)", nullable: true), ProductId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), DateCreated = table.Column(type: "datetime2", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Carts", x => x.RecordId); table.ForeignKey( name: "FK_Carts_Products_ProductId", column: x => x.ProductId, principalTable: "Products", principalColumn: "ProductId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OrderDetails", columns: table => new { OrderDetailId = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), OrderId = table.Column(type: "int", nullable: false), ProductId = table.Column(type: "int", nullable: false), Quantity = table.Column(type: "int", nullable: false), UnitPrice = table.Column(type: "decimal(18,2)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_OrderDetails", x => x.OrderDetailId); table.ForeignKey( name: "FK_OrderDetails_Orders_OrderId", column: x => x.OrderId, principalTable: "Orders", principalColumn: "OrderId", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_OrderDetails_Products_ProductId", column: x => x.ProductId, principalTable: "Products", principalColumn: "ProductId", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Carts_ProductId", table: "Carts", column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_OrderDetails_OrderId", table: "OrderDetails", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_OrderDetails_ProductId", table: "OrderDetails", column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_Products_CategoryId", table: "Products", column: "CategoryId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Carts"); migrationBuilder.DropTable( name: "OrderDetails"); migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "Products"); migrationBuilder.DropTable( name: "Categories"); } } }