Skip to main content

Migrations

There are 2 types of migrations:

  • system
  • user migrations

System Migrations

System migrations must be run in order to use the app. System migrations are always executed first, before user migrations. If you want to run pending system migrations every time app starts, pass true to autoRunMigrations in migrations config.

await runServer({
migrations: { autoRunMigrations: true },
})

User migration

User is able to provide custom migrations that will be executed after system migrations. To generate migration:

npx zmaj create-migration my_migration_name

This will create file with name, up and down migrations. Zmaj will use exported name to sort migrations. To run this migration you need to import it into this app. User migrations are run only if both autoRunMigrations and autoRunUserMigrations are true. It's currently not possible to run them with CLI.

import * as MyMigration from "2023_01_03_20_12_36__my_migration.js"
runServer({
migrations: {
autoRunMigrations: true,
autoRunUserMigrations: true,
migrations: [MyMigration],
},
})