docs: add missing details related to links and migrations (#11809)

* docs: add missing details related to links and migrations

* reorder content

* small changes

* last changes

* improve examples

* fix lint error
This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-03-11 16:22:52 +02:00
1 parent de213a8aa9
commit e0277e375e
9 files changed
+8738 -8518

No files matched your search

@@ -23,17 +23,17 @@ Alternatively, you can manually create a migration file under the `migrations` d
For example:
```ts title="src/modules/hello/migrations/Migration20240429.ts"
```ts title="src/modules/blog/migrations/Migration20240429.ts"
import { Migration } from "@mikro-orm/migrations"
export class Migration20240702105919 extends Migration {
async up(): Promise<void> {
this.addSql("create table if not exists \"my_custom\" (\"id\" text not null, \"name\" text not null, \"created_at\" timestamptz not null default now(), \"updated_at\" timestamptz not null default now(), \"deleted_at\" timestamptz null, constraint \"my_custom_pkey\" primary key (\"id\"));")
this.addSql("create table if not exists \"author\" (\"id\" text not null, \"name\" text not null, \"created_at\" timestamptz not null default now(), \"updated_at\" timestamptz not null default now(), \"deleted_at\" timestamptz null, constraint \"author_pkey\" primary key (\"id\"));")
}
async down(): Promise<void> {
this.addSql("drop table if exists \"my_custom\" cascade;")
this.addSql("drop table if exists \"author\" cascade;")
}
}
@@ -43,7 +43,7 @@ The migration's file name should be of the format `Migration{YEAR}{MONTH}{DAY}.t
In the `up` and `down` method of the migration class, you use the `addSql` method provided by MikroORM's `Migration` class to run PostgreSQL syntax.
In the example above, the `up` method creates the table `my_custom`, and the `down` method drops the table if the migration is reverted.
In the example above, the `up` method creates the table `author`, and the `down` method drops the table if the migration is reverted.
<Note title="Tip">
@@ -76,10 +76,18 @@ This reflects the changes in the database as implemented in the migration's `up`
To rollback or revert the last migration you ran for a module, run the following command:
```bash
npx medusa db:rollback helloModuleService
npx medusa db:rollback blog
```
This rolls back the last ran migration on the Hello Module.
This rolls back the last ran migration on the Blog Module.
### Caution: Rollback Migration before Deleting
If you need to delete a migration file, make sure to rollback the migration first. Otherwise, you might encounter issues when generating and running new migrations.
For example, if you delete the migration of the Blog Module, then try to create a new one, Medusa will create a brand new migration that re-creates the tables or indices. If those are still in the database, you might encounter errors.
So, always rollback the migration before deleting it.
---