/frappe-apps-manager:frappe-data-migration-generatorfrom frappe-apps-manager
Generates data migration scripts for Frappe with validation, error handling, and progress tracking. Handles CSV/Excel imports and bulk data operations.
Ships in frappe-apps-manager. 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.
Generate robust data migration scripts with validation, error handling, and progress tracking for importing data into Frappe.
These Frappe conventions apply to everything this skill generates, and override any conflicting example below.
bench (never ./env/bin/bench or a full path). Always pass --site <site> explicitly — never run a bare bench migrate / bench run-tests. Run bench start in the background and only if it isn't already running. Don't run discovery commands (which bench, bench --version).apps/<app>/<app>/<module>/doctype/<name>/<name>.json — the app name appears twice (directory + Python package) — with an empty __init__.py alongside. Never mkdir the folder; write the JSON and run bench --site <site> migrate to create the structure. Don't add creation, modified, owner, modified_by, or docstatus as fields — Frappe manages them.frappe.qb.get_query() over raw frappe.db.sql(). Use frappe.db.get_all() for server logic (ignores permissions) and frappe.db.get_list() for user-facing APIs (enforces them). Never use frappe.db.set_value() on a field with validation or lifecycle logic — load the doc and doc.save() so controller hooks run. Batch-fetch related records; never query inside a loop (N+1).frappe.db.commit() in controllers, request handlers, background jobs, or patches — Frappe auto-commits on success and rolls back on uncaught errors. Flush manually only to make a write visible to a subsequent frappe.enqueue() (or pass enqueue_after_commit=True).@frappe.whitelist() parameter so Frappe validates and casts it, and pass methods=[...] to pin the HTTP verb.Claude should invoke this skill when:
Migrate through doc.save() so controller validation and lifecycle hooks run. Make the importer idempotent — guard each row with frappe.db.exists(...) (or a flag) so re-running doesn't create duplicates. Do not call frappe.db.commit() inside the loop: when this runs as a patch, a POST request, or a background job, Frappe auto-commits on success and auto-rolls-back on an uncaught error. Reserve frappe.db.set_value() for derived/cached/counter fields with no validation.
Production-Ready CSV Importer:
import csv
import frappe
from frappe.utils import flt, cint, getdate
def import_customers_from_csv(file_path):
"""Import customers — validated, idempotent, no manual commit"""
success = []
errors = []
with open(file_path, 'r', encoding='utf-8-sig') as f:
reader = csv.DictReader(f)
for idx, row in enumerate(reader, start=2):
try:
# Validate required fields
if not row.get('Customer Name'):
raise ValueError('Customer name required')
# Transform data
customer = {
'doctype': 'Customer',
'customer_name': row['Customer Name'].strip(),
'customer_group': row.get('Customer Group', 'Commercial'),
'territory': row.get('Territory', 'All Territories'),
'email_id': row.get('Email', '').strip(),
'mobile_no': row.get('Phone', '').strip(),
'credit_limit': flt(row.get('Credit Limit', 0))
}
# Idempotency guard — skip/update existing instead of duplicating
existing = frappe.db.exists('Customer',
{'customer_name': customer['customer_name']})
if existing:
doc = frappe.get_doc('Customer', existing)
doc.update(customer)
doc.save() # runs validate() + lifecycle hooks
else:
doc = frappe.get_doc(customer)
doc.insert() # runs validate() + lifecycle hooks
success.append(row['Customer Name'])
except Exception as e:
# Row failure is recorded; the surrounding transaction
# auto-rolls-back only on an uncaught error.
errors.append({'row': idx, 'data': row, 'error': str(e)})
# No frappe.db.commit() — Frappe auto-commits on successful completion.
return {'success': success, 'errors': errors}
Patches run inside a managed transaction: Frappe auto-commits after a successful execute() and auto-rolls-back on error. Don't sprinkle frappe.db.commit(). Prefer the ORM / query builder over raw SQL, and batch-fetch lookups to avoid N+1.
import frappe
def execute():
"""Backfill customer_group — idempotent, ORM-based, no manual commit."""
rows = frappe.db.get_all(
"Customer",
filters={"customer_group": ["in", ["", None]]},
fields=["name", "territory"],
)
if not rows:
return # already migrated — safe to re-run
# Batch-fetch the territory -> default group map (avoid querying in the loop)
territory_ids = {r.territory for r in rows if r.territory}
group_map = {
t.name: t.default_customer_group
for t in frappe.db.get_all(
"Territory",
filters={"name": ["in", list(territory_ids)]},
fields=["name", "default_customer_group"],
)
}
for row in rows:
group = group_map.get(row.territory) or "Commercial"
# Has validation/lifecycle → go through the doc so hooks run
doc = frappe.get_doc("Customer", row.name)
doc.customer_group = group
doc.save()
# auto-commit on successful execute(); no frappe.db.commit() here
For a derived/cached field with no validation, a single bulk UPDATE via the query builder is preferable to looping:
# Bulk UPDATE via frappe.qb (preferred over raw frappe.db.sql("UPDATE ..."))
Customer = frappe.qb.DocType("Customer")
(
frappe.qb.update(Customer)
.set(Customer.customer_group, "Commercial")
.where(Customer.customer_group.isin(["", None]))
).run()
If you keep ANY manual commit, restrict it to a deliberate checkpoint in a long standalone backfill (run outside a request, where a mid-way crash would otherwise lose hours of work) and say why — the default is no manual commit.
Stream rows instead of loading them all into memory: combine frappe.db.unbuffered_cursor() with query.run(as_iterator=True).
def backfill_large_table():
query = frappe.qb.get_query(
"Sales Invoice",
fields=["name", "customer"],
filters={"customer_group": ["in", ["", None]]},
)
with frappe.db.unbuffered_cursor():
for row in query.run(as_iterator=True, as_dict=True):
process(row)
Frappe Data Import:
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
16 skills in this plugin
/frappe-api-handlerCreate custom API endpoints and whitelisted methods for Frappe applications. Use when building REST APIs or custom endpoints./frappe-client-script-generatorGenerate JavaScript client-side form scripts for Frappe DocTypes. Use when creating form customizations, field validations, custom buttons, or client-side logic for Frappe/ERPNext forms./frappe-doctype-architectPlan and design a DocType architecture / data model for a new Frappe feature like a seasoned lead developer — interview the user, map entities, propose DocType names and links, and draw a flowchart of how the doctypes connect. Use this skill when the user says any of "help me plan a doctype architecture", "design a data model for", "what doctypes do I need for", "model a feature", "I want to build <feature>", "I need to implement an evaluation system", "issuing certificates", "design the schema for", "how should I structure my doctypes", "map the entities for", "plan the doctypes for a <X> system" (CRM, helpdesk, ticketing, LMS, booking, approval, subscription, inventory, etc.). It GRILLS the user with staged questions, proposes sensible defaults, keeps a running model, scans the existing app codebase to REUSE or EXTEND existing doctypes (adding fields / Custom Fields) before creating new ones, then produces a Mermaid diagram + per-DocType spec tables and offers to hand off to frappe-doctype-builder to generate the JSON. This skill PLANS only — it does not write files. Also use it when the user asks "can I reuse/extend an existing doctype for this?" or "is there already a doctype for X?"./frappe-doctype-builderBuild Frappe DocTypes with fields, permissions, and naming configurations. Use this skill when creating or modifying DocType structures./frappe-documentation-generatorGenerate API documentation, user guides, and technical documentation for Frappe apps. Use when documenting APIs, creating user guides, or generating OpenAPI specs./frappe-external-api-connectorGenerate code to integrate Frappe with external REST APIs. Use when connecting to third-party services, payment gateways, or external data sources.npx claudepluginhub venkateshvenki404224/frappe-apps-manager --plugin frappe-apps-managerOther plugins' skills for the same job