Skip to content

db-migrate/plugin-typescript

Repository files navigation

Plugin-Typescript

A TypeScript plugin for db-migrate.

Usage

Usage is very simple. Simply install this plugin via npm install db-migrate-plugin-typescript or if using yarn: yarn add db-migrate-plugin-typescript

This plugin has a peer dependency on ts-node as well. So you will need to install that as a dependency or dev-dependency as well, npm install ts-node or yarn add ts-node if using yarn.

The plugin will automatically resolve and compile any .ts files in your migrations directory, using your regular tsconfig.json

Do however note that this has no effect on generating new migrations. Using db-migrate create FooMigrations.ts will not create a TypeScript migration file.

Implementation Detail

The plugin hooks into the functionality of db-migrate itself. In this case it hooks into migrator:migration:hook:require, which in this case requires another transpiler (TypeScript) and registers also a new file extension (.ts). Make sure to name your migrations accordingly (ending with .ts).