From 4523ef61510b175d086c0a2fd1f962a8fd2f587f Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Fri, 15 May 2026 07:54:35 +0200 Subject: [PATCH] Fixed Lead->Customer Relationship --- .../Shop/Leads/Entities/Lead.cs | 2 +- .../Shop/Leads/Entities/LeadConfiguration.cs | 2 +- ..._FixedLeadCustomerRelationship.Designer.cs | 776 ++++++++++++++++++ ...515055221_FixedLeadCustomerRelationship.cs | 166 ++++ .../Migrations/ShopDbContextModelSnapshot.cs | 103 +-- .../Entities/ShoppingCartItemConfiguration.cs | 8 +- 6 files changed, 951 insertions(+), 106 deletions(-) create mode 100644 LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.Designer.cs create mode 100644 LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.cs diff --git a/LiteCharms.Features/Shop/Leads/Entities/Lead.cs b/LiteCharms.Features/Shop/Leads/Entities/Lead.cs index deda2d6..cbb4ec1 100644 --- a/LiteCharms.Features/Shop/Leads/Entities/Lead.cs +++ b/LiteCharms.Features/Shop/Leads/Entities/Lead.cs @@ -1,4 +1,4 @@ -using LiteCharms.Features.Shop.Customers.Models; +using LiteCharms.Features.Shop.Customers.Entities; namespace LiteCharms.Features.Shop.Leads.Entities; diff --git a/LiteCharms.Features/Shop/Leads/Entities/LeadConfiguration.cs b/LiteCharms.Features/Shop/Leads/Entities/LeadConfiguration.cs index 39a0a20..e24839e 100644 --- a/LiteCharms.Features/Shop/Leads/Entities/LeadConfiguration.cs +++ b/LiteCharms.Features/Shop/Leads/Entities/LeadConfiguration.cs @@ -24,7 +24,7 @@ public class LeadConfiguration : IEntityTypeConfiguration builder.Property(f => f.AttributionHash).IsRequired(true); builder.HasOne(f => f.Customer) - .WithMany() + .WithMany(f => f.Leads) .HasForeignKey(f => f.CustomerId) .OnDelete(DeleteBehavior.Restrict); } diff --git a/LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.Designer.cs b/LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.Designer.cs new file mode 100644 index 0000000..9789b91 --- /dev/null +++ b/LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.Designer.cs @@ -0,0 +1,776 @@ +// +using System; +using LiteCharms.Features.Shop.Postgres; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace LiteCharms.Features.Shop.Postgres.Migrations +{ + [DbContext(typeof(ShopDbContext))] + [Migration("20260515055221_FixedLeadCustomerRelationship")] + partial class FixedLeadCustomerRelationship + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("LiteCharms.Features.Shop.CartPackages.Entities.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Active") + .HasColumnType("boolean"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("ImageUrl") + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Summary") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Package", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.CartPackages.Entities.PackageItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Active") + .HasColumnType("boolean"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("PackageId") + .HasColumnType("uuid"); + + b.Property("ProductPriceId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("ProductPriceId"); + + b.ToTable("PackageItem", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Customers.Entities.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Active") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("City") + .HasColumnType("text"); + + b.Property("Company") + .HasColumnType("text"); + + b.Property("Country") + .HasColumnType("text"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("Discord") + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LinkedIn") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.Property("PostalCode") + .HasColumnType("text"); + + b.Property("Region") + .HasColumnType("text"); + + b.Property("Slack") + .HasColumnType("text"); + + b.Property("Tax") + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Website") + .HasColumnType("text"); + + b.Property("Whatsapp") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Customers", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Leads.Entities.Lead", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AdGroupId") + .HasColumnType("bigint"); + + b.Property("AdName") + .HasColumnType("bigint"); + + b.Property("AppClickId") + .HasColumnType("text"); + + b.Property("AttributionHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("CampaignId") + .HasColumnType("bigint"); + + b.Property("ClickId") + .HasColumnType("text"); + + b.Property("ClickLocation") + .HasColumnType("text"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("CustomerId") + .HasColumnType("uuid"); + + b.Property("FeedItemId") + .HasColumnType("bigint"); + + b.Property("Source") + .HasColumnType("text"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TargetId") + .HasColumnType("bigint"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("WebClickId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Leads", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Notifications.Entities.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CorrelationId") + .IsRequired() + .HasColumnType("text"); + + b.Property("CorrelationIdType") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("Direction") + .HasColumnType("integer"); + + b.PrimitiveCollection("Errors") + .HasColumnType("jsonb"); + + b.Property("HasError") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("IsHtml") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("IsInternal") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("Message") + .IsRequired() + .HasColumnType("text"); + + b.Property("Platform") + .HasColumnType("integer"); + + b.Property("Priority") + .HasColumnType("integer"); + + b.Property("Processed") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("RecipientAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("RecipientName") + .IsRequired() + .HasColumnType("text"); + + b.Property("SenderAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("SenderName") + .HasColumnType("text"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.ToTable("Notification", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Orders.Entities.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("CustomerId") + .HasColumnType("uuid"); + + b.Property("InvoiceUrl") + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.PrimitiveCollection("Notes") + .HasColumnType("jsonb"); + + b.PrimitiveCollection("Requirements") + .HasColumnType("jsonb"); + + b.Property("Status") + .HasColumnType("integer"); + + b.PrimitiveCollection("Terms") + .HasColumnType("jsonb"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Orders", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Orders.Entities.OrderRefund", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasPrecision(18, 2) + .HasColumnType("numeric(18,2)"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("OrderId") + .HasColumnType("uuid"); + + b.Property("Reason") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderRefunds", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Products.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Active") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("Description") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("ImageUrl") + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Summary") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.PrimitiveCollection("Thumbnails") + .HasColumnType("jsonb"); + + b.HasKey("Id"); + + b.ToTable("Products", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Products.Entities.ProductPrice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Active") + .HasColumnType("boolean"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("Discount") + .HasPrecision(18, 2) + .HasColumnType("numeric(18,2)"); + + b.Property("Price") + .HasPrecision(18, 2) + .HasColumnType("numeric(18,2)"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductPrices", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Quotes.Entities.Quote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("CustomerId") + .HasColumnType("uuid"); + + b.Property("ExpiredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("InvoiceUrl") + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.Property("OrderId") + .HasColumnType("uuid"); + + b.Property("Reason") + .HasColumnType("text"); + + b.Property("ShoppingCartId") + .HasColumnType("uuid"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("OrderId") + .IsUnique(); + + b.HasIndex("ShoppingCartId") + .IsUnique(); + + b.ToTable("Quotes", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("CustomerId") + .HasColumnType("uuid"); + + b.Property("OrderId") + .HasColumnType("uuid"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.HasIndex("OrderId") + .IsUnique(); + + b.ToTable("ShoppingCarts", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("ProductPriceId") + .HasColumnType("uuid"); + + b.Property("Quantity") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(1); + + b.Property("ShoppingCartId") + .HasColumnType("uuid"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ProductPriceId"); + + b.HasIndex("ShoppingCartId"); + + b.ToTable("ShoppingCartItems", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCartPackage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("now()"); + + b.Property("PackageId") + .HasColumnType("uuid"); + + b.Property("ShoppingCartId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("ShoppingCartId"); + + b.ToTable("ShoppingCartPackages", (string)null); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.CartPackages.Entities.PackageItem", b => + { + b.HasOne("LiteCharms.Features.Shop.CartPackages.Entities.Package", "Package") + .WithMany("PackageItems") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LiteCharms.Features.Shop.Products.Entities.ProductPrice", "ProductPrice") + .WithMany() + .HasForeignKey("ProductPriceId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("ProductPrice"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Leads.Entities.Lead", b => + { + b.HasOne("LiteCharms.Features.Shop.Customers.Entities.Customer", "Customer") + .WithMany("Leads") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Orders.Entities.Order", b => + { + b.HasOne("LiteCharms.Features.Shop.Customers.Entities.Customer", "Customer") + .WithMany("Orders") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Orders.Entities.OrderRefund", b => + { + b.HasOne("LiteCharms.Features.Shop.Orders.Entities.Order", "Order") + .WithMany("Refunds") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Products.Entities.ProductPrice", b => + { + b.HasOne("LiteCharms.Features.Shop.Products.Entities.Product", "Product") + .WithMany("ProductPrices") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Quotes.Entities.Quote", b => + { + b.HasOne("LiteCharms.Features.Shop.Customers.Entities.Customer", "Customer") + .WithMany("Quotes") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LiteCharms.Features.Shop.Orders.Entities.Order", "Order") + .WithOne("Quote") + .HasForeignKey("LiteCharms.Features.Shop.Quotes.Entities.Quote", "OrderId"); + + b.HasOne("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", "ShoppingCart") + .WithOne("Quote") + .HasForeignKey("LiteCharms.Features.Shop.Quotes.Entities.Quote", "ShoppingCartId"); + + b.Navigation("Customer"); + + b.Navigation("Order"); + + b.Navigation("ShoppingCart"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", b => + { + b.HasOne("LiteCharms.Features.Shop.Customers.Entities.Customer", "Customer") + .WithMany("ShoppingCarts") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LiteCharms.Features.Shop.Orders.Entities.Order", "Order") + .WithOne("ShoppingCart") + .HasForeignKey("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", "OrderId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("Customer"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCartItem", b => + { + b.HasOne("LiteCharms.Features.Shop.Products.Entities.ProductPrice", "ProductPrice") + .WithMany() + .HasForeignKey("ProductPriceId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", "ShoppingCart") + .WithMany("ShoppingCartItems") + .HasForeignKey("ShoppingCartId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ProductPrice"); + + b.Navigation("ShoppingCart"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCartPackage", b => + { + b.HasOne("LiteCharms.Features.Shop.CartPackages.Entities.Package", "Package") + .WithMany() + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", "ShoppingCart") + .WithMany("ShoppingCartPackages") + .HasForeignKey("ShoppingCartId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("ShoppingCart"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.CartPackages.Entities.Package", b => + { + b.Navigation("PackageItems"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Customers.Entities.Customer", b => + { + b.Navigation("Leads"); + + b.Navigation("Orders"); + + b.Navigation("Quotes"); + + b.Navigation("ShoppingCarts"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Orders.Entities.Order", b => + { + b.Navigation("Quote"); + + b.Navigation("Refunds"); + + b.Navigation("ShoppingCart"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.Products.Entities.Product", b => + { + b.Navigation("ProductPrices"); + }); + + modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", b => + { + b.Navigation("Quote"); + + b.Navigation("ShoppingCartItems"); + + b.Navigation("ShoppingCartPackages"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.cs b/LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.cs new file mode 100644 index 0000000..1d701f8 --- /dev/null +++ b/LiteCharms.Features/Shop/Postgres/Migrations/20260515055221_FixedLeadCustomerRelationship.cs @@ -0,0 +1,166 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LiteCharms.Features.Shop.Postgres.Migrations +{ + /// + public partial class FixedLeadCustomerRelationship : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Leads_Customer_CustomerId", + table: "Leads"); + + migrationBuilder.DropForeignKey( + name: "FK_Leads_Customers_CustomerId1", + table: "Leads"); + + migrationBuilder.DropForeignKey( + name: "FK_ShoppingCartItems_ProductPrices_ProductPriceId1", + table: "ShoppingCartItems"); + + migrationBuilder.DropForeignKey( + name: "FK_ShoppingCartItems_ShoppingCarts_ShoppingCartId1", + table: "ShoppingCartItems"); + + migrationBuilder.DropTable( + name: "Customer"); + + migrationBuilder.DropIndex( + name: "IX_ShoppingCartItems_ProductPriceId1", + table: "ShoppingCartItems"); + + migrationBuilder.DropIndex( + name: "IX_ShoppingCartItems_ShoppingCartId1", + table: "ShoppingCartItems"); + + migrationBuilder.DropIndex( + name: "IX_Leads_CustomerId1", + table: "Leads"); + + migrationBuilder.DropColumn( + name: "ProductPriceId1", + table: "ShoppingCartItems"); + + migrationBuilder.DropColumn( + name: "ShoppingCartId1", + table: "ShoppingCartItems"); + + migrationBuilder.DropColumn( + name: "CustomerId1", + table: "Leads"); + + migrationBuilder.AddForeignKey( + name: "FK_Leads_Customers_CustomerId", + table: "Leads", + column: "CustomerId", + principalTable: "Customers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Leads_Customers_CustomerId", + table: "Leads"); + + migrationBuilder.AddColumn( + name: "ProductPriceId1", + table: "ShoppingCartItems", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "ShoppingCartId1", + table: "ShoppingCartItems", + type: "uuid", + nullable: true); + + migrationBuilder.AddColumn( + name: "CustomerId1", + table: "Leads", + type: "uuid", + nullable: true); + + migrationBuilder.CreateTable( + name: "Customer", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Active = table.Column(type: "boolean", nullable: false), + Address = table.Column(type: "text", nullable: true), + City = table.Column(type: "text", nullable: true), + Company = table.Column(type: "text", nullable: true), + Country = table.Column(type: "text", nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + Discord = table.Column(type: "text", nullable: true), + Email = table.Column(type: "text", nullable: true), + LastName = table.Column(type: "text", nullable: true), + LinkedIn = table.Column(type: "text", nullable: true), + Name = table.Column(type: "text", nullable: true), + Phone = table.Column(type: "text", nullable: true), + PostalCode = table.Column(type: "text", nullable: true), + Region = table.Column(type: "text", nullable: true), + Slack = table.Column(type: "text", nullable: true), + Tax = table.Column(type: "text", nullable: true), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), + Website = table.Column(type: "text", nullable: true), + Whatsapp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Customer", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShoppingCartItems_ProductPriceId1", + table: "ShoppingCartItems", + column: "ProductPriceId1"); + + migrationBuilder.CreateIndex( + name: "IX_ShoppingCartItems_ShoppingCartId1", + table: "ShoppingCartItems", + column: "ShoppingCartId1"); + + migrationBuilder.CreateIndex( + name: "IX_Leads_CustomerId1", + table: "Leads", + column: "CustomerId1"); + + migrationBuilder.AddForeignKey( + name: "FK_Leads_Customer_CustomerId", + table: "Leads", + column: "CustomerId", + principalTable: "Customer", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Leads_Customers_CustomerId1", + table: "Leads", + column: "CustomerId1", + principalTable: "Customers", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ShoppingCartItems_ProductPrices_ProductPriceId1", + table: "ShoppingCartItems", + column: "ProductPriceId1", + principalTable: "ProductPrices", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ShoppingCartItems_ShoppingCarts_ShoppingCartId1", + table: "ShoppingCartItems", + column: "ShoppingCartId1", + principalTable: "ShoppingCarts", + principalColumn: "Id"); + } + } +} diff --git a/LiteCharms.Features/Shop/Postgres/Migrations/ShopDbContextModelSnapshot.cs b/LiteCharms.Features/Shop/Postgres/Migrations/ShopDbContextModelSnapshot.cs index 26d0c26..955c903 100644 --- a/LiteCharms.Features/Shop/Postgres/Migrations/ShopDbContextModelSnapshot.cs +++ b/LiteCharms.Features/Shop/Postgres/Migrations/ShopDbContextModelSnapshot.cs @@ -166,74 +166,6 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations b.ToTable("Customers", (string)null); }); - modelBuilder.Entity("LiteCharms.Features.Shop.Customers.Models.Customer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Active") - .HasColumnType("boolean"); - - b.Property("Address") - .HasColumnType("text"); - - b.Property("City") - .HasColumnType("text"); - - b.Property("Company") - .HasColumnType("text"); - - b.Property("Country") - .HasColumnType("text"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Discord") - .HasColumnType("text"); - - b.Property("Email") - .HasColumnType("text"); - - b.Property("LastName") - .HasColumnType("text"); - - b.Property("LinkedIn") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Phone") - .HasColumnType("text"); - - b.Property("PostalCode") - .HasColumnType("text"); - - b.Property("Region") - .HasColumnType("text"); - - b.Property("Slack") - .HasColumnType("text"); - - b.Property("Tax") - .HasColumnType("text"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Website") - .HasColumnType("text"); - - b.Property("Whatsapp") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Customer"); - }); - modelBuilder.Entity("LiteCharms.Features.Shop.Leads.Entities.Lead", b => { b.Property("Id") @@ -270,9 +202,6 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations b.Property("CustomerId") .HasColumnType("uuid"); - b.Property("CustomerId1") - .HasColumnType("uuid"); - b.Property("FeedItemId") .HasColumnType("bigint"); @@ -295,8 +224,6 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations b.HasIndex("CustomerId"); - b.HasIndex("CustomerId1"); - b.ToTable("Leads", (string)null); }); @@ -615,9 +542,6 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations b.Property("ProductPriceId") .HasColumnType("uuid"); - b.Property("ProductPriceId1") - .HasColumnType("uuid"); - b.Property("Quantity") .ValueGeneratedOnAdd() .HasColumnType("integer") @@ -626,9 +550,6 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations b.Property("ShoppingCartId") .HasColumnType("uuid"); - b.Property("ShoppingCartId1") - .HasColumnType("uuid"); - b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); @@ -636,12 +557,8 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations b.HasIndex("ProductPriceId"); - b.HasIndex("ProductPriceId1"); - b.HasIndex("ShoppingCartId"); - b.HasIndex("ShoppingCartId1"); - b.ToTable("ShoppingCartItems", (string)null); }); @@ -692,15 +609,11 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations modelBuilder.Entity("LiteCharms.Features.Shop.Leads.Entities.Lead", b => { - b.HasOne("LiteCharms.Features.Shop.Customers.Models.Customer", "Customer") - .WithMany() + b.HasOne("LiteCharms.Features.Shop.Customers.Entities.Customer", "Customer") + .WithMany("Leads") .HasForeignKey("CustomerId") .OnDelete(DeleteBehavior.Restrict); - b.HasOne("LiteCharms.Features.Shop.Customers.Entities.Customer", null) - .WithMany("Leads") - .HasForeignKey("CustomerId1"); - b.Navigation("Customer"); }); @@ -780,26 +693,18 @@ namespace LiteCharms.Features.Shop.Postgres.Migrations modelBuilder.Entity("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCartItem", b => { - b.HasOne("LiteCharms.Features.Shop.Products.Entities.ProductPrice", null) + b.HasOne("LiteCharms.Features.Shop.Products.Entities.ProductPrice", "ProductPrice") .WithMany() .HasForeignKey("ProductPriceId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); - b.HasOne("LiteCharms.Features.Shop.Products.Entities.ProductPrice", "ProductPrice") - .WithMany() - .HasForeignKey("ProductPriceId1"); - - b.HasOne("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", null) + b.HasOne("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", "ShoppingCart") .WithMany("ShoppingCartItems") .HasForeignKey("ShoppingCartId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("LiteCharms.Features.Shop.ShoppingCarts.Entities.ShoppingCart", "ShoppingCart") - .WithMany() - .HasForeignKey("ShoppingCartId1"); - b.Navigation("ProductPrice"); b.Navigation("ShoppingCart"); diff --git a/LiteCharms.Features/Shop/ShoppingCarts/Entities/ShoppingCartItemConfiguration.cs b/LiteCharms.Features/Shop/ShoppingCarts/Entities/ShoppingCartItemConfiguration.cs index 7f13aca..5670346 100644 --- a/LiteCharms.Features/Shop/ShoppingCarts/Entities/ShoppingCartItemConfiguration.cs +++ b/LiteCharms.Features/Shop/ShoppingCarts/Entities/ShoppingCartItemConfiguration.cs @@ -1,6 +1,4 @@ -using LiteCharms.Features.Shop.Products.Entities; - -namespace LiteCharms.Features.Shop.ShoppingCarts.Entities; +namespace LiteCharms.Features.Shop.ShoppingCarts.Entities; public class ShoppingCartItemConfiguration : IEntityTypeConfiguration { @@ -15,13 +13,13 @@ public class ShoppingCartItemConfiguration : IEntityTypeConfiguration f.ShoppingCartId).IsRequired(); builder.Property(f => f.ProductPriceId).IsRequired(); - builder.HasOne() + builder.HasOne(f => f.ShoppingCart) .WithMany(s => s.ShoppingCartItems) .HasForeignKey(f => f.ShoppingCartId) .IsRequired() .OnDelete(DeleteBehavior.Cascade); - builder.HasOne() + builder.HasOne(f => f.ProductPrice) .WithMany() .HasForeignKey(f => f.ProductPriceId) .IsRequired()