Command line interface for Medusa Commerce platform with project creation, development server, and database management capabilities
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The Medusa CLI provides comprehensive database management capabilities including migration management and database seeding. These commands are only available within Medusa project directories and integrate with the local Medusa installation's database management system.
Manage database schema migrations for the Medusa project, including running, reverting, and viewing migration status.
medusa migrations [action]Parameters:
action (required): Migration action to perform
run: Execute pending migrationsrevert: Revert the most recent migrationshow: Display migration status and historyUsage Examples:
# Run all pending migrations
medusa migrations run
# Revert the last migration
medusa migrations revert
# Show migration status
medusa migrations showBehavior:
Populate the database with initial or sample data using custom seed files.
medusa seed --seed-file <path>Options:
-f, --seed-file <string> (required): Path to the seed file containing data and instructions-m, --migrate <boolean>: Run migrations before seeding (default: true)Usage Examples:
# Seed database with specific file
medusa seed --seed-file ./data/sample-products.js
# Seed without running migrations first
medusa seed --seed-file ./data/users.js --migrate false
# Seed with migrations (default behavior)
medusa seed -f ./data/store-setup.jsBehavior:
The migration system follows a structured execution pattern:
Run Migrations:
Revert Migrations:
Show Migration Status:
Migration files must follow Medusa's expected format:
File Location:
src/migrations/ or similar project structureFile Structure:
Seed files should be JavaScript modules that export seeding logic:
Basic Structure:
// Example seed file structure
module.exports = async (container) => {
const productService = container.resolve("productService");
// Seeding logic here
await productService.create({
title: "Sample Product",
// ... other product data
});
};Container Access:
The seeding process follows these steps:
Database operations use the project's existing configuration:
Configuration Sources:
Connection Handling:
Database commands respect environment settings:
NODE_ENV Handling:
Database Selection:
The migration system includes comprehensive error handling:
Pre-execution Validation:
Runtime Error Handling:
Recovery Mechanisms:
Database seeding includes robust error handling:
File Validation:
Execution Monitoring:
Database commands are proxied to the local Medusa installation:
Dynamic Loading:
@medusajs/medusa/dist/commands/Argument Forwarding: