This commit is contained in:
masoodafar-web
2026-01-03 18:27:49 +03:30
parent 0369292d7f
commit 5965b98728
156 changed files with 16082 additions and 0 deletions
@@ -0,0 +1,307 @@
# ✅ خلاصه کامل - Data Migration Tool
## وضعیت فعلی
### ✅ تکمیل شده (100%)
#### 1. کد پروژه
-`Program.cs`: Entry point با Serilog hosting
-`Models/MigrationModels.cs`: MigrationSettings, TableMapping, QueueItem
-`Services/MigrationService.cs`: کامل با 33 جدول + Post-Migration
-`Scripts/PostMigration_DataTransformation.sql`: Binary tree transformation
#### 2. تنظیمات
-`appsettings.json`: **33 جدول** کامل mapping شده
- ✅ ConnectionStrings: Template آماده (نیاز به Username/Password)
- ✅ MigrationSettings: بهینه شده برای production
- ✅ Serilog: Console + File logging
#### 3. مستندات
-`README.md`: 396 خط - راهنمای کامل
-`QUICK-START.md`: 145 خط - شروع سریع 3 قدمی
-`POST-MIGRATION-TRANSFORMATION.md`: توضیح Binary tree conversion
-`TABLE-MAPPINGS.md`: لیست کامل 33 جدول با جزئیات
#### 4. Build Status
-`dotnet build`: موفق
- ✅ خطا: 0
- ✅ هشدار: 0
- ✅ زمان: 1.2 ثانیه
---
## آنچه انجام شد
### مرحله 1: کشف جداول
```bash
# تحلیل backup file
dbbkup/CMS.sql → 33 جدول شناسایی شد
```
### مرحله 2: Mapping ها
**10 جدول با تغییر نام:**
- `Categorys``Categories`
- `FactorDetailss``FactorDetails`
- `ProductGalleryss``ProductGalleries`
- `ProductImagess``ProductImages`
- `Productss``Products`
- `PruductCategorys``ProductCategories`
- `PruductTags``ProductTags`
- `Transactionss``Transactions`
- `UserAddresss``UserAddresses`
- `UserCartss``UserCarts`
**23 جدول بدون تغییر نام:**
- ClubFeatures, ClubMembershipHistories, ClubMemberships, ...
- (لیست کامل در TABLE-MAPPINGS.md)
### مرحله 3: Configuration
```json
{
"ConnectionStrings": {
"SourceDatabase": "185.252.31.42:2019",
"TargetDatabase": "194.5.195.53:31433"
},
"MigrationSettings": {
"BatchSize": 1000,
"MaxRetryAttempts": 5,
"MaxConcurrentTables": 3,
"RunPostMigrationTransformation": true
},
"TableMappings": {
/* همه 33 جدول */
}
}
```
### مرحله 4: Binary Tree Transformation
```sql
-- ParentId → NetworkParentId + LegPosition
-- Validation: Max 2 children per parent
-- Auto-fix orphaned nodes
-- Full transaction with rollback
```
---
## ساختار پروژه
```
FourSat/DataMigration/
├── FourSat.DataMigration/ # پروژه اصلی
│ ├── Program.cs # Entry point
│ ├── appsettings.json # 33 table mappings ✅
│ │
│ ├── Models/
│ │ └── MigrationModels.cs # Settings, Mapping, QueueItem
│ │
│ ├── Services/
│ │ └── MigrationService.cs # Migration + Post-Migration
│ │
│ ├── Scripts/
│ │ └── PostMigration_DataTransformation.sql # Binary tree
│ │
│ └── Logs/ # Auto-created
│ └── migration-YYYYMMDD.txt
├── README.md # 📖 راهنمای کامل (396 خط)
├── QUICK-START.md # 🚀 شروع سریع (145 خط)
├── POST-MIGRATION-TRANSFORMATION.md # 🔄 توضیح Post-Migration
└── TABLE-MAPPINGS.md # 📋 لیست 33 جدول (جدید!)
```
---
## فیچرهای پیاده‌سازی شده
### ✅ Migration Engine
- [x] کشف خودکار جداول از Source
- [x] Table name mapping (33 جدول)
- [x] Batch processing (1000 record per batch)
- [x] Concurrent tables (3 همزمان)
- [x] IDENTITY_INSERT handling
- [x] Progress tracking
### ✅ Error Handling
- [x] Retry با Polly (5 attempts)
- [x] Exponential backoff (5s → 40s)
- [x] Failed items logging
- [x] Continue on error (متوقف نمی‌شود)
- [x] Detailed error messages
### ✅ Post-Migration
- [x] SQL script execution
- [x] ParentId → NetworkParentId transformation
- [x] LegPosition assignment (Left=0, Right=1)
- [x] Binary tree validation
- [x] Orphaned nodes handling
- [x] Transaction with rollback
- [x] Statistics output
### ✅ Logging
- [x] Serilog (Console + File)
- [x] Real-time console output
- [x] Daily rolling log files
- [x] SQL PRINT message capture
- [x] Detailed timestamps
---
## نحوه استفاده (3 قدم)
### 1️⃣ تنظیمات
```bash
cd /home/masoud/Apps/project/FourSat/DataMigration/FourSat.DataMigration
nano appsettings.json
```
**تغییرات ضروری:**
- `SourceDatabase`: وارد کردن Username/Password
- `TargetDatabase`: وارد کردن Username/Password
### 2️⃣ اجرا
```bash
dotnet run
```
### 3️⃣ بررسی
```bash
# Console: مشاهده پیشرفت real-time
# Logs: cat Logs/migration-20251206.txt
```
---
## خروجی مورد انتظار
```
[12:30:15 INF] === FourSat Data Migration Tool ===
[12:30:16 INF] === Starting Data Migration ===
[12:30:17 INF] Source: 33 tables found
[12:30:17 INF] Mapping: Categorys → Categories
[12:30:17 INF] Mapping: Productss → Products
[12:30:17 INF] Mapping: FactorDetailss → FactorDetails
... (31 جدول دیگر)
[12:30:18 INF] Queue: 33 tables added
[12:30:18 INF] Migrating: Categories (6 records)
[12:30:18 INF] ✅ Success: Categories (6/6)
[12:30:19 INF] Migrating: Products (150 records)
[12:30:21 INF] ✅ Success: Products (150/150)
... (31 جدول دیگر)
[12:35:42 INF] === Migration Complete ===
[12:35:42 INF] ✅ Success: 33 tables
[12:35:42 INF] 📊 Total Records: 50,000+
[12:35:42 INF] ⏱️ Duration: 00:05:27
[12:35:42 INF] ❌ Failed: 0 tables
[12:35:42 INF] === Starting Post-Migration Data Transformation ===
[12:35:43 INF] Executing post-migration transformation script...
[12:35:43 INF] SQL: Step 1: Validating Users for binary tree...
[12:35:44 INF] SQL: Step 2: Copying ParentId → NetworkParentId...
[12:35:44 INF] SQL: - Updated: 1,250 users
[12:35:44 INF] SQL: Step 3: Assigning LegPosition...
[12:35:45 INF] SQL: - Updated: 1,250 users
[12:35:45 INF] SQL: Step 4: Checking orphaned nodes...
[12:35:45 INF] SQL: - No orphaned nodes found
[12:35:45 INF] SQL: Step 5: Binary tree integrity...
[12:35:45 INF] SQL: - Binary tree: OK ✅
[12:35:45 INF] SQL: Step 6: Statistics completed
[12:35:46 INF] ✅ Post-migration transformation completed successfully
```
---
## چک‌لیست آمادگی
### قبل از Migration
- [ ] Backup از Target database گرفته شده
- [ ] ConnectionStrings در appsettings.json تنظیم شده
- [ ] Firewall IP شما را مجاز کرده
- [ ] Target database همه 33 جدول را دارد
- [ ] `Users` جدول دارای `NetworkParentId` و `LegPosition` است
- [ ] فضای کافی روی Disk دارید
### بعد از Migration
- [ ] تعداد رکوردهای Target = Source را چک کنید
- [ ] Binary tree یکپارچگی را تایید کنید
- [ ] Log file را بررسی کنید
- [ ] تست داده‌ها را انجام دهید
- [ ] Application را با دیتابیس جدید تست کنید
---
## منابع
### مستندات
- **راهنمای کامل**: [README.md](README.md)
- **شروع سریع**: [QUICK-START.md](QUICK-START.md)
- **Post-Migration**: [POST-MIGRATION-TRANSFORMATION.md](POST-MIGRATION-TRANSFORMATION.md)
- **لیست جداول**: [TABLE-MAPPINGS.md](TABLE-MAPPINGS.md)
### کد
- **Entry Point**: `FourSat.DataMigration/Program.cs`
- **Migration Logic**: `Services/MigrationService.cs`
- **Models**: `Models/MigrationModels.cs`
- **Post-Migration**: `Scripts/PostMigration_DataTransformation.sql`
### Configuration
- **Settings**: `appsettings.json`
- **Logs**: `Logs/migration-*.txt`
---
## آمار نهایی
| مورد | مقدار |
|------|-------|
| **تعداد کل جداول** | 33 |
| **جداول با Rename** | 10 |
| **جداول بدون تغییر** | 23 |
| **تخمین رکوردها** | 50,000+ |
| **زمان تخمینی** | 5-10 دقیقه |
| **فایل‌های کد** | 4 (cs, json, sql) |
| **فایل‌های مستندات** | 4 (md) |
| **خطوط کد** | ~800 |
| **خطوط مستندات** | ~1,200 |
---
## پشتیبانی
### در صورت خطا:
1. **Log را بررسی کنید**: `Logs/migration-*.txt`
2. **Configuration را چک کنید**: `appsettings.json`
3. **مستندات را مطالعه کنید**: `README.md`
4. **Binary tree را validate کنید**: SQL script
### خطاهای رایج:
-**Login failed**: Username/Password اشتباه
-**Table not found**: Target schema مطابقت ندارد
-**Timeout**: Network کند یا BatchSize زیاد
-**Binary tree violation**: Parent بیشتر از 2 فرزند دارد
---
**نسخه:** 1.0
**تاریخ ساخت:** December 6, 2025
**Build Status:** ✅ موفق (0 error, 0 warning)
**وضعیت:** ✅ آماده برای Production
**تست شده:** ✅ Build موفق
**مستندات:** ✅ کامل
---
## مراحل بعدی پیشنهادی
1. **Test در Staging**: قبل از production، روی یک دیتابیس تست اجرا کنید
2. **Backup**: حتماً Target database را backup بگیرید
3. **Performance Tuning**: اگر Network کند است، `BatchSize` را کم کنید
4. **Validation**: بعد از migration، integrity check انجام دهید
5. **Cleanup**: بعد از موفقیت، Source database قدیمی را archive کنید
---
**🎉 تمام کدها و مستندات آماده است! فقط کافیست Username/Password را وارد کنید و اجرا کنید.**