ditto

π A powerful CLI tool for database synchronization between PostgreSQL and MySQL
β¨ Features
- Schema Comparison - Compare table structures, columns, indexes, and constraints
- Data Synchronization - Sync data with full or incremental strategies
- Data Export - Export tables to JSON, CSV, or SQL format
- Cross-Database Support - PostgreSQL β MySQL/MariaDB
- Beautiful CLI - Rich terminal output with colors, progress bars, and tables
- Configuration File Support - YAML config for complex setups
π Installation
Using Go Install
go install github.com/anuryadi/ditto@latest
From Source
git clone https://github.com/anuryadi/ditto.git
cd ditto
make build
Binary Releases
Download pre-built binaries from the Releases page.
π Quick Start
Compare Database Schemas
# Compare PostgreSQL to MySQL
ditto compare \
--source "postgres://user:pass@localhost:5432/source_db" \
--target "mysql://user:pass@localhost:3306/target_db"
# Output to JSON
ditto compare \
--source "postgres://user:pass@localhost/db1" \
--target "mysql://user:pass@localhost/db2" \
--format json \
--output diff.json
Sync Data Between Databases
# Full sync
ditto sync \
--source "postgres://user:pass@localhost/source" \
--target "mysql://user:pass@localhost/target" \
--tables users,orders,products
# Dry run (preview without changes)
ditto sync \
--source "postgres://..." \
--target "mysql://..." \
--dry-run
Export Table Data
# Export to JSON
ditto export \
--source "postgres://user:pass@localhost/db" \
--table users \
--format json \
--output users.json
# Export to CSV
ditto export \
--source "mysql://user:pass@localhost/db" \
--table orders \
--format csv \
--output orders.csv
βοΈ Configuration
Create a .ditto.yaml file in your home directory or use --config flag:
source:
driver: postgres
host: localhost
port: 5432
database: source_db
user: postgres
password: ${DB_PASSWORD} # Environment variable
target:
driver: mysql
host: localhost
port: 3306
database: target_db
user: root
password: ${DB_PASSWORD}
sync:
strategy: full # full, incremental
batch_size: 1000
tables:
- name: users
primary_key: id
timestamp_column: updated_at
- name: orders
primary_key: id
logging:
level: info
format: console
π§ Commands
| Command |
Description |
ditto compare |
Compare schemas between source and target database |
ditto sync |
Synchronize data from source to target |
ditto export |
Export table data to file |
ditto version |
Show version information |
Global Flags
| Flag |
Description |
--config |
Path to config file (default: ~/.ditto.yaml) |
-v, --verbose |
Enable verbose output |
-h, --help |
Show help |
ποΈ Architecture
ditto/
βββ cmd/ # CLI commands (Cobra)
βββ internal/
β βββ config/ # Configuration management (Viper)
β βββ database/ # Database drivers (PostgreSQL, MySQL)
β βββ schema/ # Schema comparison logic
β βββ sync/ # Data synchronization engine
β βββ export/ # Export handlers (JSON, CSV, SQL)
β βββ ui/ # Terminal UI components (pterm)
βββ pkg/
βββ logger/ # Structured logging (zerolog)
π§ͺ Development
# Install dependencies
go mod download
# Run tests
make test
# Run with coverage
make coverage
# Lint code
make lint
# Build for all platforms
make build-all
π Roadmap
- SQLite support
- Oracle Database support
- Scheduled sync with cron
- Web dashboard for monitoring
- CDC (Change Data Capture) support
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
Made with β€οΈ by Ari Nuryadi