A Bridge CLI to manage Cloudflare D1 migrations with Prisma
npm install -g d1-prisma
# or
yarn global add d1-prisma
# or
pnpm add -g d1-prisma
# or
bun add -g d1-prismaTo install dependencies:
bun installTo build:
bun run buildTo run from source:
bun run src/index.tsThis project was created using bun init in bun v1.3.3. Bun is a fast all-in-one JavaScript runtime.
- Seamless Integration: Bridges Cloudflare D1 and Prisma migrations for a smooth development workflow
- Migration Creation: Generates SQL migration files based on Prisma schema changes
- Migration Application: Applies migrations to local or remote D1 databases
- Prisma Client Generation: Automatically regenerates Prisma client after migrations
- Cross-Platform: Works on Windows, macOS, and Linux
- Multiple Package Managers: Compatible with npm, yarn, pnpm, and bun
First, ensure you have a wrangler.toml or wrangler.jsonc file in your project root with your D1 database configuration:
# wrangler.toml
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "your-database-id"To create a new migration:
d1-prisma create --name "add-users-table"Options:
--name,-n: Migration name--schema: Path to Prisma schema (default: "./prisma/schema.prisma")--database,-d: Specific database to use
The CLI will:
- Back up your current Prisma schema
- Create a new migration file using Wrangler
- Pull the current database schema into Prisma
- Generate a diff between the current and desired schema
- Append the diff to the migration file
- Restore your original schema
To apply migrations locally:
d1-prisma applyTo apply migrations to remote database:
d1-prisma apply --remoteAfter applying, the CLI automatically regenerates your Prisma client.
- Node.js (v16 or higher)
- Wrangler CLI installed (
npm install -g wrangler) - Prisma CLI installed (
npm install -g prisma) - A configured Cloudflare D1 database
The tool automatically detects your configuration files:
wrangler.jsoncwrangler.toml
If multiple D1 databases are configured, you'll be prompted to select one.
build: Build the project todist/directorydev: Watch mode for developmentstart: Run the built CLI
The project consists of:
src/index.ts: Main CLI entry pointsrc/utils/config.ts: Configuration file parsingsrc/utils/shell.ts: Shell command utilities
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
- Cloudflare D1 - Serverless database
- Prisma - Database toolkit
- Wrangler - Cloudflare CLI tool
- Inspired by Alex Anderson Migrator CLI
If you encounter any issues or have questions, please open an issue on GitHub.
- Initial release
- Basic migration creation and application
- Support for local and remote databases