Blazing Fast Cloud Database Migration & Replication Engine
Piping entire databases between cloud clusters with zero data loss, sub-second latency, and live terminal analytics.
Features β’ Tech Stack β’ Installation β’ Quickstart β’ Environment Variables β’ Testing β’ Documentation β’ Roadmap β’ Contributing β’ License
dbshift is an open-source, production-grade CLI tool built in Go to replicate and migrate tables, schemas, indexes, and high-volume datasets across cloud databases.
Whether migrating between CockroachDB Cloud clusters, moving from PostgreSQL to Supabase / Neon, or transferring MongoDB Atlas collections, dbshift delivers maximum throughput through goroutine worker pools and native binary streaming protocols (pgx/v5 CopyFrom and Mongo BulkWrite).
__ __ __ _ _____ __
____/ / / /_ ___/ /_ (_) __// /_
/ __ / / __ \/ ___/ __ \/ / /_ / __/
/ /_/ /_/ /_/ (__ ) / / / / __// /_
\__,_(_)_,___/____/_/ /_/_/_/ \__/
Version: v1.0.0 | CockroachDB β’ PostgreSQL β’ MongoDB Atlas
- π Native Binary Wire Streaming: Utilizes PostgreSQL
pgx/v5binaryCopyFromprotocol for up to 10x faster ingestion compared to standard SQL inserts. - π§ Ultra-Low Memory Footprint (<50MB): Streams data in configurable chunk windows (default
2,500rows) via streaming cursorsβnever buffers entire tables into RAM. - βοΈ Cloud Database Native: Specially tuned for CockroachDB Cloud, PostgreSQL, Supabase, Neon, and MongoDB Atlas.
- π‘οΈ 2-Phase Constraint Handling: Safely migrates tables with complex Foreign Key graphs by deferring constraints to post-load phase, eliminating circular dependency deadlocks.
- π¨ Interactive Terminal Wizard: Intuitive CLI experience with auto-detection of engine from connection URIs and simple numbered menu choices
[1],[2]. - π Real-time Progress Tracking: Displays live transfer speed (
rows/s), total rows streamed, elapsed time, and ETA. - β Post-Migration Verification Audit: Automatically queries and matches source vs target row counts to verify 100% data integrity.
- π Auto Sequence Synchronization: Automatically resets
SERIALandBIGSERIALsequences toMAX(id)on target databases post-transfer. - π€ Headless & CI/CD Ready: Pass flags or environment variables for zero-interaction scripts and automated backup pipelines.
- Language: Go (
go1.22+/go1.26+) - PostgreSQL / CockroachDB Driver:
github.com/jackc/pgx/v5(Native binary protocol & connection pooling) - MongoDB Driver:
go.mongodb.org/mongo-driver/v2(Official BSON & bulk operations) - CLI Framework:
github.com/spf13/cobra - Terminal UI & Styling:
github.com/pterm/pterm - Environment Management:
github.com/joho/godotenv - Containerization: Docker multi-stage build (
alpine:3.20)
| Database Engine | Dialect / Wire Protocol | Supported Features |
|---|---|---|
| CockroachDB Cloud | PostgreSQL Wire | Native SHOW CREATE TABLE, Data, Primary Keys, Indexes, Sequences, JSONB, UUIDs |
| PostgreSQL | Standard Postgres (v12-v17) | Full Schema + High-Speed Binary Copy |
| Supabase | Managed Postgres | SSL Pooler & Direct Connections |
| Neon | Serverless Postgres | Auto-suspend friendly connection management |
| MongoDB Atlas | Mongo Wire Protocol | Collections, Document BSON Streaming, Secondary Indexes |
Download the standalone executable for Windows, Linux, or macOS from the GitHub Releases page.
go install github.com/dusmamud/dbshift/cmd/dbshift@latest# 1. Clone the repository
git clone https://github.com/dusmamud/dbshift.git
# 2. Move into the directory
cd dbshift
# 3. Build binary
# On Windows PowerShell:
.\scripts\build.ps1
# On Linux / macOS:
go build -ldflags="-s -w" -o bin/dbshift ./cmd/dbshiftdocker build -t dbshift .
docker run --rm -it --env-file .env dbshiftSimply run dbshift without arguments:
dbshift- Auto-Detects Engine: Reads your
.envconnection strings and automatically identifies CockroachDB / Postgres or Mongo. - Inspects Schema: Shows all tables and their exact row counts in a clean terminal table.
- Choose Scope: Press
[1]to migrate all tables or[2]to select specific tables. - Live Stream: Watch real-time multi-threaded streaming with rows/sec transfer rate.
- Verify: Review post-migration audit table comparing source vs target row counts.
dbshift \
--source="postgresql://user:pass@source-cluster.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full" \
--target="postgresql://user:pass@target-cluster.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full" \
--engine=postgres \
--concurrency=4 \
--batch-size=2500 \
--drop-existingdbshift \
--source="mongodb+srv://user:pass@example.com/prod?retryWrites=true&w=majority" \
--target="mongodb+srv://user:pass@example.com/prod?retryWrites=true&w=majority" \
--engine=mongo \
--concurrency=4You can configure dbshift using a .env file in your root folder:
cp .env.example .env| Variable | Required | Default | Description |
|---|---|---|---|
SOURCE_URI |
Yes | "" |
Connection URI of source (old) database |
TARGET_URI |
Yes | "" |
Connection URI of target (new) database |
DB_ENGINE |
No | postgres |
Database engine (postgres or mongo) |
CONCURRENCY |
No | 4 |
Number of concurrent table worker goroutines |
BATCH_SIZE |
No | 2500 |
Number of rows per streaming chunk |
dbshift [command] [flags]dbshiftβ Launch interactive wizard (or direct migration if--sourceand--targetare passed).dbshift inspect --url="<URI>" --engine=postgresβ Inspect schema, column counts, indexes, and row counts.dbshift verify --source="<SRC>" --target="<TGT>"β Run standalone count verification audit between two databases.dbshift versionβ Print version and build info.
| Flag | Shorthand | Default | Description |
|---|---|---|---|
--source |
-s |
"" |
Source database connection URI |
--target |
-t |
"" |
Target database connection URI |
--engine |
-e |
postgres |
Database engine (postgres or mongo) |
--mode |
-m |
full |
Migration mode: full, data-only, schema-only |
--concurrency |
-c |
4 |
Number of parallel worker goroutines |
--batch-size |
-b |
2500 |
Number of rows per streaming chunk |
--drop-existing |
false |
Drop conflicting target tables/collections before copying | |
--tables |
"" |
Comma-separated list of specific tables (e.g. users,orders) |
Run all unit tests:
go test -v ./...Run tests with race condition detector:
go test -v -race ./...Run tests with coverage:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.outAfter each migration, an automated audit is performed and rendered in the terminal:
βββββββββββββββββββββββββββ¬ββββββββββββββ¬ββββββββββββββ¬βββββββββββββββ¬βββββββββββββ
β Table / Collection β Source Rows β Target Rows β Verification β Audit Time β
βββββββββββββββββββββββββββΌββββββββββββββΌββββββββββββββΌβββββββββββββββΌβββββββββββββ€
β music_albums β 1,803 β 1,803 β β MATCH β 18ms β
β music_artists β 13,516 β 13,516 β β MATCH β 24ms β
β music_chart_cache β 50 β 50 β β MATCH β 12ms β
β music_songs β 51,958 β 51,958 β β MATCH β 54ms β
β user_playlist β 8 β 8 β β MATCH β 8ms β
β user_playlist_tracks β 13 β 13 β β MATCH β 10ms β
βββββββββββββββββββββββββββ΄ββββββββββββββ΄ββββββββββββββ΄βββββββββββββββ΄βββββββββββββ
βββββββββββββββββββββββββββ MIGRATION SUCCESSFUL βββββββββββββββββββββββββββ
β All 6 tables/collections verified with 100% integrity. β
β Total Rows Transferred: 67,348 β
β Total Elapsed Time: 14.8s β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
dbshift/
βββ .github/
β βββ ISSUE_TEMPLATE/
β β βββ bug_report.md # GitHub bug report template
β β βββ feature_request.md # GitHub feature request template
β βββ workflows/
β β βββ ci.yml # Automated CI test & build pipeline
β β βββ release.yml # Automated multi-arch release pipeline
β βββ pull_request_template.md # GitHub PR template
βββ cmd/
β βββ dbshift/
β βββ main.go # CLI entry point
βββ docs/
β βββ ARCHITECTURE.md # Concurrency, memory & streaming design
β βββ CLI_REFERENCE.md # Comprehensive flag & command reference
β βββ COCKROACHDB.md # CockroachDB Cloud migration guide
βββ internal/
β βββ config/ # Configuration & .env parser
β βββ core/ # Migration engine & driver interface
β βββ driver/
β β βββ mongo/ # MongoDB Atlas adapter
β β βββ postgres/ # PostgreSQL & CockroachDB adapter
β βββ ui/ # Terminal interactive wizard & progress bars
βββ scripts/
β βββ build.ps1 # PowerShell build script for Windows
βββ .dockerignore
βββ .env.example
βββ .gitignore
βββ .golangci.yml # Linter configuration
βββ CODE_OF_CONDUCT.md # Contributor Covenant 2.1
βββ CONTRIBUTING.md # Contribution guide
βββ Dockerfile # Multi-stage production container build
βββ LICENSE # MIT License
βββ README.md # Flagship documentation
- CockroachDB Cloud β CockroachDB Cloud replication
- PostgreSQL / Supabase / Neon support
- MongoDB Atlas document streaming
- 2-Phase foreign key constraint resolution
- Auto-detection of database engine from URI
- Post-migration verification count audit
- MySQL β MySQL engine adapter
- Cross-engine migration (MongoDB to Postgres JSONB)
- Change Data Capture (CDC) real-time streaming sync
Contributions are welcome! Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md before opening a pull request.
If you discover a security vulnerability, please review our SECURITY.md policy for responsible disclosure.
This project is licensed under the MIT License - see the LICENSE file for details.
dusmamud
- GitHub: @dusmamud