herdux-cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +370 -0
- package/README.pt-BR.md +369 -0
- package/dist/commands/backup.d.ts +3 -0
- package/dist/commands/backup.d.ts.map +1 -0
- package/dist/commands/backup.js +66 -0
- package/dist/commands/backup.js.map +1 -0
- package/dist/commands/clean.d.ts +3 -0
- package/dist/commands/clean.d.ts.map +1 -0
- package/dist/commands/clean.js +102 -0
- package/dist/commands/clean.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +146 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/create.d.ts +3 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +26 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +92 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/drop.d.ts +3 -0
- package/dist/commands/drop.d.ts.map +1 -0
- package/dist/commands/drop.js +40 -0
- package/dist/commands/drop.js.map +1 -0
- package/dist/commands/list.d.ts +3 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +55 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/restore.d.ts +3 -0
- package/dist/commands/restore.d.ts.map +1 -0
- package/dist/commands/restore.js +54 -0
- package/dist/commands/restore.js.map +1 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +42 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/core/command-runner.d.ts +12 -0
- package/dist/core/command-runner.d.ts.map +1 -0
- package/dist/core/command-runner.js +20 -0
- package/dist/core/command-runner.js.map +1 -0
- package/dist/core/logger.d.ts +10 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +25 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/services/backup.service.d.ts +4 -0
- package/dist/services/backup.service.d.ts.map +1 -0
- package/dist/services/backup.service.js +99 -0
- package/dist/services/backup.service.js.map +1 -0
- package/dist/services/config.service.d.ts +26 -0
- package/dist/services/config.service.d.ts.map +1 -0
- package/dist/services/config.service.js +83 -0
- package/dist/services/config.service.js.map +1 -0
- package/dist/services/environment.service.d.ts +4 -0
- package/dist/services/environment.service.d.ts.map +1 -0
- package/dist/services/environment.service.js +51 -0
- package/dist/services/environment.service.js.map +1 -0
- package/dist/services/postgres.service.d.ts +27 -0
- package/dist/services/postgres.service.d.ts.map +1 -0
- package/dist/services/postgres.service.js +180 -0
- package/dist/services/postgres.service.js.map +1 -0
- package/dist/utils/detect-binary.d.ts +3 -0
- package/dist/utils/detect-binary.d.ts.map +1 -0
- package/dist/utils/detect-binary.js +16 -0
- package/dist/utils/detect-binary.js.map +1 -0
- package/dist/utils/resolve-connection.d.ts +3 -0
- package/dist/utils/resolve-connection.d.ts.map +1 -0
- package/dist/utils/resolve-connection.js +107 -0
- package/dist/utils/resolve-connection.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
🇺🇸 English | 🇧🇷 [Português](./README.pt-BR.md)
|
|
2
|
+
|
|
3
|
+
# Herdux — Database Workflow CLI
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>Infrastructure-grade power. Developer-grade experience.</strong>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
A fast, interactive CLI that removes friction from daily local database workflows, especially when juggling multiple instances and large datasets.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
> Optimized for local and development environments. Production use is supported with explicit configuration.
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<img src=".github/herdux.gif" alt="herdux terminal gif" width="1220" />
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ⚡ Quick Start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g herdux-cli
|
|
27
|
+
herdux doctor
|
|
28
|
+
herdux list
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
That's it. You're managing databases.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Why Herdux?
|
|
36
|
+
|
|
37
|
+
Managing local databases through raw bash scripts or binaries is repetitive, error-prone, and painful at scale.
|
|
38
|
+
|
|
39
|
+
### ❌ Without Herdux
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Backup a database
|
|
43
|
+
pg_dump -U postgres -h localhost -p 5416 -Fc -f ./backups/mydb_2026-02-23.dump mydb
|
|
44
|
+
|
|
45
|
+
# Then manually drop it
|
|
46
|
+
psql -U postgres -h localhost -p 5416 -c "DROP DATABASE mydb;"
|
|
47
|
+
|
|
48
|
+
# Restore from backup
|
|
49
|
+
pg_restore -U postgres -h localhost -p 5416 -d mydb --clean --if-exists ./backups/mydb_2026-02-23.dump
|
|
50
|
+
|
|
51
|
+
# Check if tools are installed
|
|
52
|
+
psql --version && pg_dump --version && pg_restore --version
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### ✅ With Herdux
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
herdux backup mydb --drop --yes # Backup + drop in one shot
|
|
59
|
+
herdux restore ./backups/mydb.dump --db mydb # Auto-creates DB if missing & detects format
|
|
60
|
+
herdux clean # Multi-select and batch-drop databases
|
|
61
|
+
herdux doctor # Full system health check
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Fewer flags. Fewer mistakes. Zero terminal fatigue.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 🎯 Who is Herdux for?
|
|
69
|
+
|
|
70
|
+
**Herdux** was built *for developers, by developers*.
|
|
71
|
+
|
|
72
|
+
It was born from the daily frustration of constantly having to restore backups to test specific states, drop corrupted databases during development, and juggle raw database binaries.
|
|
73
|
+
|
|
74
|
+
It is specifically designed for developers who:
|
|
75
|
+
- Manage local infrastructures and need to check disk sizes before seeding new databases.
|
|
76
|
+
- Want to quickly clone, seed, and reset databases without reading `man` pages.
|
|
77
|
+
- Need safe backup & restore workflows that don't rely on fragile bash scripts.
|
|
78
|
+
- Prefer terminal-first tooling.
|
|
79
|
+
- Want predictable connection resolution without hidden magic.
|
|
80
|
+
|
|
81
|
+
If you manage databases locally, Herdux was created to solve your pain.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🚀 Key Features
|
|
86
|
+
|
|
87
|
+
- **📋 Smart Listing** — Optimized listing strategy for massive clusters. Optional `--size` flag for disk usage analysis, sorted largest-first.
|
|
88
|
+
- **💾 Intelligent Backup & Restore** — Supports Custom (`.dump`) and Plain (`.sql`) formats. Auto-detects the right tool for restores.
|
|
89
|
+
- **🧹 Bulk Cleanup** — Multi-select databases, optionally backup, and batch-drop them. Reclaim disk space instantly.
|
|
90
|
+
- **🩺 System Diagnostics** — One-command health check verifying binaries, authentication, and connectivity.
|
|
91
|
+
- **⚙️ Persistent Profiles** — Save named server configurations. Switch between environments with `-s pg16`.
|
|
92
|
+
- **🎯 Smart Connection Resolution** — Explicit CLI flags → profiles → saved defaults → auto-discovery. Always predictable.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 💡 Philosophy
|
|
97
|
+
|
|
98
|
+
**Herdux** combines *herd* and *UX* — delivering a better developer experience when managing your local database clusters. The name reflects our focus on improving the developer experience of managing database herds.
|
|
99
|
+
|
|
100
|
+
**Herdux** follows three principles:
|
|
101
|
+
|
|
102
|
+
- **Safety first** — Never drops data without explicit confirmation or a verified backup.
|
|
103
|
+
- **Explicit over implicit** — Connection resolution follows a strict, documented priority. No magic.
|
|
104
|
+
- **Developer workflow optimization** — Every command is designed to save you from repetitive terminal work.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 🔒 Safety
|
|
109
|
+
|
|
110
|
+
**Herdux** handles destructive operations with care:
|
|
111
|
+
|
|
112
|
+
- **Never drops a database** unless explicit confirmation is given
|
|
113
|
+
- **Aborts the entire operation** if a safety backup fails during `herdux clean`
|
|
114
|
+
- **Validates `pg_dump` exit codes** before considering a backup successful
|
|
115
|
+
- **Requires `--drop` flag** intentionally — dropping is never the default
|
|
116
|
+
- **`--yes` must be combined with `--drop`** — cannot skip confirmation alone
|
|
117
|
+
|
|
118
|
+
> If you request a backup before dropping and that backup fails, **Herdux** stops immediately. No data is lost.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 🧩 Requirements
|
|
124
|
+
|
|
125
|
+
- **Node.js** 18 or higher
|
|
126
|
+
- **PostgreSQL client tools** (`psql`, `pg_dump`, `pg_restore`) installed and available in your `PATH`
|
|
127
|
+
|
|
128
|
+
> [!TIP]
|
|
129
|
+
> Run `herdux doctor` after installation to verify everything is set up correctly.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 📦 Installation
|
|
134
|
+
|
|
135
|
+
**npm (recommended):**
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm install -g herdux-cli
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**From source:**
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
git clone https://github.com/eduardozaniboni/herdux.git
|
|
145
|
+
cd herdux
|
|
146
|
+
npm install
|
|
147
|
+
npm run build
|
|
148
|
+
npm link
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 🛠️ Commands
|
|
154
|
+
|
|
155
|
+
### `herdux version`
|
|
156
|
+
|
|
157
|
+
Shows the CLI version and the connected PostgreSQL server version.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
herdux version
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### `herdux doctor`
|
|
164
|
+
|
|
165
|
+
Runs a full system health check:
|
|
166
|
+
|
|
167
|
+
- Verifies `psql`, `pg_dump`, and `pg_restore` are installed and reachable
|
|
168
|
+
- Attempts a live connection using the resolved configuration
|
|
169
|
+
- Tests authentication against the target server
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
herdux doctor
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### 📋 `herdux list`
|
|
178
|
+
|
|
179
|
+
Lists all databases on the connected server.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
herdux list # Fast listing (name, owner, encoding)
|
|
183
|
+
herdux ls --size # Includes disk size, sorted largest → smallest
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
> [!NOTE]
|
|
187
|
+
> The `--size` flag calculates physical disk usage via `pg_database_size()`. On servers with dozens of multi-GB databases, this may take a few minutes depending on disk speed.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
### `herdux create <name>`
|
|
192
|
+
|
|
193
|
+
Creates a new database.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
herdux create my_new_db
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### `herdux drop <name>`
|
|
200
|
+
|
|
201
|
+
Drops a database with interactive confirmation.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
herdux drop my_old_db
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### 🧹 `herdux clean` — Bulk Cleanup
|
|
210
|
+
|
|
211
|
+
Working with seed-heavy development databases? Need to reclaim disk space fast?
|
|
212
|
+
|
|
213
|
+
`herdux clean` allows you to:
|
|
214
|
+
|
|
215
|
+
- **Multi-select** databases from an interactive checkbox UI
|
|
216
|
+
- **Optionally generate safety backups** before any destructive action
|
|
217
|
+
- **Batch-drop** all selected databases safely
|
|
218
|
+
- **Abort immediately** if any backup fails, preventing data loss
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
herdux clean
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
This is designed for the real-world dev workflow: clone databases, experiment, then clean up everything in one shot.
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
### 📦 `herdux backup <database>`
|
|
229
|
+
|
|
230
|
+
Generates a timestamped backup in `./backups/`.
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
herdux backup mydb # Custom format (.dump)
|
|
234
|
+
herdux backup mydb --format plain # Plain SQL (.sql)
|
|
235
|
+
herdux backup mydb --drop # Backup, then ask to drop
|
|
236
|
+
herdux backup mydb --drop --yes # Backup + drop, no questions
|
|
237
|
+
herdux backup mydb -o ./my-backups # Custom output directory
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
| Option | Description |
|
|
241
|
+
|---|---|
|
|
242
|
+
| `-F, --format <type>` | `custom` (default, compressed) or `plain` (raw SQL) |
|
|
243
|
+
| `-d, --drop` | Prompt to drop database after successful backup |
|
|
244
|
+
| `-y, --yes` | Skip drop confirmation (requires `--drop`) |
|
|
245
|
+
| `-o, --output <dir>` | Output directory (default: `./backups`) |
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
### 📥 `herdux restore <file>`
|
|
250
|
+
|
|
251
|
+
Restores a database from a backup file. Automatically detects the format:
|
|
252
|
+
|
|
253
|
+
- `.sql` → uses `psql -f`
|
|
254
|
+
- `.dump` or any other extension → uses `pg_restore`
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
herdux restore ./backups/mydb_2026-02-23.dump --db mydb
|
|
258
|
+
herdux restore ./exports/data.sql --db mydb
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Need to override auto-detection? Use `--format`:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
herdux restore archive.bkp --db mydb --format custom
|
|
265
|
+
herdux restore script.txt --db mydb --format plain
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## ⚙️ Configuration & Server Profiles
|
|
271
|
+
|
|
272
|
+
`herdux` stores configuration locally at `~/.herdux/config.json`.
|
|
273
|
+
|
|
274
|
+
### Set Global Defaults
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
herdux config set user postgres
|
|
278
|
+
herdux config set password my_secret
|
|
279
|
+
herdux config set port 5432
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Named Server Profiles
|
|
283
|
+
|
|
284
|
+
Manage multiple database instances effortlessly:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
herdux config add pg16 --port 5416
|
|
288
|
+
herdux config add pg17 --port 5417 --user admin
|
|
289
|
+
herdux config add staging --host 192.168.0.10 --port 5432
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Then connect using the `-s` flag:
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
herdux list -s pg16
|
|
296
|
+
herdux backup mydb -s staging
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### View & Manage Config
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
herdux config list # Show all saved settings and profiles
|
|
303
|
+
herdux config get port # Get a specific value
|
|
304
|
+
herdux config rm pg16 # Remove a server profile
|
|
305
|
+
herdux config reset # Clear all configuration
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## 🔌 Connection Priority
|
|
311
|
+
|
|
312
|
+
When resolving how to connect, **Herdux** follows a strict, predictable priority order:
|
|
313
|
+
|
|
314
|
+
| Priority | Source | Example |
|
|
315
|
+
|---|---|---|
|
|
316
|
+
| 1️⃣ | **CLI flags** | `herdux list --port 5417` |
|
|
317
|
+
| 2️⃣ | **Server profile** | `herdux list -s pg16` |
|
|
318
|
+
| 3️⃣ | **Saved defaults** | `herdux config set port 5432` |
|
|
319
|
+
| 4️⃣ | **Auto-discovery** | Scans common ports; prompts if multiple found |
|
|
320
|
+
|
|
321
|
+
This means explicit input always wins. No surprises.
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## 🤔 Why not pgAdmin?
|
|
326
|
+
|
|
327
|
+
**Herdux** is not a GUI replacement.
|
|
328
|
+
It’s a workflow accelerator for developers who live in the terminal.
|
|
329
|
+
|
|
330
|
+
No GUI. No overhead. Just speed.
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## 🧠 Design Principles
|
|
335
|
+
|
|
336
|
+
- No hidden defaults.
|
|
337
|
+
- No destructive magic.
|
|
338
|
+
- Deterministic connection resolution.
|
|
339
|
+
- Explicit and composable commands.
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 🐳 Docker Support (Coming Soon)
|
|
344
|
+
|
|
345
|
+
**Herdux** will be able to detect and interact with PostgreSQL instances running inside Docker containers — listing, connecting, and managing them as naturally as local instances.
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
## 🗺 Roadmap
|
|
350
|
+
|
|
351
|
+
See [ROADMAP.md](./ROADMAP.md) for our detailed future plans, including Docker integration and encrypted backups.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## 🤝 Contributing
|
|
356
|
+
|
|
357
|
+
PRs are welcome! Please open an issue first to discuss major changes.
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
git clone https://github.com/eduardozaniboni/herdux.git
|
|
361
|
+
cd herdux
|
|
362
|
+
npm install
|
|
363
|
+
npm run dev
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## 📄 License
|
|
369
|
+
|
|
370
|
+
MIT
|