home / skills / medusajs / medusa-agent-skills / db-generate

This skill generates Medusa module migrations by running npx medusa db:generate for a given module and reports results and next steps.

npx playbooks add skill medusajs/medusa-agent-skills --skill db-generate

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
768 B
---
name: db-generate
description: Generate database migrations for a Medusa module
argument-hint: <module-name>
allowed-tools: Bash(npx medusa db:generate:*)
---

# Generate Database Migrations

Generate database migrations for the specified Medusa module.

The user will provide the module name as an argument (e.g., `brand`, `product`, `custom-module`).

For example: `/medusa-dev:db-generate brand`

Use the Bash tool to execute the command `npx medusa db:generate <module-name>`, replacing `<module-name>` with the provided argument.

Report the results to the user, including:

- The module name for which migrations were generated
- Migration file name or location
- Any errors or warnings
- Next steps (running `npx medusa db:migrate` to apply the migrations)

Overview

This skill generates database migrations for a specified Medusa module. It runs the Medusa CLI command to create migration files and reports the outcome, including file names, locations, and any errors. It also provides clear next steps to apply the generated migrations.

How this skill works

You provide the module name as an argument and the skill executes: npx medusa db:generate <module-name>. The skill captures the CLI output, extracts the generated migration file name or path, and surfaces any errors or warnings. Finally, it summarizes results and recommends running npx medusa db:migrate to apply changes.

When to use it

  • When you added or changed database models inside a Medusa module
  • Before deploying code that depends on new or modified schema
  • When preparing staged or production database updates
  • To verify what migration files will be created for a module

Best practices

  • Run the generate command from your Medusa project root where package.json is located
  • Use a descriptive module name that matches your Medusa service folder
  • Review the generated migration file for correctness before applying
  • Commit migration files to version control and include migration in deployment checklist
  • Run migrations in a safe environment (staging) before production

Example use cases

  • Creating migrations after adding a new Product attribute in the product module
  • Generating migration files for a custom-module that adds new tables
  • Verifying migration output when refactoring entity fields in brand module
  • Preparing a release by generating and reviewing all module migrations

FAQ

What exact command does this skill run?

It runs npx medusa db:generate <module-name>, where you replace <module-name> with the module argument.

What do I do after migrations are generated?

Review the migration file, commit it, then run npx medusa db:migrate to apply changes to the database.