From 0ddf64370d978416fcdaee0c9ad4756961a4eea2 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sat, 29 Nov 2025 04:57:42 +0330 Subject: [PATCH] feat: Complete Phase 8 - Migration & Seed Data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Database Migration: - Applied migration 20251129002222_AddNetworkClubSystemV2 - Created 11 new tables: * SystemConfigurations * SystemConfigurationHistories * ClubMemberships * ClubMembershipHistories * ClubFeatures * UserClubFeatures * NetworkWeeklyBalances * WeeklyCommissionPools * UserCommissionPayouts * CommissionPayoutHistories * NetworkMembershipHistories - Updated existing tables: * Users: Added NetworkParentId, LegPosition * UserWallets: Added DiscountBalance * Products: Added IsClubExclusive, ClubDiscountPercent Seed Data: - Added 10 default SystemConfigurations: * Network settings (MaxDepth, AllowOrphanNodes) * Club settings (DefaultDuration, MinimumActivation) * Commission settings (PoolPercent, MinimumPayout, WithdrawalMethods) * System settings (MaintenanceMode, AuditLog) Migration Status: ✅ Applied successfully Database Schema: ✅ Verified Build Status: ✅ Success (0 errors) --- .../ApplicationDbContextInitialiser.cs | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContextInitialiser.cs b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContextInitialiser.cs index 2d603b8..863b53f 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContextInitialiser.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContextInitialiser.cs @@ -1,5 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using CMSMicroservice.Domain.Entities.Configuration; +using CMSMicroservice.Domain.Enums; +using System.Collections.Generic; namespace CMSMicroservice.Infrastructure.Persistence; @@ -44,6 +47,104 @@ public class ApplicationDbContextInitialiser } public async Task TrySeedAsync() { + // Seed default System Configurations for Network-Club-Commission System + if (!_context.SystemConfigurations.Any()) + { + var defaultConfigurations = new List + { + // Network Configuration + new SystemConfiguration + { + Key = "Network.MaxDepth", + Value = "10", + Description = "حداکثر عمق شبکه باینری", + Scope = ConfigurationScope.Network, + IsActive = true + }, + new SystemConfiguration + { + Key = "Network.AllowOrphanNodes", + Value = "false", + Description = "اجازه حذف والدین که فرزند دارند", + Scope = ConfigurationScope.Network, + IsActive = true + }, + + // Club Configuration + new SystemConfiguration + { + Key = "Club.DefaultMembershipDurationMonths", + Value = "12", + Description = "مدت زمان پیش‌فرض عضویت باشگاه (ماه)", + Scope = ConfigurationScope.Club, + IsActive = true + }, + new SystemConfiguration + { + Key = "Club.MinimumActivationAmount", + Value = "1000000", + Description = "حداقل مبلغ برای فعال‌سازی عضویت (ریال)", + Scope = ConfigurationScope.Club, + IsActive = true + }, + + // Commission Configuration + new SystemConfiguration + { + Key = "Commission.WeeklyPoolContributionPercent", + Value = "10", + Description = "درصد مشارکت در استخر هفتگی از تعادل کل", + Scope = ConfigurationScope.Commission, + IsActive = true + }, + new SystemConfiguration + { + Key = "Commission.MinimumPayoutAmount", + Value = "100000", + Description = "حداقل مبلغ برای پرداخت کمیسیون (ریال)", + Scope = ConfigurationScope.Commission, + IsActive = true + }, + new SystemConfiguration + { + Key = "Commission.CashWithdrawalEnabled", + Value = "true", + Description = "امکان برداشت نقدی فعال باشد", + Scope = ConfigurationScope.Commission, + IsActive = true + }, + new SystemConfiguration + { + Key = "Commission.DiamondWithdrawalEnabled", + Value = "true", + Description = "امکان تبدیل به الماس فعال باشد", + Scope = ConfigurationScope.Commission, + IsActive = true + }, + + // System Configuration + new SystemConfiguration + { + Key = "System.MaintenanceMode", + Value = "false", + Description = "حالت تعمیر و نگهداری سیستم", + Scope = ConfigurationScope.System, + IsActive = true + }, + new SystemConfiguration + { + Key = "System.EnableAuditLog", + Value = "true", + Description = "فعال‌سازی لاگ تغییرات", + Scope = ConfigurationScope.System, + IsActive = true + } + }; + await _context.SystemConfigurations.AddRangeAsync(defaultConfigurations); + await _context.SaveChangesAsync(); + + _logger.LogInformation("Seeded {Count} default system configurations", defaultConfigurations.Count); + } } }