From 52ae04827edfd435105f7c18b5827e5fae8122f8 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 04:42:05 +0000 Subject: [PATCH] =?UTF-8?q?feat(product):=20T2=20=E2=80=94=20EF=20Core=20p?= =?UTF-8?q?ersistence=20+=20ORM=20config=20(verbatim=20from=20monolith)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Configure ProductDbContext with DbSets for Product and ProductCategory - Port ORM configuration verbatim from monolith: - AppProducts table: Name indexed/required/100, Description/500, Icon unicode(false)/256, self-referencing Parent→Children with Restrict, BuyingPrice/SellingPrice decimal(18,2) - AppProductCategories table: Name required/100, Description/500 - Add EnsureCreated() on startup for automatic schema creation - Verified build succeeds and tables are created correctly in PostgreSQL --- src/Services/Product/Product.API/Program.cs | 6 +++++ .../Data/ProductDbContext.cs | 24 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Services/Product/Product.API/Program.cs b/src/Services/Product/Product.API/Program.cs index 73146ef..0ae7c5f 100644 --- a/src/Services/Product/Product.API/Program.cs +++ b/src/Services/Product/Product.API/Program.cs @@ -13,6 +13,12 @@ var app = builder.Build(); +using (var scope = app.Services.CreateScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); +} + if (app.Environment.IsDevelopment()) { app.UseSwagger(); diff --git a/src/Services/Product/Product.Infrastructure/Data/ProductDbContext.cs b/src/Services/Product/Product.Infrastructure/Data/ProductDbContext.cs index 37cfb81..c38c688 100644 --- a/src/Services/Product/Product.Infrastructure/Data/ProductDbContext.cs +++ b/src/Services/Product/Product.Infrastructure/Data/ProductDbContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Product.Domain.Entities; namespace Product.Infrastructure.Data; @@ -8,9 +9,26 @@ public ProductDbContext(DbContextOptions options) : base(optio { } - protected override void OnModelCreating(ModelBuilder modelBuilder) + public DbSet Products => Set(); + public DbSet ProductCategories => Set(); + + protected override void OnModelCreating(ModelBuilder builder) { - base.OnModelCreating(modelBuilder); - // TODO: Configure entity mappings migrated from monolith + base.OnModelCreating(builder); + + // ProductCategory — verbatim from monolith + builder.Entity().Property(p => p.Name).IsRequired().HasMaxLength(100); + builder.Entity().Property(p => p.Description).HasMaxLength(500); + builder.Entity().ToTable("AppProductCategories"); + + // Product — verbatim from monolith + builder.Entity().Property(p => p.Name).IsRequired().HasMaxLength(100); + builder.Entity().HasIndex(p => p.Name); + builder.Entity().Property(p => p.Description).HasMaxLength(500); + builder.Entity().Property(p => p.Icon).IsUnicode(false).HasMaxLength(256); + builder.Entity().HasOne(p => p.Parent).WithMany(p => p.Children).OnDelete(DeleteBehavior.Restrict); + builder.Entity().Property(p => p.BuyingPrice).HasColumnType("decimal(18,2)"); + builder.Entity().Property(p => p.SellingPrice).HasColumnType("decimal(18,2)"); + builder.Entity().ToTable("AppProducts"); } }