www/apps/resources/app/medusa-cli/commands/db/page.mdx
import { Table } from "docs-ui"
export const metadata = {
title: db Commands - Medusa CLI Reference,
}
Commands in the Medusa CLI starting with db: perform actions on the database.
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.
npx medusa db:setup --db <name>
Use this command if you're setting up a Medusa project or database manually.
</Note> `--db <name>`
</Table.Cell>
<Table.Cell>
The database name.
</Table.Cell>
<Table.Cell>
Yes
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--skip-links`
</Table.Cell>
<Table.Cell>
Skip syncing links to the database.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Links are synced by default.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--execute-safe-links`
</Table.Cell>
<Table.Cell>
Skip prompts when syncing links and execute only safe actions.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Prompts are shown for unsafe actions, by default.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--execute-all-links`
</Table.Cell>
<Table.Cell>
Skip prompts when syncing links and execute all (including unsafe) actions.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Prompts are shown for unsafe actions, by default.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--no-interactive`
</Table.Cell>
<Table.Cell>
Disable the command's prompts.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>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.
npx medusa db:create --db <name>
Use this command if you want to only create a database.
</Note> `--db <name>`
</Table.Cell>
<Table.Cell>
The database name.
</Table.Cell>
<Table.Cell>
Yes
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--no-interactive`
</Table.Cell>
<Table.Cell>
Disable the command's prompts.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
\-
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>Generate a migration file for the latest changes in one or more modules.
npx medusa db:generate <module_names...>
`module_names`
</Table.Cell>
<Table.Cell>
The name of one or more modules (separated by spaces) to generate migrations for. For example, `brand`.
</Table.Cell>
<Table.Cell>
Yes
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>Run the latest migrations to reflect changes on the database, sync link definitions with the database, and run migration data scripts.
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.
</Note> `--skip-links`
</Table.Cell>
<Table.Cell>
Skip syncing links to the database.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Links are synced by default.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--skip-scripts`
</Table.Cell>
<Table.Cell>
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).
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Data migration scripts are run by default starting from
[Medusa v2.3.0](https://github.com/medusajs/medusa/releases/tag/v2.3.0).
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--execute-safe-links`
</Table.Cell>
<Table.Cell>
Skip prompts when syncing links and execute only safe actions.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Prompts are shown for unsafe actions, by default.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--execute-all-links`
</Table.Cell>
<Table.Cell>
Skip prompts when syncing links and execute all (including unsafe) actions.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Prompts are shown for unsafe actions, by default.
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>Revert the last migrations run on one or more modules.
npx medusa db:rollback <module_names...>
`module_names`
</Table.Cell>
<Table.Cell>
The name of one or more modules (separated by spaces) to rollback their migrations for. For example, `brand`.
</Table.Cell>
<Table.Cell>
Yes
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>Sync the database with the link definitions in your application, including the definitions in Medusa's modules.
npx medusa db:sync-links
`--execute-safe`
</Table.Cell>
<Table.Cell>
Skip prompts when syncing links and execute only safe actions.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Prompts are shown for unsafe actions, by default.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`--execute-all`
</Table.Cell>
<Table.Cell>
Skip prompts when syncing links and execute all (including unsafe) actions.
</Table.Cell>
<Table.Cell>
No
</Table.Cell>
<Table.Cell>
Prompts are shown for unsafe actions, by default.
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>