{"id":14524,"library":"db-migrate-plugin-typescript","title":"DB Migrate TypeScript Plugin","description":"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.","status":"maintenance","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/db-migrate/plugin-typescript","tags":["javascript","dbmigrate","db-migrate","db","migrate","migration","migrator","database","sql"],"install":[{"cmd":"npm install db-migrate-plugin-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add db-migrate-plugin-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add db-migrate-plugin-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for runtime TypeScript compilation of migration files by db-migrate.","package":"ts-node","optional":false}],"imports":[{"note":"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.","symbol":"db-migrate-plugin-typescript","correct":"npm install db-migrate-plugin-typescript ts-node"},{"note":"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.","symbol":"Migration interface","correct":"import { Migration } from 'db-migrate';"}],"quickstart":{"code":"{\n  \"compilerOptions\": {\n    \"target\": \"ESNext\",\n    \"module\": \"CommonJS\",\n    \"esModuleInterop\": true,\n    \"strict\": true,\n    \"outDir\": \"./dist\",\n    \"rootDir\": \"./migrations\"\n  },\n  \"include\": [\"./migrations/**/*.ts\"]\n}\n\n// migrations/1678886400000_create_users_table.ts\nimport { Migration } from 'db-migrate';\n\nexport const up: Migration = async (db) => {\n  await db.createTable('users', {\n    id: { type: 'int', primaryKey: true, autoIncrement: true },\n    name: { type: 'string', length: 50, notNull: true },\n    email: { type: 'string', length: 100, notNull: true, unique: true },\n    created_at: { type: 'timestamp', notNull: true, defaultValue: new Date() }\n  });\n};\n\nexport const down: Migration = async (db) => {\n  await db.dropTable('users');\n};\n\n// To install: npm install db-migrate db-migrate-plugin-typescript ts-node @types/db-migrate --save-dev\n// To run: db-migrate up","lang":"typescript","description":"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`."},"warnings":[{"fix":"Explicitly install `ts-node` as a direct or dev dependency: `npm install ts-node` or `yarn add ts-node`.","message":"In 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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"The `db-migrate create <name>` command does not generate TypeScript files. It will create a `.js` file, even with this plugin installed.","severity":"gotcha","affected_versions":"*"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'2.0.0':44 '2017':48 'automat':25 'base':82 'cadenc':54 'compil':113 'configur':87 'current':40 'databas':21,90,123 'db':1,12,60,77,117,119 'db-migrat':11,59,76,116 'dbmigrat':115 'decemb':47 'depend':109 'differenti':71 'directori':33 'ecosystem':62 'enabl':15 'exist':85 'file':23,28 'found':29 'includ':72 'infrequ':69 'integr':74 'javascript':114 'key':70 'leverag':84 'manag':92 'manual':98 'migrat':2,13,22,32,61,78,83,118,120,121,122 'node':105 'packag':6 'peer':108 'plugin':4,9,51 'project':36,95 'provid':7 'releas':45,53 'requir':97,102 'runtim':111 'schema':91 'seamless':73 'simplifi':89 'sql':124 'stabl':41 'step':100 'tie':56 'transpil':26,99 'ts':27,104 'ts-node':103 'tsconfig.json':38,86 'typescript':3,19,81,94,112 'typescript-bas':80 'updat':66 'use':17,34 'version':42 'without':96","created_at":"2026-04-20T18:42:14.654066+00:00","updated_at":"2026-04-20T18:42:14.654066+00:00","problems":[{"fix":"Install `ts-node` explicitly: `npm install ts-node` or `yarn add ts-node`.","cause":"The `ts-node` package, a peer dependency, is not installed in the project.","error":"Error: Cannot find module 'ts-node' from '<path>'"},{"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`).","cause":"The plugin might not be correctly recognized by `db-migrate`, or the migration file does not end with the expected `.ts` extension.","error":"Migration file '<filename>' not found or could not be loaded"},{"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`.","cause":"`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).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"db-migrate","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/db-migrate/plugin-typescript","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/db-migrate-plugin-typescript","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}