Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

hyp migrate.md

maoxiaoyue edited this page Apr 14, 2026 · 1 revision

hyp migrate — 資料庫 Migration 工具

掃描 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 快照

子命令

diff

比對當前 model 與快照,產生 SQL migration 檔案。

hyp migrate diff [flags]
Flag 說明 預設值
-d, --dialect SQL 方言:postgresmysql postgres
-o, --output 輸出目錄 migrations/
-s, --snapshot 快照檔案路徑 .hyp/schema_snapshot.json

偵測的變更類型:

類型 說明
AddTable 新增 model struct
DropTable 移除 model struct
AddColumn struct 新增欄位
DropColumn struct 移除欄位
AlterColumn 欄位型別或約束變更

支援的 bun tag:pkautoincrementnotnulluniquetypedefault

snapshot

儲存當前 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

相關命令

詳細文檔

HypGo

繁體中文 | English


中文文件

設計文件

套件

AI 協作工具鏈

CLI 命令


English Docs

Design Docs

Packages

AI Collaboration Toolchain

CLI Commands

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /