db Commands - Medusa CLI Reference

Commands in the Medusa CLI starting with db: perform actions on the database.

db:setup#

Creates a database for the Medusa application with the specified name, if it doesn't exist. Then, it runs migrations and syncs links.

It also updates your .env file with the database name.

Tip: Use this command if you're setting up a Medusa project or database manually.

Options#

Option

Description

Required

Default

--db <name>

The database name.

Yes

-

--skip-links

Skip syncing links to the database.

No

Links are synced by default.

--execute-safe-links

Skip prompts when syncing links and execute only safe actions.

No

Prompts are shown for unsafe actions, by default.

--execute-all-links

Skip prompts when syncing links and execute all (including unsafe) actions.

No

Prompts are shown for unsafe actions, by default.

--no-interactive

Disable the command's prompts.

No

-

--skip-search

Skip creating, altering, and dropping search indexes. This option is added starting from Medusa v2.21.1.

No

The command migrates search indexes by default if your application registers the Search Module, which is the default since Medusa v2.21.1.

--execute-safe-search

Skip prompts when migrating search indexes and leave every index that no definition declares any more in place. This option is added starting from Medusa v2.21.1.

No

Prompts are shown for unsafe actions, by default.

--execute-all-search

Skip prompts when migrating search indexes and drop every index that no definition declares any more. This option is added starting from Medusa v2.21.1.

No

Prompts are shown for unsafe actions, by default.


db:create#

Creates a database for the Medusa application with the specified name, if it doesn't exist.

It also updates your .env file with the database name.

Tip: Use this command if you want to only create a database.

Options#

Option

Description

Required

Default

--db <name>

The database name.

Yes

-

--no-interactive

Disable the command's prompts.

No

-


db:generate#

Generate a migration file for the latest changes in one or more modules.

Arguments#

Argument

Description

Required

module_names

The name of one or more modules (separated by spaces) to generate migrations for. For example, brand.

Yes


db:migrate#

Run the latest migrations to reflect changes on the database, sync link definitions with the database, and run migration data scripts.

Tip: Use this command if you've updated the Medusa packages, or you've created customizations and want to reflect them in the database.

Options#

Option

Description

Required

Default

--skip-links

Skip syncing links to the database.

No

Links are synced by default.

--skip-scripts

Skip running data migration scripts. This option is added starting from Medusa v2.3.0.

No

Data migration scripts are run by default starting from Medusa v2.3.0.

--execute-safe-links

Skip prompts when syncing links and execute only safe actions.

No

Prompts are shown for unsafe actions, by default.

--execute-all-links

Skip prompts when syncing links and execute all (including unsafe) actions.

No

Prompts are shown for unsafe actions, by default.

--skip-search

Skip creating, altering, and dropping search indexes. This option is added starting from Medusa v2.21.1.

No

The command migrates search indexes by default if your application registers the Search Module, which is the default since Medusa v2.21.1.

--execute-safe-search

Skip prompts when migrating search indexes and leave every index that no definition declares any more in place. This option is added starting from Medusa v2.21.1.

No

Prompts are shown for unsafe actions, by default.

--execute-all-search

Skip prompts when migrating search indexes and drop every index that no definition declares any more. This option is added starting from Medusa v2.21.1.

No

Prompts are shown for unsafe actions, by default.


db:migrate:search#

Create, alter, and drop the physical search indexes that match the search index definitions in your application. The db:migrate command runs this command for you if your application registers the Search Module, which is the default since Medusa v2.21.1. So, run it on its own to migrate the search indexes without touching the database.

Note: This command is available since Medusa v2.21.1. Learn more about index migrations in the Reindexing and Migrations guide.

The command prompts you to select which indexes to drop when no definition declares them any more. Pass one of the options below to skip the prompt, which you must do when you run the command in a CI pipeline or another environment without a terminal. Otherwise, the command leaves those indexes in place.

Options#

Option

Description

Required

Default

--execute-safe-search

Skip prompts and leave every index that no definition declares any more in place.

No

Prompts are shown for unsafe actions, by default.

--execute-all-search

Skip prompts and drop every index that no definition declares any more.

No

Prompts are shown for unsafe actions, by default.


db:rollback#

Revert the last migrations run on one or more modules.

Arguments#

Argument

Description

Required

module_names

The name of one or more modules (separated by spaces) to rollback their migrations for. For example, brand.

Yes


Sync the database with the link definitions in your application, including the definitions in Medusa's modules.

Options#

Option

Description

Required

Default

--execute-safe

Skip prompts when syncing links and execute only safe actions.

No

Prompts are shown for unsafe actions, by default.

--execute-all

Skip prompts when syncing links and execute all (including unsafe) actions.

No

Prompts are shown for unsafe actions, by default.


Reset the Database#

The Medusa CLI does not provide a dedicated command to drop or reset the database. To reset your database, drop it manually using PostgreSQL tools, then run db:setup to recreate and reinitialize it.

Warning: Dropping the database permanently deletes all data. Make sure to back up any data you want to keep before running these commands.

For example, using the psql command:

Terminal
❯psql -c "DROP DATABASE <db_name>;"

Then, run db:setup to create the database and run all migrations:

Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Medusa MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵