mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 16:37:56 +00:00
ad4929e48b
* Turkish language created for Docs. Belgeler için türkçe dil desteği oluşturuldu. * Turkish docs fix
51 lines
1.2 KiB
Markdown
51 lines
1.2 KiB
Markdown
# Database Migration
|
|
|
|
There may be some incompatible changes during the plugin update iteration, these incompatible upgrade scripts can be handled by writing migration files.
|
|
|
|
## How to add a migration file?
|
|
|
|
```ts
|
|
export class MyPlugin extends Plugin {
|
|
load() {
|
|
// Load a single Migration file
|
|
this.db.addMigration();
|
|
// Load multiple Migration files
|
|
this.db.addMigrations();
|
|
}
|
|
}
|
|
```
|
|
|
|
API reference.
|
|
|
|
- [db.addMigration()](/api/database#addmigration)
|
|
- [db.addMigrations()](/api/database#addmigrations)
|
|
|
|
## When to execute?
|
|
|
|
```bash
|
|
## When the app is upgraded, migrator.up() and db.sync() are executed
|
|
yarn nocobase upgrade
|
|
# Trigger migration separately
|
|
yarn nocobase migrator up
|
|
```
|
|
|
|
## When do I need to write a migration file?
|
|
|
|
It is usually used to update the system configuration stored in the database during the upgrade process. If it is just a collection configuration change, you don't need to configure migration, just execute ``yarn nocobase db:sync`` to synchronize to the database.
|
|
|
|
## Migration file
|
|
|
|
```ts
|
|
import { Migration } from '@nocobase/server';
|
|
|
|
export default class CustomMigration extends Migration {
|
|
async up() {
|
|
//
|
|
}
|
|
|
|
async down() {
|
|
//
|
|
}
|
|
}
|
|
```
|