Skip to content

D1 Migrator

The @zintrust/d1-migrator package provides a dedicated CLI workflow for migrating existing databases to Cloudflare D1.

It supports resumable migrations, schema analysis, data validation, and batch-based transfer for MySQL, PostgreSQL, SQLite, and SQL Server sources.

Installation

bash
npm install @zintrust/d1-migrator

After installation, the command is auto-registered with the ZinTrust CLI. No manual entry in src/zintrust.plugins.ts is required.

bash
zin migrate-to-d1 --help

What it provides

  • Source support for MySQL, PostgreSQL, SQLite, and SQL Server
  • Target support for local D1 and remote D1 workflows
  • Checkpoint-based resume support for interrupted migrations
  • Schema compatibility checks before migration
  • Dry-run mode for validation before execution
  • Batch and checkpoint tuning for large datasets

Basic usage

Zero-arg env-driven mode

bash
export DB_CONNECTION=mysql
export DB_READ_HOSTS=127.0.0.1
export DB_PORT=3306
export DB_DATABASE=zintrust
export DB_USERNAME=root
export DB_PASSWORD=secret
export D1_TARGET_DB=zintrust-live-test

zin migrate-to-d1

Explicit flags

bash
zin migrate-to-d1 \
  --from mysql \
  --source-connection "mysql://user:password@localhost:3306/mydb" \
  --to d1 \
  --target-database my-d1-db

Common options

OptionDescription
--fromSource driver: mysql, postgresql, sqlite, sqlserver
--toTarget mode: d1 or d1-remote
--source-connectionSource database connection string
--target-databaseTarget D1 database name or identifier
--batch-sizeRows per migration batch
--checkpoint-intervalRows between saved checkpoints
--dry-runValidate without making changes
--schema-onlyConvert and inspect schema only
--interactiveInteractive mode for compatibility review
--resumeResume a previous migration

Programmatic usage

typescript
import { D1Migrator } from '@zintrust/d1-migrator';

const progress = await D1Migrator.DataMigrator.migrateData({
  sourceConnection: 'mysql://user:password@localhost:3306/mydb',
  sourceDriver: 'mysql',
  targetDatabase: 'my-d1-db',
  targetType: 'd1',
  batchSize: 1000,
  checkpointInterval: 10000,
});

console.log(progress.status, progress.processedRows);

When to use it

Use @zintrust/d1-migrator when you need to:

  • move an existing SQL database into Cloudflare D1
  • analyze source schema compatibility before migration
  • perform safe dry runs before production transfer
  • resume interrupted migrations without starting over

Package

Released under the MIT License.