mongoose-to-prisma

Migrate a single Mongoose model file to Prisma extensions following GROWI's incremental migration patterns.

1.5k|244|Updated Feb 16, 2017
One-click install
npx skills add https://github.com/growilabs/growi --skill mongoose-to-prisma
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mongoose-to-prisma
Source: https://github.com/growilabs/growi/tree/main/.claude/skills/mongoose-to-prisma
Command: npx skills add https://github.com/growilabs/growi --skill mongoose-to-prisma

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrating a large codebase from Mongoose to Prisma one model at a time is error-prone: indexes can silently disappear, relation optionality can cause production 500s, and API response shapes can break the frontend. This Skill walks a developer through migrating one Mongoose model file to Prisma extensions with human approval at every stage, following GROWI's established conventions.

Core Features & Use Cases

  • Guided six-step migration: Analyzes the model (fields, statics, virtuals, hooks, plugins, callers), verifies schema.prisma, generates a Prisma extension, updates callers, reviews tests, and cleans up superseded Mongoose code.
  • Backward compatibility handling: Preserves _id/__v computed fields, remaps renamed relation fields (e.g. ownerId back to owner) in API responses, and keeps the Mongoose schema block so autoIndex continues creating indexes.
  • Edge-case detection: Flags sparse indexes needing migrate-mongo migrations, hard-delete paths that force optional relations, factory-pattern crowi dependencies, and __v behavior changes.
  • Use Case: Run it on apps/app/src/server/models/tag.ts to produce a Prisma extension, updated callers, and a cleaned-up model file, with a diff review and approval gate before every write.

Quick Start

Ask the AI to migrate the Mongoose model at apps/app/src/server/models/tag.ts to Prisma using this skill, then approve each proposed step as it is presented.

Frequently Asked Questions about mongoose-to-prisma

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate a Mongoose model to Prisma in GROWI?

Invoke the skill with the path to one Mongoose model file, such as /mongoose-to-prisma apps/app/src/server/models/tag.ts. It analyzes the model, verifies schema.prisma, generates a Prisma extension, updates callers, and cleans up Mongoose code, asking for your approval before each write.

How are Mongoose statics and virtuals converted to Prisma?

Statics become methods inside a Prisma.defineExtension model block, using context.findMany, context.findUnique, and context.count. Virtuals become result compute aliases whose needs list every scalar field the getter reads.

Does Prisma support sparse indexes when migrating from Mongoose?

No, Prisma does not support sparse indexes. The skill flags any sparse index and proposes a migrate-mongo migration using the native MongoDB driver's collection.createIndex with the sparse option, plus a comment in schema.prisma.

Why keep the Mongoose schema block after migrating to Prisma?

Mongoose's autoIndex still creates the model's indexes on connect, so the schema block is kept until all models have migrated. Deleting it early requires an explicit migrate-mongo migration to recreate the indexes, or they silently stop existing.

Should Prisma relations be required or optional when migrating from Mongoose?

Decide by checking whether the referenced model has a hard-delete path that leaves orphans, not by copying Mongoose's required flag. If hard deletes can leave dangling references, make the relation optional to avoid runtime 'Inconsistent query result' errors.

What are the limitations of this Mongoose to Prisma migration skill?

It handles only one model file per invocation, never modifies frontend code, and never runs prisma db push or prisma generate. Factory-pattern models that depend on the crowi instance require a case-by-case design decision with the developer.