docs: replace usages of migrations and links commands (#8894)
This commit is contained in:
1 parent
9b6c2e5efa
commit
8c82207a41
12 files changed
+39
-51
No files matched your search
@@ -17,7 +17,7 @@ A migration is a class created in a TypeScript or JavaScript file under a module
|
|||||||
|
|
||||||
## How to Write a Migration?
|
## How to Write a Migration?
|
||||||
|
|
||||||
The Medusa CLI tool provides a [migrations generate](!resources!/medusa-cli#migrations-generate) command to generate a migration for the specified modules' data models.
|
The Medusa CLI tool provides a [db:generate](!resources!/medusa-cli/commands/db#dbgenerate) command to generate a migration for the specified modules' data models.
|
||||||
|
|
||||||
Alternatively, you can manually create a migration file under the `migrations` directory of your module.
|
Alternatively, you can manually create a migration file under the `migrations` directory of your module.
|
||||||
|
|
||||||
@@ -51,8 +51,14 @@ In the example above, the `up` method creates the table `my_custom`, and the `do
|
|||||||
|
|
||||||
To run your migration, run the following command:
|
To run your migration, run the following command:
|
||||||
|
|
||||||
|
<Note>
|
||||||
|
|
||||||
|
This command also syncs module links. If you don't want that, use the `--skip-links` option.
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
This reflects the changes in the database as implemented in the migration's `up` method.
|
This reflects the changes in the database as implemented in the migration's `up` method.
|
||||||
@@ -58,14 +58,20 @@ In this example, you define a module link between the `hello` module's `MyCustom
|
|||||||
|
|
||||||
### 2. Sync Links
|
### 2. Sync Links
|
||||||
|
|
||||||
Medusa stores links as pivot tables in the database. So, to reflect your link in the database, run the `links sync` command:
|
Medusa stores links as pivot tables in the database. So, to reflect your link in the database, run the `db:sync-links` command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa links sync
|
npx medusa db:sync-links
|
||||||
```
|
```
|
||||||
|
|
||||||
Use this command whenever you make changes to your links. For example, run this command if you remove your link definition file.
|
Use this command whenever you make changes to your links. For example, run this command if you remove your link definition file.
|
||||||
|
|
||||||
|
<Note title="Tip">
|
||||||
|
|
||||||
|
You can also use the `db:migrate` command, which both runs the migrations and syncs the links.
|
||||||
|
|
||||||
|
</Note>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Define a List Link
|
## Define a List Link
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ A migration defines changes to be made in the database, such as create or update
|
|||||||
To generate a migration for the data models in your module, run the following command:
|
To generate a migration for the data models in your module, run the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations generate helloModuleService
|
npx medusa db:generate helloModuleService
|
||||||
```
|
```
|
||||||
|
|
||||||
The `migrations generate` command of the Medusa CLI accepts one or more module names (for example, `helloModuleService`) to generate the migration for.
|
The `db:generate` command of the Medusa CLI accepts one or more module names (for example, `helloModuleService`) to generate the migration for.
|
||||||
|
|
||||||
The above command creates a migration file at the directory `src/modules/hello/migrations` similar to the following:
|
The above command creates a migration file at the directory `src/modules/hello/migrations` similar to the following:
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ In the migration class, the `up` method creates the table `my_custom` and define
|
|||||||
To reflect the changes in the generated migration file, run the `migration` command:
|
To reflect the changes in the generated migration file, run the `migration` command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
If ran successfully, the `my_custom` table will be created in the database.
|
If ran successfully, the `my_custom` table will be created in the database.
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ So, add the following script in `package.json`:
|
|||||||
```json
|
```json
|
||||||
"scripts": {
|
"scripts": {
|
||||||
// ...
|
// ...
|
||||||
"predeploy": "medusa migrations run && medusa links sync"
|
"predeploy": "medusa db:migrate"
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ You can create a B2B module that adds necessary data models to represent a B2B c
|
|||||||
You can now run migrations with the following commands:
|
You can now run migrations with the following commands:
|
||||||
|
|
||||||
```bash npm2yarn
|
```bash npm2yarn
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add Create Company API Route
|
### Add Create Company API Route
|
||||||
|
|||||||
@@ -166,10 +166,10 @@ export const restockModelHighlights = [
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
You can now run the module's migrations with the following command:
|
You can now run the migrations with the following command:
|
||||||
|
|
||||||
```bash npm2yarn
|
```bash npm2yarn
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create Restock Notification API Route
|
### Create Restock Notification API Route
|
||||||
|
|||||||
@@ -264,21 +264,15 @@ This defines a link between `DigitalProductOrder` and the Order Module’s `Orde
|
|||||||
To create tables for the digital product data models in the database, start by generating the migrations for the Digital Product Module with the following command:
|
To create tables for the digital product data models in the database, start by generating the migrations for the Digital Product Module with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations generate digitalProductModuleService
|
npx medusa db:generate digitalProductModuleService
|
||||||
```
|
```
|
||||||
|
|
||||||
This generates a migration in the `src/modules/digital-product/migrations` directory.
|
This generates a migration in the `src/modules/digital-product/migrations` directory.
|
||||||
|
|
||||||
Then, reflect the migrations in the database with the following command:
|
Then, reflect the migrations and links in the database with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
|
||||||
|
|
||||||
Next, to reflect your links in the database, run the `links sync` command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npx medusa links sync
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -409,22 +409,16 @@ This defines a link between the Delivery Module’s `delivery` data model and th
|
|||||||
To create tables for the above data models in the database, start by generating the migrations for the Restaurant and Delivery Modules with the following commands:
|
To create tables for the above data models in the database, start by generating the migrations for the Restaurant and Delivery Modules with the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations generate restaurantModuleService
|
npx medusa db:generate restaurantModuleService
|
||||||
npx medusa migrations generate deliveryModuleService
|
npx medusa db:generate deliveryModuleService
|
||||||
```
|
```
|
||||||
|
|
||||||
This generates migrations in the `src/modules/restaurant/migrations` and `src/modules/delivery/migrations` directories.
|
This generates migrations in the `src/modules/restaurant/migrations` and `src/modules/delivery/migrations` directories.
|
||||||
|
|
||||||
Then, to reflect the migration in the database, run the following command:
|
Then, to reflect the migration and links in the database, run the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
|
||||||
|
|
||||||
Next, to reflect your links in the database, run the `links sync` command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npx medusa links sync
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -213,21 +213,15 @@ This adds a list link between the `Vendor` and `Order` data models, indicating t
|
|||||||
To create tables for the marketplace data models in the database, start by generating the migrations for the Marketplace Module with the following command:
|
To create tables for the marketplace data models in the database, start by generating the migrations for the Marketplace Module with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations generate marketplaceModuleService
|
npx medusa db:generate marketplaceModuleService
|
||||||
```
|
```
|
||||||
|
|
||||||
This generates a migration in the `src/modules/marketeplace/migrations` directory.
|
This generates a migration in the `src/modules/marketeplace/migrations` directory.
|
||||||
|
|
||||||
Then, to reflect the migration in the database, run the following command:
|
Then, to reflect the migration and links in the database, run the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
|
||||||
|
|
||||||
Next, to reflect your links in the database, run the `links sync` command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npx medusa links sync
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -252,21 +252,15 @@ This defines a list link to the `Order` data model since a subscription has mult
|
|||||||
To create a table for the `Subscription` data model in the database, start by generating the migrations for the Subscription Module with the following command:
|
To create a table for the `Subscription` data model in the database, start by generating the migrations for the Subscription Module with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations generate subscriptionModuleService
|
npx medusa db:generate subscriptionModuleService
|
||||||
```
|
```
|
||||||
|
|
||||||
This generates a migration in the `src/modules/subscriptions/migrations` directory.
|
This generates a migration in the `src/modules/subscriptions/migrations` directory.
|
||||||
|
|
||||||
Then, to reflect the migration in the database, run the following command:
|
Then, to reflect the migration and links in the database, run the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
|
||||||
|
|
||||||
Next, to reflect your links in the database, run the `links sync` command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npx medusa links sync
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ npm run build
|
|||||||
3. Run migrations:
|
3. Run migrations:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Create an admin user:
|
4. Create an admin user:
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ export const metadata = {
|
|||||||
|
|
||||||
If you run into errors after updating Medusa and its dependencies, it's highly recommended to check the Upgrade Guides if there is a specific guide for your version. These guides include steps required to perform after upgrading Medusa.
|
If you run into errors after updating Medusa and its dependencies, it's highly recommended to check the Upgrade Guides if there is a specific guide for your version. These guides include steps required to perform after upgrading Medusa.
|
||||||
|
|
||||||
If there's no upgrade guide for your version, make sure that you ran the `migrations` command in the root directory of your Medusa application:
|
If there's no upgrade guide for your version, make sure that you ran the `db:migrate` command in the root directory of your Medusa application:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx medusa migrations run
|
npx medusa db:migrate
|
||||||
```
|
```
|
||||||
|
|
||||||
This ensures your application has the latest database structure required. Then, try running your Medusa application again and check whether the same error occurs.
|
This ensures your application has the latest database structure required. Then, try running your Medusa application again and check whether the same error occurs.
|
||||||
Reference in new issue
Block a user