using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace LiteCharms.Infrastructure.Database.Migrations { /// public partial class AddedQuoteShoppingCartalteredOrderCustomer : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Order_ProductPrice_ProductPriceId", table: "Order"); migrationBuilder.DropIndex( name: "IX_Order_ProductPriceId", table: "Order"); migrationBuilder.RenameColumn( name: "ProductPriceId", table: "Order", newName: "ShoppingCartId"); migrationBuilder.AddColumn( name: "QuoteId", table: "Order", type: "uuid", nullable: true); migrationBuilder.CreateTable( name: "ShoppingCart", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), CustomerId = table.Column(type: "uuid", nullable: true), OrderId = table.Column(type: "uuid", nullable: true), QuoteId = table.Column(type: "uuid", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ShoppingCart", x => x.Id); table.ForeignKey( name: "FK_ShoppingCart_Customer_CustomerId", column: x => x.CustomerId, principalTable: "Customer", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Quote", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CustomerId1 = table.Column(type: "uuid", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), ExpiredAt = table.Column(type: "timestamp with time zone", nullable: true), CustomerId = table.Column(type: "uuid", nullable: false), ShoppingCartId = table.Column(type: "uuid", nullable: false), Status = table.Column(type: "integer", nullable: false), Reason = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Quote", x => x.Id); table.ForeignKey( name: "FK_Quote_Customer_CustomerId", column: x => x.CustomerId, principalTable: "Customer", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Quote_Customer_CustomerId1", column: x => x.CustomerId1, principalTable: "Customer", principalColumn: "Id"); table.ForeignKey( name: "FK_Quote_ShoppingCart_ShoppingCartId", column: x => x.ShoppingCartId, principalTable: "ShoppingCart", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "ShoppingCartItems", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ShoppingCartId = table.Column(type: "uuid", nullable: false), ProductPriceId = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), Quantity = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShoppingCartItems", x => x.Id); table.ForeignKey( name: "FK_ShoppingCartItems_ProductPrice_ProductPriceId", column: x => x.ProductPriceId, principalTable: "ProductPrice", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ShoppingCartItems_ShoppingCart_ShoppingCartId", column: x => x.ShoppingCartId, principalTable: "ShoppingCart", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Order_QuoteId", table: "Order", column: "QuoteId", unique: true); migrationBuilder.CreateIndex( name: "IX_Order_ShoppingCartId", table: "Order", column: "ShoppingCartId", unique: true); migrationBuilder.CreateIndex( name: "IX_Quote_CustomerId", table: "Quote", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Quote_CustomerId1", table: "Quote", column: "CustomerId1"); migrationBuilder.CreateIndex( name: "IX_Quote_ShoppingCartId", table: "Quote", column: "ShoppingCartId", unique: true); migrationBuilder.CreateIndex( name: "IX_ShoppingCart_CustomerId", table: "ShoppingCart", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_ShoppingCartItems_ProductPriceId", table: "ShoppingCartItems", column: "ProductPriceId"); migrationBuilder.CreateIndex( name: "IX_ShoppingCartItems_ShoppingCartId", table: "ShoppingCartItems", column: "ShoppingCartId"); migrationBuilder.AddForeignKey( name: "FK_Order_Quote_QuoteId", table: "Order", column: "QuoteId", principalTable: "Quote", principalColumn: "Id", onDelete: ReferentialAction.Restrict); migrationBuilder.AddForeignKey( name: "FK_Order_ShoppingCart_ShoppingCartId", table: "Order", column: "ShoppingCartId", principalTable: "ShoppingCart", principalColumn: "Id"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Order_Quote_QuoteId", table: "Order"); migrationBuilder.DropForeignKey( name: "FK_Order_ShoppingCart_ShoppingCartId", table: "Order"); migrationBuilder.DropTable( name: "Quote"); migrationBuilder.DropTable( name: "ShoppingCartItems"); migrationBuilder.DropTable( name: "ShoppingCart"); migrationBuilder.DropIndex( name: "IX_Order_QuoteId", table: "Order"); migrationBuilder.DropIndex( name: "IX_Order_ShoppingCartId", table: "Order"); migrationBuilder.DropColumn( name: "QuoteId", table: "Order"); migrationBuilder.RenameColumn( name: "ShoppingCartId", table: "Order", newName: "ProductPriceId"); migrationBuilder.CreateIndex( name: "IX_Order_ProductPriceId", table: "Order", column: "ProductPriceId"); migrationBuilder.AddForeignKey( name: "FK_Order_ProductPrice_ProductPriceId", table: "Order", column: "ProductPriceId", principalTable: "ProductPrice", principalColumn: "Id", onDelete: ReferentialAction.Restrict); } } }