--- sidebar_label: "db" sidebar_position: 5 --- import { Table } from "docs-ui" export const metadata = { title: `db Commands - Medusa CLI Reference`, } # {metadata.title} 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. ```bash npx medusa db:setup --db ``` Use this command if you're setting up a Medusa project or database manually. ### Options Option Description Required Default `--db ` 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. ```bash npx medusa db:create --db ``` Use this command if you want to only create a database. ### Options Option Description Required Default `--db ` 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. ```bash npx medusa db:generate ``` ### Arguments Argument Description Required `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, sync link definitions with the database, and run migration data scripts. ```bash npx medusa db:migrate ``` 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](https://github.com/medusajs/medusa/releases/tag/v2.3.0). No Data migration scripts are run by default starting from [Medusa v2.3.0](https://github.com/medusajs/medusa/releases/tag/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.
--- ## db\:rollback Revert the last migrations ran on one or more modules. ```bash npx medusa db:rollback ``` ### Arguments Argument Description Required `module_names` The name of one or more module (separated by spaces) to rollback their migrations for. For example, `helloModuleService`. Yes
--- ## db\:sync-links Sync the database with the link definitions in your application, including the definitions in Medusa's modules. ```bash npx medusa db:sync-links ``` ### 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.