# 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:


for example:


# Structure

Migrations have to export an up and a down function. These functions get a Knex (opens new window) instance that can be used to do virtually whatever.

module.exports = {
	async up(knex) {
		await knex.schema.createTable('test', (table) => {

	async down(knex) {
		await knex.schema.dropTable('test');


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.

Last Updated: 10/26/2021, 1:19:23 AM