using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace LiteCharms.Features.Shop.Postgres.Migrations { /// public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Customer", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Company = table.Column(type: "text", nullable: true), Name = table.Column(type: "text", nullable: false), LastName = table.Column(type: "text", nullable: false), Tax = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: false), Discord = table.Column(type: "text", nullable: true), Slack = table.Column(type: "text", nullable: true), LinkedIn = table.Column(type: "text", nullable: true), Whatsapp = table.Column(type: "text", nullable: true), Website = table.Column(type: "text", nullable: true), Phone = table.Column(type: "text", nullable: true), Address = table.Column(type: "text", nullable: true), City = table.Column(type: "text", nullable: true), Region = table.Column(type: "text", nullable: true), Country = table.Column(type: "text", nullable: true), PostalCode = table.Column(type: "text", nullable: true), Active = table.Column(type: "boolean", nullable: false, defaultValue: true) }, constraints: table => { table.PrimaryKey("PK_Customer", x => x.Id); }); migrationBuilder.CreateTable( name: "Notification", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Direction = table.Column(type: "integer", nullable: false), Platform = table.Column(type: "integer", nullable: false), Priority = table.Column(type: "integer", nullable: false), CorrelationIdType = table.Column(type: "integer", nullable: false), Sender = table.Column(type: "text", nullable: false), SenderName = table.Column(type: "text", nullable: true), Subject = table.Column(type: "text", nullable: false), Message = table.Column(type: "text", nullable: false), Recipient = table.Column(type: "text", nullable: false), RecipientAddress = table.Column(type: "text", nullable: false), CorrelationId = table.Column(type: "text", nullable: false), IsHtml = table.Column(type: "boolean", nullable: false, defaultValue: false), IsInternal = table.Column(type: "boolean", nullable: false, defaultValue: true), Processed = table.Column(type: "boolean", nullable: false, defaultValue: false), HasError = table.Column(type: "boolean", nullable: false, defaultValue: false), Errors = table.Column(type: "jsonb", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Notification", x => x.Id); }); migrationBuilder.CreateTable( name: "Package", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), Name = table.Column(type: "text", nullable: false), Summary = table.Column(type: "character varying(512)", maxLength: 512, nullable: false), Description = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), ImageUrl = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), Active = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Package", x => x.Id); }); migrationBuilder.CreateTable( name: "Product", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "text", nullable: false), Summary = table.Column(type: "character varying(512)", maxLength: 512, nullable: false), Description = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), ImageUrl = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), Thumbnails = table.Column(type: "jsonb", nullable: true), Active = table.Column(type: "boolean", nullable: false, defaultValue: true) }, constraints: table => { table.PrimaryKey("PK_Product", x => x.Id); }); migrationBuilder.CreateTable( name: "Lead", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), CustomerId = table.Column(type: "uuid", nullable: true), Source = table.Column(type: "text", nullable: true), ClickId = table.Column(type: "text", nullable: true), WebClickId = table.Column(type: "text", nullable: true), AppClickId = table.Column(type: "text", nullable: true), CampaignId = table.Column(type: "bigint", nullable: true), AdGroupId = table.Column(type: "bigint", nullable: true), AdName = table.Column(type: "bigint", nullable: true), TargetId = table.Column(type: "bigint", nullable: true), FeedItemId = table.Column(type: "bigint", nullable: true), ClickLocation = table.Column(type: "text", nullable: true), AttributionHash = table.Column(type: "text", nullable: false), Status = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Lead", x => x.Id); table.ForeignKey( name: "FK_Lead_Customer_CustomerId", column: x => x.CustomerId, principalTable: "Customer", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Order", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), CustomerId = table.Column(type: "uuid", nullable: false), Status = table.Column(type: "integer", nullable: false), Requirements = table.Column(type: "jsonb", nullable: true), Notes = table.Column(type: "jsonb", nullable: true), Terms = table.Column(type: "jsonb", nullable: true), InvoiceUrl = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true) }, constraints: table => { table.PrimaryKey("PK_Order", x => x.Id); table.ForeignKey( name: "FK_Order_Customer_CustomerId", column: x => x.CustomerId, principalTable: "Customer", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "ProductPrice", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), ProductId = table.Column(type: "uuid", nullable: false), Price = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), Discount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false), Active = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ProductPrice", x => x.Id); table.ForeignKey( name: "FK_ProductPrice_Product_ProductId", column: x => x.ProductId, principalTable: "Product", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "OrderRefund", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), OrderId = table.Column(type: "uuid", nullable: false), Reason = table.Column(type: "text", nullable: false), Amount = table.Column(type: "numeric(18,2)", precision: 18, scale: 2, nullable: false) }, constraints: table => { table.PrimaryKey("PK_OrderRefund", x => x.Id); table.ForeignKey( name: "FK_OrderRefund_Order_OrderId", column: x => x.OrderId, principalTable: "Order", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "ShoppingCart", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), CustomerId = table.Column(type: "uuid", nullable: false), OrderId = 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", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ShoppingCart_Order_OrderId", column: x => x.OrderId, principalTable: "Order", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "PackageItem", columns: table => new { Id = table.Column(type: "uuid", nullable: false), PackageId = table.Column(type: "uuid", nullable: false), ProductPriceId = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), Active = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PackageItem", x => x.Id); table.ForeignKey( name: "FK_PackageItem_Package_PackageId", column: x => x.PackageId, principalTable: "Package", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PackageItem_ProductPrice_ProductPriceId", column: x => x.ProductPriceId, principalTable: "ProductPrice", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "Quote", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), ExpiredAt = table.Column(type: "timestamp with time zone", nullable: true), CustomerId = table.Column(type: "uuid", nullable: false), OrderId = table.Column(type: "uuid", nullable: true), ShoppingCartId = table.Column(type: "uuid", nullable: true), Status = table.Column(type: "integer", nullable: false), InvoiceUrl = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), 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_Order_OrderId", column: x => x.OrderId, principalTable: "Order", 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.CreateTable( name: "ShoppingCartPackage", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), ShoppingCartId = table.Column(type: "uuid", nullable: false), PackageId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ShoppingCartPackage", x => x.Id); table.ForeignKey( name: "FK_ShoppingCartPackage_Package_PackageId", column: x => x.PackageId, principalTable: "Package", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_ShoppingCartPackage_ShoppingCart_ShoppingCartId", column: x => x.ShoppingCartId, principalTable: "ShoppingCart", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Lead_CustomerId", table: "Lead", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Order_CustomerId", table: "Order", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_OrderRefund_OrderId", table: "OrderRefund", column: "OrderId"); migrationBuilder.CreateIndex( name: "IX_PackageItem_PackageId", table: "PackageItem", column: "PackageId"); migrationBuilder.CreateIndex( name: "IX_PackageItem_ProductPriceId", table: "PackageItem", column: "ProductPriceId"); migrationBuilder.CreateIndex( name: "IX_ProductPrice_ProductId", table: "ProductPrice", column: "ProductId"); migrationBuilder.CreateIndex( name: "IX_Quote_CustomerId", table: "Quote", column: "CustomerId"); migrationBuilder.CreateIndex( name: "IX_Quote_OrderId", table: "Quote", column: "OrderId", unique: true); 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_ShoppingCart_OrderId", table: "ShoppingCart", column: "OrderId", unique: true); migrationBuilder.CreateIndex( name: "IX_ShoppingCartItems_ProductPriceId", table: "ShoppingCartItems", column: "ProductPriceId"); migrationBuilder.CreateIndex( name: "IX_ShoppingCartItems_ShoppingCartId", table: "ShoppingCartItems", column: "ShoppingCartId"); migrationBuilder.CreateIndex( name: "IX_ShoppingCartPackage_PackageId", table: "ShoppingCartPackage", column: "PackageId"); migrationBuilder.CreateIndex( name: "IX_ShoppingCartPackage_ShoppingCartId", table: "ShoppingCartPackage", column: "ShoppingCartId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Lead"); migrationBuilder.DropTable( name: "Notification"); migrationBuilder.DropTable( name: "OrderRefund"); migrationBuilder.DropTable( name: "PackageItem"); migrationBuilder.DropTable( name: "Quote"); migrationBuilder.DropTable( name: "ShoppingCartItems"); migrationBuilder.DropTable( name: "ShoppingCartPackage"); migrationBuilder.DropTable( name: "ProductPrice"); migrationBuilder.DropTable( name: "Package"); migrationBuilder.DropTable( name: "ShoppingCart"); migrationBuilder.DropTable( name: "Product"); migrationBuilder.DropTable( name: "Order"); migrationBuilder.DropTable( name: "Customer"); } } }