Skip to content

Default Loader Plugin

The default loader plugin is responsible for importing migration files written in JavaScript or TypeScript. Migration files can be written using either CommonJS or ES Modules.

Supported extensions

The default loader plugin supports the following extensions:

  • .js - either CommonJS or ES Modules depending on your package.json’s type field
  • .cjs - CommonJS
  • .mjs - ES Modules
  • .ts - either CommonJS or ES Modules written in TypeScript
  • .cts - CommonJS written in TypeScript
  • .mts - ES Modules written in TypeScript

Supported exports

The default loader plugin supports the following exports:

ES Modules

Default export

Exporting a function as the default export.

import { database } from 'some-database';
export default async function someMigration() {
await database.query(...);
await database.query(...);
}

Named export

Exporting a function named up.

import { database } from 'some-database';
export const up = async () => {
await database.query(...);
await database.query(...);
};

CommonJS

module.exports

Exporting a function as the module.

const { database } = require('some-database');
module.exports = async function someMigration() {
await database.query(...);
await database.query(...);
}

exports.up

Exporting an up function.

const { database } = require('some-database');
exports.up = async () => {
await database.query(...);
await database.query(...);
};