database-design
النجوم١
التفرعات٠
آخر تحديث٢٥ أبريل ٢٠٢٦ في ٢٢:٥٧
Schema 設計、ORM 與 Migration 指南
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
SKILL.md
readonlyالقائمة
Schema 設計、ORM 與 Migration 指南
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
完整的網站開發指南,涵蓋 UI/UX 設計、React/Vue/Next.js 前端框架、Laravel/Node.js 後端、Coding Style 與互動式選擇精靈
Web 動畫(Framer Motion、GSAP、View Transitions API、Lottie)。CSS 動畫見 ui/no-ai-feel.md
REST API 與 GraphQL 設計規範指南
認證授權(Auth.js、Clerk、JWT/Cookie 安全、RBAC/ABAC)。不含 OAuth provider 細節
Laravel、Node.js、Django、FastAPI 後端框架指南
JavaScript、TypeScript、PHP、Python、CSS 代碼規範
| id | database_design |
| name | database_design |
| description | Schema 設計、ORM 與 Migration 指南 |
| 項目 | 規範 | 範例 |
|---|---|---|
| 表名 | 複數、snake_case | users, blog_posts |
| 欄位 | 單數、snake_case | user_id, created_at |
| 主鍵 | id | id |
| 外鍵 | 表名單數_id | user_id, post_id |
-- 主鍵
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
-- 字串
name VARCHAR(255)
email VARCHAR(255) UNIQUE
content TEXT
status ENUM('draft', 'published')
-- 數字
price DECIMAL(10, 2)
quantity INT UNSIGNED
-- 時間
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
deleted_at TIMESTAMP NULL
-- 布林
is_active BOOLEAN DEFAULT TRUE
users.id → profiles.user_id
users.id → posts.user_id
posts ← post_tag → tags
-- 單欄索引
CREATE INDEX idx_email ON users(email);
-- 複合索引
CREATE INDEX idx_status_created ON posts(status, created_at);
-- 唯一索引
CREATE UNIQUE INDEX idx_unique_email ON users(email);
// 關聯定義
class User extends Model {
public function posts() {
return $this->hasMany(Post::class);
}
}
// 查詢
$users = User::with('posts')
->where('status', 'active')
->orderBy('created_at', 'desc')
->paginate(20);
const users = await prisma.user.findMany({
where: { status: 'active' },
include: { posts: true },
orderBy: { createdAt: 'desc' },
take: 20,
});
// 建立
php artisan make:migration create_posts_table
// 執行
php artisan migrate
// 回滾
php artisan migrate:rollback
建議規則:避免 N+1(用 eager load /
with()/include);migration 用版本控制;機密用 secret manager。