Back to Strapi

Migrations

docs/docs/docs/01-core/database/03-migrations.md

5.52.2789 B
Original Source

Strapi manages schema and data migrations in multiple ways. As much as possible we try to automatically sync the DB schema with the application configuration. However this in not sufficient to manage data migrations or schema migrations that are not reconcilable.

Internal migrations

Creating a migration

  • Add a migration file in packages/core/database/src/migrations/internal-migrations
  • Import it in the index.ts file of the same folder and add it to the exported array as the last element.

Migration file format

Every migration should follow this API

ts
export default {
  name: 'name-of-migration',
  async up(knex: Knex, db: Database): void {},
  async down(knex: Knex, db: Database): void {},
};