/database:orm-syncfrom database
讓 ORM entity 與資料庫 schema 保持同步(DB-first)——加新表/view、從資料庫重新產生 entity、修正 precision/nullable/長度與實際 schema 的偏差;附 EF Core Power Tools(efcpt)流程。Use when 加表, 同步 Entity, scaffold, efcpt, 更新實體, re-scaffold, 重新產生 Entity, "DB schema 同步到 ORM", "entity 欄位型別跟資料庫不一致", or when a file with an "auto generated" header must be changed (手改會被覆蓋).
Ships in database. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
核心原則:Entity 是資料庫 schema 的鏡射。修 precision/nullable/長度偏差,不手改自動產生的檔(下次 scaffold 會覆蓋),一律回到產生工具重新產生。
先看專案的 *.csproj/package.json/pyproject.toml、產生工具設定檔(efcpt-config.json、efpt.config.json、prisma/schema.prisma、sqlacodegen 設定)、DB 連線字串,對照下表載入附錄,並在回報第一行寫「附錄:<檔名>」。
| 偵測到 | 附錄 |
|---|---|
Microsoft.EntityFrameworkCore*、efcpt-config.json/efpt.config.json、自動產生檔頭 EF Core Power Tools | ${CLAUDE_PLUGIN_ROOT}/references/orm/ef-core.md(「efcpt scaffold」一節) |
| SQL Server/PostgreSQL/MySQL/SQLite 連線線索 | ${CLAUDE_PLUGIN_ROOT}/references/dialects/<sqlserver|postgresql|mysql|sqlite>.md(型別對照、連線字串、常見坑) |
沒有對應附錄(Prisma、SQLAlchemy、TypeORM 等):照本 skill 的通用流程,加上專案既有程式的寫法(先找 2–3 個既有 entity 當樣板;有裝 workspace 就照 workspace:convention-first(可選))。做完問使用者要不要把這次的寫法整理成新附錄 references/orm/<工具>.md,回報寫「附錄:無(照既有程式)」。
本次變更需要新增或改 schema(新表、加欄、view 改名、型別變)時,照順序:
migration skill)。migration-first 的兩個坑:
若專案的 reverse-engineer 來源是獨立的「設計庫/參考庫」(與 runtime/app DB 不同連線),要先在那個庫套用 schema 變更(並備妥 rollback plan),再 scaffold。設計庫已有目標 schema、只是 re-scaffold,直接走第 2 節。
git diff --stat 確認除預期檔案外,既有檔案零差異(已存在的 entity 有手動修改的要先備份)。migration skill。| 想法 | 現實 |
|---|---|
| 「用 ORM 內建的 scaffold 指令就好」 | 要用專案約定的產生工具,才讀得到設定與模板 |
| 「只改一份設定就好」 | 多份設定檔的表清單必須同步 |
| 「裝最新版工具就好」 | 工具版本要與專案 ORM 版本一致 |
| 「連線字串寫進設定檔」 | 禁止,僅在記憶體或 shell 變數使用 |
| 「產生器連的就是 runtime DB」 | 專案可能用獨立設計庫,先確認 |
| 「產生完就好,不用檢查」 | 必須確認既有檔案零差異再建 migration |
| 「直接套用 migration」 | 先審查 migration SQL,確認無破壞性變更 |
| 「手改自動產生的 entity 比較快」 | 下次產生會被覆蓋;調模板或設定 |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub kerryhuang/plugharbor --plugin database4 skills in this plugin
/migration資料庫 migration 全流程——建立、審查產生的 SQL、套用、回滾、失敗修復、切換目標資料庫,以及特殊情境診斷(snapshot 衝突、歷史紀錄遺失、緊急回滾);方言走 dialects 附錄,工具走 ORM 附錄(附 EF Core)。Use when 建 migration, 套用 migration, 回滾 migration, migration 失敗, dotnet ef, snapshot 衝突, "migration 對不上", "緊急回滾", "migration 診斷", "create migration", "apply migration", "rollback"./schema-conventions撰寫或審查資料表(CREATE TABLE)與檢視表(CREATE VIEW)腳本的慣例——檔案結構、命名、主鍵、稽核欄、軟刪除、約束、view 撰寫原則;方言差異走附錄(附 SQL Server、PostgreSQL、MySQL、SQLite)。Use when writing or reviewing table/view DDL, "資料表慣例", "table 命名規則", "怎麼建表", "view 慣例", "檢視表怎麼寫", "schema convention", "table convention", "view convention"./schema-docs由 SQL view 檔解析欄位映射、關聯與計算邏輯,產生資料表結構說明文件(Markdown);方言關鍵字走附錄。Use when 產生資料表描述, 文件化檢視表, 更新 TableDescription, 由 view 產欄位對照.Other plugins' skills for the same job