This package provides a plugin for `db-migrate` that enables the use of TypeScript for database migration files. It automatically transpiles `.ts` files found in the migration directory using your project's `tsconfig.json`. The current stable version is 2.0.0, released in December 2017. As a plugin, its release cadence is tied to the `db-migrate` ecosystem, but its own updates have been infrequent. Key differentiators include seamless integration with `db-migrate` for TypeScript-based migrations, leveraging existing `tsconfig.json` configurations, and simplifying database schema management for TypeScript projects without requiring manual transpilation steps. It requires `ts-node` as a peer dependency for runtime TypeScript compilation.
npm install db-migrate-plugin-typescriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure `tsconfig.json` for TypeScript migrations and provides an example of a `.ts` migration file. It also shows the npm commands to install the plugin and `ts-node`.
Explicitly install `ts-node` as a direct or dev dependency: `npm install ts-node` or `yarn add ts-node`.
After running `db-migrate create MyMigration`, manually rename the generated JavaScript file (e.g., `MyMigration.js`) to a TypeScript file (e.g., `MyMigration.ts`) and convert its contents to TypeScript.
Test thoroughly with your current environment (Node.js, TypeScript, `db-migrate` versions). Be prepared for potential compatibility problems and consider contributing to the project or seeking alternatives if persistent issues arise.
Install `ts-node` explicitly: `npm install ts-node` or `yarn add ts-node`.
Ensure `db-migrate-plugin-typescript` is installed and listed in your `package.json`. Verify that your migration files are named with a `.ts` extension (e.g., `123456789_create_table.ts`).
Verify that `ts-node` is installed and that your `tsconfig.json` is correctly set up. Ensure `compilerOptions.module` is set to `"CommonJS"` (or compatible) if you are running Node.js in a CJS context, and `compilerOptions.esModuleInterop` is `true`.