Registry / database / prisma-data-migrations

prisma-data-migrations

JSON →
library1.6.0jsnpmunverified

Prisma Data Migrations is a library (v1.6.0) that fills the gap in Prisma ORM by adding support for post-migration data scripts alongside schema migrations. It provides a CLI tool for initializing configuration, generating typed migration contexts, and executing scripts within database transactions. Unlike Prisma's built-in migration system which only handles schema changes, this package enables data seeding, transformations, and cleanup after schema migrations. Active development with monthly releases. Key differentiator: seamless integration with Prisma's existing migration folder structure, TypeScript-first, and atomic transaction support.

npm install prisma-data-migrations
INSTALL
IMPORT
SIG · PRISMA-DATA-MIGRAT
P
prisma-data-migrations
databasejavascriptv1.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

PrismaClient
import { PrismaClient } from '@prisma/client'
import { PrismaClient } from 'prisma-data-migrations'
PrismaClient is always from @prisma/client, not from this package. The library only provides the generated migration types.
Prisma.TransactionClient
import { Prisma } from 'prisma-data-migrations/migrations/20250108201031_add_user_name'
import Prisma from '@prisma/client'
The generated namespace includes the transaction client type. Import from the specific migration folder after generating types.
data migration scripts
// Create a file named post.ts (or .js, .sh) in the migration folder // The library automatically picks up scripts named 'post' with any extension
// Naming the file migration.ts or data.ts - only post.* is recognized
The script must be named exactly 'post' (case-sensitive) plus an extension like .ts, .js, or .sh. Other names are ignored.

Shows full setup: install, init config, generate typed migrations, create a post-script with Prisma transaction, and execute via CLI.

// 1. Install npm install prisma-data-migrations --save-dev // 2. Initialize config npx prisma-dm init // 3. Generate types (after prisma migrate) npx prisma-dm generate // 4. Create post-migration script in prisma/migrations/<timestamp>_<name>/post.ts import { Prisma, PrismaClient } from 'prisma-data-migrations/migrations/20250108201031_add_user_name'; async function seedUsers(prisma: Prisma.TransactionClient) { await prisma.user.createMany({ data: [{ name: 'Alice' }, { name: 'Bob' }], skipDuplicates: true, }); } const prisma = new PrismaClient(); prisma.$transaction(seedUsers, { timeout: 30_000 }) .then(() => console.log('Migration done')) .catch((e) => { console.error(e); process.exit(1); }); // 5. Run migration with data scripts npx prisma-dm migrate
Debug
Known issues
gotchaPost-scripts must be wrapped in a transaction. If the script fails, you must manually reapply after fixing the issue.
fix
Always use prisma.$transaction() to wrap your migration logic. Use run:postscript command to re-run after failure.
affects: <=1.6.0
gotchaThe post-script file must be named exactly 'post' (case-sensitive) with any extension. Other names like 'migration.ts' or 'data.js' are ignored.
fix
Rename the script file to post.ts (or .js, .sh) in the migration folder.
affects: <=1.6.0
deprecatedThe merge:schema command is only needed if using prismaSchemaFolder feature; it may be removed in future versions.
fix
Skip this step if you don't use prismaSchemaFolder. Manual copying of schema.prisma is also supported.
affects: <=1.6.0
gotchaWhen using TypeScript post-scripts, you must have ts-node or tsx installed globally or as dev dependencies.
fix
Install ts-node: npm install ts-node --save-dev
affects: <=1.6.0
breakingImport paths changed in v1.3.0: previously generated types were under 'prisma-data-migrations/generated', now under 'prisma-data-migrations/migrations/<migration_id>'
fix
Update import paths to match the new pattern with the migration folder name.
affects: >=1.3.0
Errors
Common errors & fixes
Error: Cannot find module 'prisma-data-migrations/migrations/20250108201031_add_user_name'
Types not generated yet or import path incorrect.
fix
Run npx prisma-dm generate after creating migration folders.
Error: post script file not found at prisma/migrations/20250108201031_add_user_name/post.ts
File must be named exactly 'post' with correct extension.
fix
Rename your script to post.ts (or .js, .sh) and place it directly in the migration folder.
Error: prisma-dm is not recognized as an internal or external command
Package not installed or not in PATH.
fix
Install locally: npm install prisma-data-migrations --save-dev, then use npx prisma-dm.
TypeError: Cannot read properties of undefined (reading 'user')
Transaction context not used correctly; plain PrismaClient used instead of TransactionClient.
fix
Access models via the prisma parameter inside the transaction callback, not via the outer PrismaClient instance.
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies
prismarequiredPrisma ORM required as peer dependency for schema management and runtime types
@prisma/clientrequiredGenerates the PrismaClient and transaction client used in migration scripts
typescriptoptionalRequired for type generation and running TypeScript post-scripts
Agent activity
6 hits · last 30 days
node
6
Resources
prisma-data-migrations — npm install prisma-data-migrations · libregistry