postgres-copy
v1.0.0
Published
A simple CLI tool to copy the contents of a Postgres table from one database to another
Maintainers
Readme
📤 Postgres-Copy
A simple and developer-friendly CLI tool to copy table contents from one PostgreSQL database to another. Whether you're working across different servers or within the same instance, postgres-copy has your back. 🚀
🌟 Features
✅ Easily copy data from one Postgres table to another.
✅ Supports copying across entirely different servers.
✅ Prompts for sensitive information like passwords to keep your workflow secure.
✅ Skips user confirmation when run in non-interactive environments.
📦 Installation
Make sure you have Node.js installed. Then you can globally install postgres-copy using:
npm install -g postgres-copy🚀 Usage
Run the CLI tool using the command:
postgres-copy [options]Example:
postgres-copy \
--source-url postgresql://localhost:5432/db1 \
--source-user postgres \
--source-table public.mytable \
--target-url postgresql://remote-server:5432/db2 \
--target-user admin \
--target-password secret \
--target-table public.mytable_copyThis will copy the table public.mytable from db1 on localhost:5432 to the table public.mytable_copy in db2 hosted on remote-server:5432.
⚙️ Available Options
| Option | Alias | Description | Type | Default |
|---------------------|-------|----------------------------------------------------------------------------|---------|----------------------------------------|
| --source-url | -s | The URL of the source database (e.g., postgresql://localhost:5432/mydb). | string | postgresql://localhost:5432/postgres |
| --source-user | -su | The user of the source database. | string | postgres |
| --source-password | -sp | The password of the source database (will be prompted if empty). | string | |
| --source-table | -st | The table to copy (e.g., public.mytable). Required. | string | N/A |
| --target-url | -t | The URL of the target database (defaults to source-url). | string | Source database's URL (source-url) |
| --target-user | -tu | The user of the target database (defaults to source-user). | string | Source database's user (source-user) |
| --target-password | -tp | The password of the target database (will be prompted if empty). | string | |
| --target-table | -tt | The table to copy into (defaults to source-table). | string | Source table (source-table) |
| --yes | -y | Skip confirmation prompts. | boolean | false |
💡 Handy Tips
- Always Test Before Production: Run the command with test databases to ensure everything is being copied as expected. 💡
- Partial Configuration: If you leave parameters like
target-url,target-user, ortarget-tableblank, the tool will reuse values from their respective source parameters.
🔧 Development
Want to contribute? Awesome! Clone the repository:
git clone https://github.com/yourusername/postgres-copy.git
cd postgres-copy
npm run build
npm installFeel free to submit pull requests, file issues, or improve the documentation. We value community involvement! 🌈
🔒 Security
The tool will prompt for passwords if they are not provided as part of the command-line options. This avoids sensitive data being left in shell history. Always securely manage and protect access to your databases! 🔐
🌍 License
This project is licensed under the MIT License. Feel free to use, modify, and distribute it. 😊
❤️ Acknowledgments
Big thanks to the amazing Node.js and PostgreSQL communities for their great tools and documentation that made this project possible. 💖
Enjoy using postgres-copy! If you have any feedback or ideas for improvement, let us know. 🎉
