# Veritabanı ORM: **GORM v1.31** Sürücü: **MySQL (gorm.io/driver/mysql)** Karakter seti: `utf8mb4` --- ## Tablolar ### `users` `gorm.Model` gömülüdür → `id`, `created_at`, `updated_at`, `deleted_at` otomatik eklenir. | Sütun | Tip | Kısıtlama | Açıklama | |---|---|---|---| | `id` | BIGINT UNSIGNED | PK, AUTO_INCREMENT | — | | `username` | VARCHAR(255) | — | Kullanıcı adı | | `email` | VARCHAR(255) | UNIQUE, NOT NULL | Giriş e-postası | | `password` | VARCHAR(255) | — | bcrypt hash (JSON'da gizli) | | `email_verified` | TINYINT(1) | DEFAULT 0 | E-posta doğrulandı mı | | `email_verify_token` | VARCHAR(255) | INDEX | Doğrulama token'ı | | `email_verified_at` | DATETIME | NULL | Doğrulama zamanı | | `is_admin` | TINYINT(1) | DEFAULT 0 | Yönetici mi | | `created_at` | DATETIME | — | — | | `updated_at` | DATETIME | — | — | | `deleted_at` | DATETIME | INDEX, NULL | Soft-delete | --- ### `social_accounts` | Sütun | Tip | Kısıtlama | Açıklama | |---|---|---|---| | `id` | BIGINT UNSIGNED | PK | — | | `user_id` | BIGINT UNSIGNED | NOT NULL, INDEX | `users.id` yabancı anahtar | | `provider` | VARCHAR(255) | NOT NULL | `google`, `github` vb. | | `provider_id` | VARCHAR(255) | NOT NULL | Sağlayıcıdan gelen ID | | `email` | VARCHAR(255) | — | Sağlayıcı e-postası | | `name` | VARCHAR(255) | — | Tam ad | | `avatar_url` | VARCHAR(255) | — | Profil fotoğrafı URL | | `created_at` | DATETIME | — | — | | `updated_at` | DATETIME | — | — | | `deleted_at` | DATETIME | NULL | Soft-delete | --- ### `profiles` | Sütun | Tip | Kısıtlama | Açıklama | |---|---|---|---| | `id` | BIGINT UNSIGNED | PK | — | | `user_id` | BIGINT UNSIGNED | NOT NULL, INDEX | `users.id` yabancı anahtar | | `avatar_url` | VARCHAR(255) | — | Profil fotoğrafı | | `first_name` | VARCHAR(255) | — | Ad | | `last_name` | VARCHAR(255) | — | Soyad | | `created_at` | DATETIME | — | — | | `updated_at` | DATETIME | — | — | | `deleted_at` | DATETIME | NULL | Soft-delete | --- ### `settings` Site genel ayarları. Örnek alanlar: - `title`, `meta_title`, `meta_description` - `phone`, `url`, `email` - sosyal alanlar (`facebook`, `x`, `instagram`, ...) - logo/medya alanları (`w_logo`, `b_logo`, `w_width`, ...) - `is_active` ### `heroes` Anasayfa hero/banner kayıtları: - `color`, `title`, `text1/text2/text4/text5` - `image`, `width`, `height`, `quality`, `format` - `is_active` ### `cors_whitelists` / `cors_blacklists` Dynamic CORS politika tabloları: - whitelist: izinli origin - blacklist: engelli origin (öncelikli blok) ### `rate_limit_settings` DB tabanlı rate-limit kuralları: - `name` (unique): ör. `api/v1/auth/login`, `api/v1/auth/register`, `api` - `max_requests`, `window_seconds`, `is_active` ### Shop tabloları - `product_categories` - `product_tags` - `products` - join tabloları: `product_product_categories`, `product_product_tags` - `product_category_views` - `product_comments` - `carts` - `cart_items` ### Blog tabloları - `categories` - `tags` - `posts` - join tabloları: `post_categories`, `post_tags` - `category_views` - `comments` --- ## İlişkiler ``` users (1) ──────── (N) social_accounts users (1) ──────── (N) profiles ``` --- ## AutoMigrate `config.ConnectDB()` her başlatmada çalışır ve eksik tabloları / sütunları ekler. Mevcut sütunları silmez veya daraltmaz. ```go db.AutoMigrate( &accountModels.User{}, &accountModels.SocialAccount{}, &accountModels.Profile{}, &settingsModels.Setting{}, &settingsModels.Hero{}, &settingsModels.CorsWhitelist{}, &settingsModels.CorsBlacklist{}, &settingsModels.RateLimitSetting{}, &shopModels.ProductCategory{}, &shopModels.ProductTag{}, &shopModels.Product{}, &shopModels.ProductCategoryView{}, &shopModels.ProductComment{}, &shopModels.Cart{}, &shopModels.CartItem{}, &blogModels.Category{}, &blogModels.Tag{}, &blogModels.Post{}, &blogModels.CategoryView{}, &blogModels.Comment{}, ) ``` --- ## Notlar - Tüm modellerde `gorm.Model` kullanıldığı için soft delete (`deleted_at`) aktiftir. - CORS ve rate-limit için başlangıç seed kayıtları uygulama açılışında yalnızca **yoksa** oluşturulur.