new-model
FreeNo executable scriptsNot checked新增数据库模型/表。当用户说加表、新增 model、加数据库字段时触发。
by iceymoss★ 43 GitHub starsAbout this skill
新增数据库表 / 字段。结构变更前必须先与用户对齐 schema。
步骤
1. 与用户对齐 schema(必须)
按 database-model.md,问清楚:
- 表名、字段、类型、索引、是否软删除
- JSON 字段统一用
TEXT(不要用 JSONB) - 主键交给 GORM 处理(不写 AUTO_INCREMENT / SERIAL)
- 三库兼容:MySQL / PostgreSQL / SQLite 都跑得过
2. 写 DDL
- MySQL:
deploy/sql/<svc>.sql(追加新表/ALTER TABLE) - 注意:SQLite 不支持
ALTER COLUMN,只能ADD COLUMN - 保留字列名用
commonGroupCol/commonKeyCol(见model/main.go约定) - 布尔值用
commonTrueVal/commonFalseVal
3. 生成 GORM model
goctl model mysql ddl -src=./deploy/sql/<svc>.sql -dir=./apps/<svc>/models/ -c
如果是 MongoDB:
goctl model mongo --type <Type> --dir ./apps/<svc>/models/
4. 迁移 / 初始化
如果项目用代码自动迁移,确认 AutoMigrate 列表里加上新模型。
否则在 deploy/sql/ 提供 idempotent 的 SQL 脚本。
5. 数据库分支
需要数据库特定 SQL 时用:
common.UsingPostgreSQL { ... }
common.UsingSQLite { ... }
common.UsingMySQL { ... }
不要把 MySQL 方言的语法直接写死。
6. 测试
- 单元测试不 mock 数据库(
test-files.md) - 测试结束清理数据
- 三种数据库环境都跑通
严格约束
- 绝对不修改
.env - 绝对不直接 drop / truncate 现有表
- 新增字段如果是 NOT NULL,必须给默认值(兼容旧行)
- 涉及生产数据的迁移必须在 PR 描述里说明回滚方案
Install new-model in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the new-model skill do?
新增数据库模型/表。当用户说加表、新增 model、加数据库字段时触发。
How do I install the new-model skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the new-model skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
by Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
by Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropic