Files
docs/archive/collected-docs/DataMigration/SUMMARY.md
T
masoodafar-web 5965b98728 update
2026-01-03 18:27:49 +03:30

9.5 KiB

خلاصه کامل - 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: کشف جداول

# تحلیل backup file
dbbkup/CMS.sql → 33 جدول شناسایی شد

مرحله 2: Mapping ها

10 جدول با تغییر نام:

  • CategorysCategories
  • FactorDetailssFactorDetails
  • ProductGalleryssProductGalleries
  • ProductImagessProductImages
  • ProductssProducts
  • PruductCategorysProductCategories
  • PruductTagsProductTags
  • TransactionssTransactions
  • UserAddresssUserAddresses
  • UserCartssUserCarts

23 جدول بدون تغییر نام:

  • ClubFeatures, ClubMembershipHistories, ClubMemberships, ...
  • (لیست کامل در TABLE-MAPPINGS.md)

مرحله 3: Configuration

{
  "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

-- 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

  • کشف خودکار جداول از Source
  • Table name mapping (33 جدول)
  • Batch processing (1000 record per batch)
  • Concurrent tables (3 همزمان)
  • IDENTITY_INSERT handling
  • Progress tracking

Error Handling

  • Retry با Polly (5 attempts)
  • Exponential backoff (5s → 40s)
  • Failed items logging
  • Continue on error (متوقف نمی‌شود)
  • Detailed error messages

Post-Migration

  • SQL script execution
  • ParentId → NetworkParentId transformation
  • LegPosition assignment (Left=0, Right=1)
  • Binary tree validation
  • Orphaned nodes handling
  • Transaction with rollback
  • Statistics output

Logging

  • Serilog (Console + File)
  • Real-time console output
  • Daily rolling log files
  • SQL PRINT message capture
  • Detailed timestamps

نحوه استفاده (3 قدم)

1️⃣ تنظیمات

cd /home/masoud/Apps/project/FourSat/DataMigration/FourSat.DataMigration
nano appsettings.json

تغییرات ضروری:

  • SourceDatabase: وارد کردن Username/Password
  • TargetDatabase: وارد کردن Username/Password

2️⃣ اجرا

dotnet run

3️⃣ بررسی

# 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 را با دیتابیس جدید تست کنید

منابع

مستندات

کد

  • 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 را وارد کنید و اجرا کنید.