Registry / database / db-migrate-plugin-typescript

db-migrate-plugin-typescript

JSON →
library2.0.0jsnpmunverified

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-typescript
INSTALL
IMPORT
SIG · DB-MIGRATE-PLUGIN-
D
db-migrate-plugin-typescript
databasejavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

db-migrate-plugin-typescript
✓ npm install db-migrate-plugin-typescript ts-node
This package is a db-migrate plugin and is not directly imported into user code. It is loaded by db-migrate automatically once installed. Its primary interaction is via the file system for migration files and its configuration via tsconfig.json.
Migration interface
✓ import { Migration } from 'db-migrate';
While this plugin enables TypeScript, the core Migration interface comes from `db-migrate` itself (or its associated types). Ensure `@types/db-migrate` is installed if you want type checking within your migration files.

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`.

{ "compilerOptions": { "target": "ESNext", "module": "CommonJS", "esModuleInterop": true, "strict": true, "outDir": "./dist", "rootDir": "./migrations" }, "include": ["./migrations/**/*.ts"] } // migrations/1678886400000_create_users_table.ts import { Migration } from 'db-migrate'; export const up: Migration = async (db) => { await db.createTable('users', { id: { type: 'int', primaryKey: true, autoIncrement: true }, name: { type: 'string', length: 50, notNull: true }, email: { type: 'string', length: 100, notNull: true, unique: true }, created_at: { type: 'timestamp', notNull: true, defaultValue: new Date() } }); }; export const down: Migration = async (db) => { await db.dropTable('users'); }; // To install: npm install db-migrate db-migrate-plugin-typescript ts-node @types/db-migrate --save-dev // To run: db-migrate up
db-migrate --version
Debug
Known issues
breakingIn version 2.0.0, `ts-node` was changed from a direct dependency to a peer dependency. If you upgrade to v2.0.0 or later, `ts-node` must be explicitly installed in your project.
fix
Explicitly install `ts-node` as a direct or dev dependency: `npm install ts-node` or `yarn add ts-node`.
affects: >=2.0.0
gotchaThe `db-migrate create <name>` command does not generate TypeScript files. It will create a `.js` file, even with this plugin installed.
fix
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.
affects: *
gotchaThe last release (v2.0.0) was in December 2017. This may lead to compatibility issues with newer Node.js, TypeScript versions, or recent `db-migrate` updates.
fix
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.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'ts-node' from '<path>'
The `ts-node` package, a peer dependency, is not installed in the project.
fix
Install `ts-node` explicitly: `npm install ts-node` or `yarn add ts-node`.
Migration file '<filename>' not found or could not be loaded
The plugin might not be correctly recognized by `db-migrate`, or the migration file does not end with the expected `.ts` extension.
fix
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`).
SyntaxError: Cannot use import statement outside a module
`ts-node` or your `tsconfig.json` is misconfigured, preventing proper transpilation of ES module syntax to CommonJS (which Node.js typically expects outside of explicit ESM projects).
fix
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`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
ts-noderequiredRequired for runtime TypeScript compilation of migration files by db-migrate.
Agent activity
18 hits · last 30 days
node
14
Resources
db-migrate-plugin-typescript — npm install db-migrate-plugin-typescript · libregistry