mcpField
F
frappe-agent-migrator

frappe-agent-migrator

github.com/impertio-studio开发198114 次安装30 周前更新
代码仓库

关于 frappe-agent-migrator

frappe-agent-migrator 是用于规划和执行 Frappe/ERPNext 版本迁移的 Agent,检查版本间的破坏性变更并扫描自定义代码中的兼容性问题。它要求按主版本顺序升级,并生成前置条件、迁移路径和代码修复清单。

主要功能

  1. 01规划连续的主版本迁移路径
  2. 02核对版本破坏性变更
  3. 03扫描自定义应用的弃用模式
  4. 04生成环境前置条件清单
  5. 05输出代码补丁与迁移评估

适用场景

  1. 01升级前评估 Frappe/ERPNext 版本
  2. 02检查自定义应用的兼容性风险
  3. 03规划多步版本升级
  4. 04整理迁移前置条件和代码修复

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/impertio-studio/frappe_claude_skill_package --skill frappe-agent-migrator

安装后在 Claude Code 中输入/frappe-agent-migrator确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
.gitkeep
breaking-changes.md
checklists.md
workflow.md

详细介绍

版本迁移助手

通过分析破坏性变更、扫描自定义代码以检查兼容性问题并生成迁移计划,系统地规划和执行 Frappe/ERPNext 版本迁移。

目的:在升级前检测每一项破坏性变更,防止迁移失败。

何时使用此 Agent

MIGRATION TRIGGER
|
+-- Planning a version upgrade
|   "We need to go from v14 to v15"
|   --> USE THIS AGENT
|
+-- Post-upgrade errors
|   "Everything broke after bench update"
|   --> USE THIS AGENT (Step 2-5 for diagnosis)
|
+-- Checking custom app compatibility
|   "Will our custom app work on v16?"
|   --> USE THIS AGENT (Step 3 for code scan)
|
+-- Already mid-migration with issues
|   "bench migrate fails with errors"
|   --> USE THIS AGENT + frappe-agent-debugger

迁移工作流

STEP 1: IDENTIFY MIGRATION PATH
  Source version → Target version (NEVER skip major versions)

STEP 2: CHECK BREAKING CHANGES
  Apply breaking changes database for each version jump

STEP 3: SCAN CUSTOM CODE
  Grep for deprecated patterns in all custom apps

STEP 4: GENERATE MIGRATION PLAN
  Backup → Staging → Test → Production sequence

STEP 5: GENERATE PATCH LIST
  Specific code changes needed per custom app

详细步骤请参阅 references/workflow.md。

步骤 1:迁移路径规则

绝不跳过主要版本。务必按顺序迁移:

来源目标路径
v14v15v14 → v15
v14v16v14 → v15 → v16
v15v16v15 → v16
版本识别
# Check current versions
bench version
# Output shows: frappe X.Y.Z, erpnext X.Y.Z

# Check available versions
cd apps/frappe && git tag | grep "^v1[456]" | tail -5

步骤 2:破坏性变更摘要

v14 → v15 破坏性变更
类别变更影响检测模式
调度器Tick 间隔从 240s 变为 60s任务可能运行得更频繁检查 scheduler_events
后台任务新增 job_id 去重现在会阻止重复任务检查 frappe.enqueue() 调用
Web 视图工作区取代 Module Def 页面自定义模块页面会失效搜索 Module Def 引用
打印格式HTML 转 PDF 引擎变更打印布局可能不同测试所有打印格式
数据库要求 MariaDB 10.6+服务器先决条件检查 mysql --version
Python要求 Python 3.10+语法/库兼容性检查 python3 --version
APIfrappe.client.get_list 签名变更自定义 API 调用可能失败搜索 frappe.client.get_list
权限对 API 的权限检查更加严格访客访问可能失效检查 allow_guest=True 的用法
资源新前端构建系统自定义 JS 包可能失效测试 bench build
钩子boot_session 钩子变更自定义启动数据可能失效搜索 boot_session
命名部分命名规则变更文档名称可能不同检查 autoname 设置
报表报表生成器变更可能需要更新自定义报表测试所有脚本报表
v15 → v16 破坏性变更
类别变更影响检测模式
DocType 扩展extend_doctype_class 取代 doc_events 覆盖控制器覆盖需要重构搜索带有方法覆盖的 doc_events
类型注解类型提示现为最佳实践代码风格变更不会造成破坏,但建议采用
Chrome PDF新 PDF 引擎(基于 Chrome)打印格式渲染变更测试所有打印格式
数据脱敏新隐私功能需要配置 PII 字段检查敏感字段
UUID 命名新的 uuid 命名规则命名逻辑变更检查 autoname 设置
Python要求 Python 3.11+库兼容性检查 python3 --version
Node.js要求 Node 18+构建系统先决条件检查 node --version
Redis要求 Redis 7+缓存/队列兼容性检查 redis-server --version
已弃用的 API移除了多个 API使用已移除 API 的代码会失败参阅 breaking-changes.md
工作流工作流引擎更新可能需要检查自定义工作流状态测试所有工作流
门户门户页面渲染变更自定义门户页面可能失效测试所有门户页面
后台任务RQ 版本升级任务序列化方式变更测试后台任务

完整详情请参阅 references/breaking-changes.md。

步骤 3:已弃用模式检测

务必扫描自定义应用代码,查找以下模式:

v14 → v15 已弃用模式
# Run these grep commands in apps/{your_app}/ directory:

# 1. Old-style module page references
grep -rn "Module Def" --include="*.py" --include="*.json"

# 2. Old scheduler API
grep -rn "frappe.utils.scheduler" --include="*.py"

# 3. Deprecated client API
grep -rn "frappe.set_route\|cur_page\|page_container" --include="*.js"

# 4. Old-style print format
grep -rn "frappe.get_print\|standard_format" --include="*.py"

# 5. Deprecated database methods
grep -rn "frappe.db.sql_list\|frappe.db.sql_ddl" --include="*.py"
v15 → v16 已弃用模式
# Run these grep commands in apps/{your_app}/ directory:

# 1. doc_events that should use extend_doctype_class
grep -rn "doc_events" hooks.py

# 2. Old-style controller override
grep -rn "override_doctype_class" --include="*.py"

# 3. Deprecated frappe.utils methods
grep -rn "frappe.utils.now_datetime\b" --include="*.py"

# 4. Old print format API
grep -rn "frappe.utils.pdf\|get_pdf" --include="*.py"

# 5. Removed API calls
grep -rn "frappe.get_hooks\b.*boot_session" --include="*.py"

# 6. Missing type annotations (warning, not error)
grep -rn "def .*whitelist" --include="*.py"

步骤 4:迁移计划模板

务必按以下格式生成迁移计划:

## Migration Plan: v{source} → v{target}

### Prerequisites
- [ ] Python version: {required}
- [ ] Node.js version: {required}
- [ ] MariaDB version: {required}
- [ ] Redis version: {required}
- [ ] Disk space: minimum 2x current DB size

### Phase 1: Preparation (Day 1)
1. Full backup: `bench --site {site} backup --with-files`
2. Document current state: `bench version > pre-migration-versions.txt`
3. List all custom apps: `bench --site {site} list-apps`
4. Run deprecated pattern scan (Step 3)
5. Fix all detected issues in custom apps

### Phase 2: Staging (Day 2-3)
1. Clone production to staging environment
2. Restore backup on staging: `bench --site staging restore {backup}`
3. Switch branch: `bench switch-to-branch version-{target} frappe erpnext`
4. Run migration: `bench --site staging migrate`
5. Run full test suite on staging

### Phase 3: Testing (Day 4-5)
- [ ] All DocTypes load correctly
- [ ] All print formats render correctly
- [ ] All workflows transition correctly
- [ ] All scheduled jobs execute correctly
- [ ] All custom reports generate correctly
- [ ] All API endpoints respond correctly
- [ ] All user permissions work correctly
- [ ] Performance is acceptable (page load < 3s)

### Phase 4: Production (Day 6)
1. Schedule maintenance window
2. Enable maintenance mode: `bench --site {site} set-maintenance-mode on`
3. Final backup: `bench --site {site} backup --with-files`
4. Switch branch: `bench switch-to-branch version-{target} frappe erpnext`
5. Run migration: `bench --site {site} migrate`
6. Run `bench build --production`
7. Restart: `bench restart` (or `sudo supervisorctl restart all`)
8. Disable maintenance mode: `bench --site {site} set-maintenance-mode off`
9. Verify (Phase 3 checklist again)

### Rollback Plan
1. Stop all services: `sudo supervisorctl stop all`
2. Restore backup: `bench --site {site} restore {backup_path}`
3. Switch back: `bench switch-to-branch version-{source} frappe erpnext`
4. Run migration: `bench --site {site} migrate`
5. Rebuild: `bench build --production`
6. Restart: `sudo supervisorctl restart all`

步骤 5:自定义应用补丁列表

对于步骤 3 中发现的每种已弃用模式,都生成具体的修复方案:

文件行当前代码所需更改是否有破坏性影响?
{file}{line}{old_pattern}{new_pattern}是/否
常见补丁(v14 → v15)
模式替换为
frappe.db.sql_list(...)frappe.db.get_all(..., pluck="name")
Module Def 页面引用工作区配置
cur_page JS 引用frappe.router API
旧的调度器 tick 假设检查 60s 间隔的时间安排
常见补丁(v15 → v16)
模式替换为
doc_events 控制器覆盖hooks.py 中的 extend_doctype_class
覆盖方法中缺少 super()添加 super().method() 调用
frappe.utils.pdf.get_pdf()更新后的 PDF API
没有类型注解为公共方法添加类型提示

Agent 输出格式

始终按以下格式生成迁移输出:

## Migration Assessment

### Version Path
{source} → {target} (via {intermediate versions if any})

### Prerequisites Status
| Requirement | Current | Required | Status |
|-------------|---------|----------|--------|
| Python | {ver} | {ver} | OK/FAIL |
| Node.js | {ver} | {ver} | OK/FAIL |
| MariaDB | {ver} | {ver} | OK/FAIL |

### Breaking Changes Found: {count}
[List from Step 2]

### Custom Code Issues Found: {count}
[Table from Step 3 scan]

### Migration Plan
[From Step 4]

### Patch List
[From Step 5]

### Risk Assessment
| Risk | Likelihood | Impact | Mitigation |
|------|-----------|--------|------------|

### Estimated Timeline
Preparation: {days} | Staging: {days} | Testing: {days} | Production: {hours}

### Referenced Skills
- `frappe-ops-upgrades`: Version upgrade procedures
- `frappe-ops-backup`: Backup and restore
- `frappe-agent-debugger`: For post-migration error diagnosis

请参阅 references/checklists.md 获取完整的迁移检查清单。 请参阅 references/breaking-changes.md 获取完整的破坏性变更数据库。

评论

支持 Markdown