Development Resources

db Commands - Medusa CLI Reference

Commands 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 exit. Then, it runs migrations and syncs links.

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

Terminal
npx medusa db:setup --db <name>
TipUse this command if you're setting up a Medusa project or database manually.

Options#

OptionDescriptionRequiredDefault

--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

-

db:create#

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

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

Terminal
npx medusa db:create --db <name>
TipUse this command if you want to only create a database.

Options#

OptionDescriptionRequiredDefault

--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.

Terminal
npx medusa db:generate <module_names...>

Arguments#

ArgumentDescriptionRequired

module_names

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

Yes

db:migrate#

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

Terminal
npx medusa db:migrate
TipUse this command if you've updated the Medusa packages, or you've created customizations and want to reflect them in the database.

Options#

OptionDescriptionRequiredDefault

--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.

db:rollback#

Revert the last migrations ran on one or more modules.

Terminal
npx medusa db:rollback <module_names...>
ArgumentDescriptionRequired

module_names

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

Yes

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

Terminal
npx medusa db:sync-links

Options#

OptionDescriptionRequiredDefault

--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.

Was this page helpful?
Edit this page