mirror of
https://github.com/directus/directus.git
synced 2026-02-04 14:45:03 -05:00
* WIP * updates * docs updates * structure * big structure update * docs module icon change * in-app docs nav * more content and structure changes * Remove redundant * Fix docs build in app Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
46 lines
979 B
Markdown
46 lines
979 B
Markdown
# Custom Migrations
|
|
|
|
> Directus allows adding custom migration files that run whenever the `directus database migrate:*` commands are
|
|
> executed. All migrations must reside in the `extensions/migrations` folder.
|
|
|
|
## File Name
|
|
|
|
The file name follows the following structure:
|
|
|
|
```
|
|
[identifier]-[name].js
|
|
```
|
|
|
|
for example:
|
|
|
|
```
|
|
20201202A-my-custom-migration.js
|
|
```
|
|
|
|
## Structure
|
|
|
|
Migrations have to export an `up` and a `down` function. These functions get a [Knex](http://knexjs.org) instance that
|
|
can be used to do virtually whatever.
|
|
|
|
```js
|
|
module.exports = {
|
|
async up(knex) {
|
|
await knex.schema.createTable('test', (table) => {
|
|
table.increments();
|
|
table.string('rijk');
|
|
});
|
|
},
|
|
|
|
async down(knex) {
|
|
await knex.schema.dropTable('test');
|
|
},
|
|
};
|
|
```
|
|
|
|
::: danger Danger
|
|
|
|
Seeing that these migrations are a bit of a free-for-all, you can really harm your database. Please make sure you know
|
|
what you're doing and backup your database before adding these migrations.
|
|
|
|
:::
|