⚠️ Kurumsal Hesap - Eksik Yapılar

Tarih: 2025-11-24 | Platform: Muzibu | v3 - Yapılması Gerekenler

🔴 Mevcut Migration Sorunları

❌ Problem: users Tablosuna Tenant-Specific Kolon

000002_refactor_users_corporate_fields.php dosyası users tablosuna corporate_account_id ekliyor. Bu, users tablosunun universal yapısını bozar!

✓ Çözüm: Üyeler de corporate_accounts Tablosunda

Yeni mimaride üyeler de muzibu_corporate_accounts tablosunda tutulacak. parent_id = NULL → Kurum sahibi, parent_id = X → Üye

📋 Yapılacak İşlemler

1. Migration Düzeltmeleri SİL

database/migrations/tenant/2025_11_24_000002_refactor_users_corporate_fields.php

Bu migration silinmeli - users tablosuna hiçbir kolon eklenmeyecek

2. Ana Tablo Migration Güncelleme GÜNCELLE

database/migrations/tenant/2025_11_24_000001_create_muzibu_corporate_accounts_table.php

Eksik kolonlar eklenmeli:

$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
+ $table->foreignId('parent_id')->nullable()->constrained('muzibu_corporate_accounts')->onDelete('cascade');
$table->string('corporate_code', 20)->unique()->nullable();
$table->string('company_name')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();

+ $table->index('parent_id');

3. parent_id Migration Birleştir SİL

database/migrations/tenant/2025_11_24_000003_add_parent_id_to_muzibu_corporate_accounts.php

Bu migration silinmeli - parent_id ana migration'a taşındı

4. Model Güncelleme GÜNCELLE

Modules/Muzibu/app/Models/MuzibuCorporateAccount.php

Eksik özellikler:

5. CorporateService Güncelleme GÜNCELLE

app/Services/Auth/CorporateService.php

Tüm metodlar yeni mimariye göre güncellenmeli:

6. Adres İlişkisi YENİ

Model'e cart_addresses ilişkisi ekle:

📊 Eski vs Yeni Mimari

Özellik Eski (Yanlış) Yeni (Doğru)
Üye Kaydı users.corporate_account_id corporate_accounts (parent_id)
Üyeleri Bul User::where('corporate_account_id', $id) CorporateAccount::where('parent_id', $id)
Üye mi? $user->corporate_account_id !== null CorporateAccount::isUserMember($userId)
users Tablosu Tenant-specific kolon var ❌ Universal kalır ✓
Fatura Adresi corporate_accounts tablosunda cart_addresses tablosunda ✓

🎯 Final Tablo Yapısı

muzibu_corporate_accounts
├── id (PK)
├── user_id (FK → users) -- Bu kaydın sahibi user
├── parent_id (FK → self) -- NULL = kurum, değer = üye
├── corporate_code -- Davet kodu (nullable - sadece kurum)
├── company_name -- Şirket adı (nullable - sadece kurum)
├── is_active
└── timestamps

✓ users tablosu HİÇ DEĞİŞMEZ
✓ Fatura bilgileri cart_addresses'te

📝 İşlem Özeti

Silinecek: 2 migration dosyası (000002, 000003)
Güncellenecek: 1 migration, 1 model, 1 service
Yeni Eklenecek: Adres relationship metodları

⏱️ Uygulama Sırası

  1. Migration dosyalarını düzelt (sil + güncelle)
  2. Model'i güncelle (fillable, relationships, helpers)
  3. CorporateService'i güncelle (tüm metodlar)
  4. Migration çalıştır: php artisan tenants:migrate --tenant=1001
  5. Test et