-
Notifications
You must be signed in to change notification settings - Fork 0
hyp migrate.md
maoxiaoyue edited this page Apr 14, 2026
·
1 revision
掃描 Go Model struct(bun ORM tag),比對快照,自動產生 up/down SQL migration。
hyp migrate diff # PostgreSQL migration hyp migrate diff --dialect mysql # MySQL migration hyp migrate diff -o db/migrations/ # 自訂輸出目錄 hyp migrate snapshot # 儲存當前 schema 快照
比對當前 model 與快照,產生 SQL migration 檔案。
hyp migrate diff [flags]
| Flag | 說明 | 預設值 |
|---|---|---|
-d, --dialect |
SQL 方言:postgres 或 mysql
|
postgres |
-o, --output |
輸出目錄 | migrations/ |
-s, --snapshot |
快照檔案路徑 | .hyp/schema_snapshot.json |
偵測的變更類型:
| 類型 | 說明 |
|---|---|
AddTable |
新增 model struct |
DropTable |
移除 model struct |
AddColumn |
struct 新增欄位 |
DropColumn |
struct 移除欄位 |
AlterColumn |
欄位型別或約束變更 |
支援的 bun tag:pk、autoincrement、notnull、unique、type、default
儲存當前 model schema 到快照檔案,作為未來 diff 的基線。
hyp migrate snapshot [flags]
| Flag | 說明 | 預設值 |
|---|---|---|
-s, --snapshot |
快照檔案路徑 | .hyp/schema_snapshot.json |
# 1. 定義/修改 model struct(含 bun tag) # 2. 產生 migration hyp migrate diff # 3. 檢視產生的 SQL cat migrations/*_up.sql cat migrations/*_down.sql # 4. 套用 SQL 到資料庫 # 5. 快照自動更新(diff 完成後自動儲存)
Detected 2 change(s):
• AddColumn: users.bio (TEXT)
• AlterColumn: users.name VARCHAR(100) → VARCHAR(255)
Migration files generated:
UP: migrations/20260403_143000_up.sql
DOWN: migrations/20260403_143000_down.sql
Snapshot updated: .hyp/schema_snapshot.json
- hyp generate model — 生成含 bun tag 的 model
設計文件
套件
- config — 設定
- context — 請求上下文
- router — 路由器
- server — 伺服器
- middleware — 中介層
- websocket — WebSocket
- hidb — 資料庫 ORM
- hidb/cassandra — Cassandra
- logger — 日誌
- json — JSON 處理
- grpc — gRPC
AI 協作工具鏈
- schema — Schema-first 路由
- manifest — 專案 Manifest
- contract — Contract Testing
- errors — Typed Error Catalog
- migrate — Migration Diff
- scaffold — 智慧 Scaffold
- airules — AI Rules
CLI 命令
- hyp 總覽
- hyp new
- hyp api
- hyp run
- hyp restart
- hyp generate
- hyp migrate
- hyp context
- hyp ai-rules
- hyp chkcomment
- hyp impact
- hyp docker
- hyp health
- hyp version
- hyp difflog
Design Docs
Packages
- config — Configuration
- context — Request Context
- router — Router
- server — Server
- middleware — Middleware
- websocket — WebSocket
- hidb — Database ORM
- hidb/cassandra - Cassandra 5.0
- logger — Logger
- json — JSON
- grpc — gRPC
AI Collaboration Toolchain
- schema — Schema-first Routing
- manifest — Project Manifest
- contract — Contract Testing
- errors — Typed Error Catalog
- migrate — Migration Diff
- scaffold — Smart Scaffold
- airules — AI Rules
CLI Commands