Load cjs custom migrations (#18385)

This commit is contained in:
Brainslug
2023-05-02 21:10:19 +02:00
committed by GitHub
parent 80bcc35af3
commit 1fba5ebf94
3 changed files with 23 additions and 12 deletions

View File

@@ -22,23 +22,27 @@ for example:
20201202A-my-custom-migration.js
```
::: tip
For backwards compatibility it is possible to rename your existing CommonJS migrations to `<migration-name>.cjs`. However using ESM where possible is recommended.
:::
## 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');
});
},
export async function up(knex) {
await knex.schema.createTable('test', (table) => {
table.increments();
table.string('rijk');
});
};
async down(knex) {
await knex.schema.dropTable('test');
},
export async function down(knex) {
await knex.schema.dropTable('test');
};
```