بنقرة واحدة
database-design
Database design best practices, indexing strategies, and migration patterns for ZGO
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Database design best practices, indexing strategies, and migration patterns for ZGO
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
ZGO API development standards including pagination, error handling, and RESTful design
Test patterns, mocking strategies, and organization best practices
Standardized error format, error code clusters, and API client usage for consistent error handling.
Specifications for Zustand stores, React Query hooks, and the Service-Hook-Type pattern with optimistic updates.
Strict rules for environment variable management using Zod validation and src/config/env.ts.
Guidelines for managing internationalization (i18n) in the project using next-intl and unified translation patterns.
| name | database-design |
| description | Database design best practices, indexing strategies, and migration patterns for ZGO |
| version | 1.0.0 |
| category | architecture |
| tags | ["database","sql","gorm","migration","optimization"] |
| author | ZGO Team |
| updated | "2026-01-24T00:00:00.000Z" |
This skill provides the definitive standards for database design in the ZGO project. It ensures data integrity, query performance, and consistent migration workflows across all modules.
snake_case, plural (e.g., users, user_orders).snake_case (e.g., created_at, is_active).PO suffix and a TableName() method.Every table must include these core audit and identification fields:
id: BigInt / Serial (Primary Key)created_at: Time with zoneupdated_at: Time with zonedeleted_at: Indexable time (for GORM soft deletes)// Example PO Structure
type UserPO struct {
ID uint `gorm:"primaryKey"`
Username string `gorm:"size:255;not null;uniqueIndex"`
Email string `gorm:"size:255;not null;uniqueIndex"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
func (UserPO) TableName() string {
return "users"
}
string in Go. Specify size:255 or text in GORM tags.bool. Defaults to false.int or string with validation in the Service layer. Do not rely solely on DB-level enums.datatypes.JSON or string for flexible data blobs.email, username, or slug to prevent logical duplicates.WHERE clauses (e.g., status, user_id).Username string `gorm:"uniqueIndex:idx_users_username"`
Status string `gorm:"index:idx_users_status"`
// Composite Index
TenantID uint `gorm:"index:idx_tenant_created;priority:1"`
CreatedAt time.Time `gorm:"index:idx_tenant_created;priority:2"`
We use GORM's AutoMigrate for simple development, but production changes must use explicit migration files or controlled scripts to prevent data loss.
SELECT *In repositories, only fetch what you need if performance is critical. However, for standard CRUD, GORM's default behavior is acceptable.
Never perform a database query inside a loop. Use Eager Loading.
// ❌ WRONG
for _, user := range users {
var profile Profile
db.Where("user_id = ?", user.ID).First(&profile) // N queries
}
// ✅ CORRECT (GORM Preload)
db.Preload("Profile").Find(&users) // 2 queries total
Whenever a query feels slow, use EXPLAIN ANALYZE in your DB console to check for sequential scans vs. index hits.
id, created_at, updated_at, deleted_at.snake_case.TableName() is explicitly defined in model.go.module-creation: Where model.go lives.coding-standards: General naming and error handling.Version: 1.0.0
Last Updated: 2026-01-24
Maintainer: ZGO Team