From 38e765203d6a6e435e4e80368ee3dbb6c4098d2a Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Fri, 29 May 2026 09:02:47 +0200 Subject: [PATCH] Refactored migrations --- .../LiteCharms.Features.MidrandBooks.csproj | 3 - ...ner.cs => 20260529070104_Init.Designer.cs} | 47 +-------------- ...8052014_Init.cs => 20260529070104_Init.cs} | 33 ----------- .../MidrandBooksDbContextModelSnapshot.cs | 57 ++----------------- .../Products/Entities/ProductConfiguration.cs | 2 + 5 files changed, 9 insertions(+), 133 deletions(-) rename LiteCharms.Features.MidrandBooks/Postgres/Migrations/{20260528052014_Init.Designer.cs => 20260529070104_Init.Designer.cs} (95%) rename LiteCharms.Features.MidrandBooks/Postgres/Migrations/{20260528052014_Init.cs => 20260529070104_Init.cs} (93%) diff --git a/LiteCharms.Features.MidrandBooks/LiteCharms.Features.MidrandBooks.csproj b/LiteCharms.Features.MidrandBooks/LiteCharms.Features.MidrandBooks.csproj index 82d3a1b..17db6dd 100644 --- a/LiteCharms.Features.MidrandBooks/LiteCharms.Features.MidrandBooks.csproj +++ b/LiteCharms.Features.MidrandBooks/LiteCharms.Features.MidrandBooks.csproj @@ -162,8 +162,5 @@ - - - diff --git a/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260528052014_Init.Designer.cs b/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260529070104_Init.Designer.cs similarity index 95% rename from LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260528052014_Init.Designer.cs rename to LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260529070104_Init.Designer.cs index ed24e21..42297c0 100644 --- a/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260528052014_Init.Designer.cs +++ b/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260529070104_Init.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations { [DbContext(typeof(MidrandBooksDbContext))] - [Migration("20260528052014_Init")] + [Migration("20260529070104_Init")] partial class Init { /// @@ -649,40 +649,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b.ToTable("Prices", (string)null); }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Products.Models.ProductPrice", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Amount") - .HasColumnType("numeric"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Discount") - .HasColumnType("numeric"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ProductId") - .HasColumnType("bigint"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("ProductId") - .IsUnique(); - - b.ToTable("ProductPrice"); - }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.AuthorBooks.Entities.AuthorBook", b => { b.HasOne("LiteCharms.Features.MidrandBooks.Authors.Entities.Author", "Author") @@ -931,15 +897,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b.Navigation("Product"); }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Products.Models.ProductPrice", b => - { - b.HasOne("LiteCharms.Features.MidrandBooks.Products.Entities.Product", null) - .WithOne("Price") - .HasForeignKey("LiteCharms.Features.MidrandBooks.Products.Models.ProductPrice", "ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.AuthorBooks.Entities.AuthorBook", b => { b.Navigation("Pages"); @@ -973,8 +930,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Products.Entities.Product", b => { - b.Navigation("Price"); - b.Navigation("Prices"); }); #pragma warning restore 612, 618 diff --git a/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260528052014_Init.cs b/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260529070104_Init.cs similarity index 93% rename from LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260528052014_Init.cs rename to LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260529070104_Init.cs index 1c0cb96..d960313 100644 --- a/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260528052014_Init.cs +++ b/LiteCharms.Features.MidrandBooks/Postgres/Migrations/20260529070104_Init.cs @@ -259,30 +259,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations onDelete: ReferentialAction.Restrict); }); - //migrationBuilder.CreateTable( - // name: "ProductPrice", - // columns: table => new - // { - // Id = table.Column(type: "bigint", nullable: false) - // .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - // CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - // UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), - // ProductId = table.Column(type: "bigint", nullable: false), - // Amount = table.Column(type: "numeric", nullable: false), - // Discount = table.Column(type: "numeric", nullable: false), - // Enabled = table.Column(type: "boolean", nullable: false) - // }, - // constraints: table => - // { - // table.PrimaryKey("PK_ProductPrice", x => x.Id); - // table.ForeignKey( - // name: "FK_ProductPrice_Products_ProductId", - // column: x => x.ProductId, - // principalTable: "Products", - // principalColumn: "Id", - // onDelete: ReferentialAction.Cascade); - // }); - migrationBuilder.CreateTable( name: "Shippings", columns: table => new @@ -427,12 +403,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations table: "Prices", column: "ProductId"); - migrationBuilder.CreateIndex( - name: "IX_ProductPrice_ProductId", - table: "ProductPrice", - column: "ProductId", - unique: true); - migrationBuilder.CreateIndex( name: "IX_Refunds_OrderId", table: "Refunds", @@ -467,9 +437,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations migrationBuilder.DropTable( name: "OrderItems"); - migrationBuilder.DropTable( - name: "ProductPrice"); - migrationBuilder.DropTable( name: "Refunds"); diff --git a/LiteCharms.Features.MidrandBooks/Postgres/Migrations/MidrandBooksDbContextModelSnapshot.cs b/LiteCharms.Features.MidrandBooks/Postgres/Migrations/MidrandBooksDbContextModelSnapshot.cs index 634218e..6045ed4 100644 --- a/LiteCharms.Features.MidrandBooks/Postgres/Migrations/MidrandBooksDbContextModelSnapshot.cs +++ b/LiteCharms.Features.MidrandBooks/Postgres/Migrations/MidrandBooksDbContextModelSnapshot.cs @@ -57,7 +57,7 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b.HasIndex("ProductId"); - b.ToTable("Books", (string)null); + b.ToTable("Books"); }); modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Authors.Entities.Author", b => @@ -454,7 +454,7 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b.HasKey("Id"); - b.ToTable("ShippingProviders", (string)null); + b.ToTable("ShippingProviders"); }); modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Pages.Entities.BookPage", b => @@ -646,40 +646,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b.ToTable("Prices", (string)null); }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Products.Models.ProductPrice", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Amount") - .HasColumnType("numeric"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Discount") - .HasColumnType("numeric"); - - b.Property("Enabled") - .HasColumnType("boolean"); - - b.Property("ProductId") - .HasColumnType("bigint"); - - b.Property("UpdatedAt") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("ProductId") - .IsUnique(); - - b.ToTable("ProductPrice", (string)null); - }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.AuthorBooks.Entities.AuthorBook", b => { b.HasOne("LiteCharms.Features.MidrandBooks.Authors.Entities.Author", "Author") @@ -718,7 +684,7 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b1.HasKey("AuthorId", "__synthesizedOrdinal"); - b1.ToTable("Authors", (string)null); + b1.ToTable("Authors"); b1 .ToJson("SocialMedia") @@ -772,7 +738,7 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b1.HasKey("CustomerId", "__synthesizedOrdinal"); - b1.ToTable("Customers", (string)null); + b1.ToTable("Customers"); b1 .ToJson("SocialMedia") @@ -862,7 +828,7 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b1.HasKey("BookPageId", "__synthesizedOrdinal"); - b1.ToTable("BookPages", (string)null); + b1.ToTable("BookPages"); b1 .ToJson("References") @@ -904,7 +870,7 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b1.HasKey("ProductId"); - b1.ToTable("Products", (string)null); + b1.ToTable("Products"); b1 .ToJson("Metadata") @@ -928,15 +894,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations b.Navigation("Product"); }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Products.Models.ProductPrice", b => - { - b.HasOne("LiteCharms.Features.MidrandBooks.Products.Entities.Product", null) - .WithOne("Price") - .HasForeignKey("LiteCharms.Features.MidrandBooks.Products.Models.ProductPrice", "ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - modelBuilder.Entity("LiteCharms.Features.MidrandBooks.AuthorBooks.Entities.AuthorBook", b => { b.Navigation("Pages"); @@ -970,8 +927,6 @@ namespace LiteCharms.Features.MidrandBooks.Postgres.Migrations modelBuilder.Entity("LiteCharms.Features.MidrandBooks.Products.Entities.Product", b => { - b.Navigation("Price"); - b.Navigation("Prices"); }); #pragma warning restore 612, 618 diff --git a/LiteCharms.Features.MidrandBooks/Products/Entities/ProductConfiguration.cs b/LiteCharms.Features.MidrandBooks/Products/Entities/ProductConfiguration.cs index db18548..795097d 100644 --- a/LiteCharms.Features.MidrandBooks/Products/Entities/ProductConfiguration.cs +++ b/LiteCharms.Features.MidrandBooks/Products/Entities/ProductConfiguration.cs @@ -4,6 +4,8 @@ public sealed class ProductConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { + builder.Ignore(p => p.Price); + builder.ToTable("Products"); builder.HasKey(f => f.Id);