spindb 0.5.2 β†’ 0.5.4

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.
Files changed (38) hide show
  1. package/README.md +188 -9
  2. package/cli/commands/connect.ts +334 -105
  3. package/cli/commands/create.ts +106 -67
  4. package/cli/commands/deps.ts +19 -4
  5. package/cli/commands/edit.ts +245 -0
  6. package/cli/commands/engines.ts +434 -0
  7. package/cli/commands/info.ts +279 -0
  8. package/cli/commands/list.ts +1 -1
  9. package/cli/commands/menu.ts +664 -167
  10. package/cli/commands/restore.ts +11 -25
  11. package/cli/commands/start.ts +25 -20
  12. package/cli/commands/url.ts +79 -0
  13. package/cli/index.ts +9 -3
  14. package/cli/ui/prompts.ts +20 -12
  15. package/cli/ui/theme.ts +1 -1
  16. package/config/engine-defaults.ts +24 -1
  17. package/config/os-dependencies.ts +151 -113
  18. package/config/paths.ts +7 -36
  19. package/core/binary-manager.ts +12 -6
  20. package/core/config-manager.ts +17 -5
  21. package/core/dependency-manager.ts +144 -15
  22. package/core/error-handler.ts +336 -0
  23. package/core/platform-service.ts +634 -0
  24. package/core/port-manager.ts +11 -3
  25. package/core/process-manager.ts +12 -2
  26. package/core/start-with-retry.ts +167 -0
  27. package/core/transaction-manager.ts +170 -0
  28. package/engines/mysql/binary-detection.ts +177 -100
  29. package/engines/mysql/index.ts +240 -131
  30. package/engines/mysql/restore.ts +257 -0
  31. package/engines/mysql/version-validator.ts +373 -0
  32. package/{core/postgres-binary-manager.ts β†’ engines/postgresql/binary-manager.ts} +63 -23
  33. package/engines/postgresql/binary-urls.ts +5 -3
  34. package/engines/postgresql/index.ts +35 -4
  35. package/engines/postgresql/restore.ts +54 -5
  36. package/engines/postgresql/version-validator.ts +262 -0
  37. package/package.json +6 -2
  38. package/cli/commands/postgres-tools.ts +0 -216
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SpinDB
2
2
 
3
- Spin up local PostgreSQL and MySQL databases without Docker. A lightweight alternative to DBngin.
3
+ Spin up local PostgreSQL and MySQL databases without Docker. A lightweight alternative to DBngin and Postgres.app.
4
4
 
5
5
  ## Features
6
6
 
@@ -45,12 +45,17 @@ spindb connect mydb
45
45
  | `spindb` | Open interactive menu |
46
46
  | `spindb create [name]` | Create a new database container |
47
47
  | `spindb list` | List all containers |
48
+ | `spindb info [name]` | Show container details (or all containers) |
48
49
  | `spindb start [name]` | Start a container |
49
50
  | `spindb stop [name]` | Stop a container |
50
- | `spindb connect [name]` | Connect with psql/mysql shell |
51
+ | `spindb connect [name]` | Connect with psql/mysql shell (`--pgcli`/`--mycli` for enhanced) |
52
+ | `spindb url [name]` | Output connection string |
53
+ | `spindb edit [name]` | Edit container properties (rename, port) |
51
54
  | `spindb restore [name] [backup]` | Restore a backup file |
52
55
  | `spindb clone [source] [target]` | Clone a container |
53
56
  | `spindb delete [name]` | Delete a container |
57
+ | `spindb engines` | List installed database engines |
58
+ | `spindb engines delete` | Delete an installed engine version |
54
59
  | `spindb config show` | Show configuration |
55
60
  | `spindb config detect` | Auto-detect database tools |
56
61
  | `spindb deps check` | Check status of client tools |
@@ -60,16 +65,27 @@ spindb connect mydb
60
65
 
61
66
  ### PostgreSQL 🐘
62
67
 
63
- - Downloads binaries from [zonky.io](https://github.com/zonkyio/embedded-postgres-binaries)
68
+ - Downloads server binaries from [zonky.io embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres-binaries)
64
69
  - Versions: 14, 15, 16, 17
65
70
  - Requires system client tools (psql, pg_dump, pg_restore) for some operations
66
71
 
72
+ **Why zonky.io?** Zonky.io provides pre-compiled PostgreSQL server binaries for multiple platforms (macOS, Linux) and architectures (x64, ARM64) hosted on Maven Central. This allows SpinDB to download and run PostgreSQL without requiring a full system installation. The binaries are extracted from official PostgreSQL distributions and repackaged for easy embedding in applications.
73
+
67
74
  ### MySQL 🐬
68
75
 
69
76
  - Uses system-installed MySQL (via Homebrew, apt, etc.)
70
77
  - Version determined by system installation
71
78
  - Requires: mysqld, mysql, mysqldump, mysqladmin
72
79
 
80
+ **Linux Note:** On Linux systems, MariaDB is commonly used as a drop-in replacement for MySQL. SpinDB fully supports MariaDB and will automatically detect it. When MariaDB is installed, the `mysql`, `mysqld`, and `mysqldump` commands work the same way. Install with:
81
+ ```bash
82
+ # Ubuntu/Debian
83
+ sudo apt install mariadb-server
84
+
85
+ # Arch
86
+ sudo pacman -S mariadb
87
+ ```
88
+
73
89
  ## How It Works
74
90
 
75
91
  Data is stored in `~/.spindb/`:
@@ -91,6 +107,44 @@ Data is stored in `~/.spindb/`:
91
107
  └── config.json
92
108
  ```
93
109
 
110
+ ## How Data Persists
111
+
112
+ SpinDB runs database servers as **native processes** on your machineβ€”no Docker or virtualization involved. When you start a container, SpinDB launches the actual `postgres` or `mysqld` binary, which listens on localhost at your configured port.
113
+
114
+ ### What happens when you start a container
115
+
116
+ 1. SpinDB runs the database server binary (e.g., `pg_ctl start`)
117
+ 2. The server binds to `127.0.0.1` on your configured port
118
+ 3. A **PID file** is created to track the running process
119
+ 4. Logs are written to the container's log file
120
+
121
+ ### What happens when you stop a container
122
+
123
+ 1. SpinDB sends a shutdown signal to the database process
124
+ 2. The server flushes any pending writes to disk
125
+ 3. The **PID file is removed**
126
+ 4. Your data remains safely in the data directory
127
+
128
+ ### Where your data lives
129
+
130
+ All database files persist in the container's `data/` directory:
131
+
132
+ ```
133
+ ~/.spindb/containers/postgresql/mydb/
134
+ β”œβ”€β”€ container.json # Container configuration (port, version, etc.)
135
+ β”œβ”€β”€ postgres.log # Server logs
136
+ └── data/ # ← Your actual database files live here
137
+ β”œβ”€β”€ base/ # Table data
138
+ β”œβ”€β”€ pg_wal/ # Transaction logs
139
+ └── ...
140
+ ```
141
+
142
+ The `data/` directory is a standard PostgreSQL/MySQL data directory. Stopping and starting a container doesn't affect your dataβ€”only the PID file changes.
143
+
144
+ ### How SpinDB knows if a container is running
145
+
146
+ SpinDB checks for the PID file and verifies the process is still alive. No PID file (or dead process) = stopped container.
147
+
94
148
  ## Client Tools
95
149
 
96
150
  SpinDB bundles the PostgreSQL **server** but not client tools. For `connect` and `restore` commands, you need client tools installed.
@@ -109,12 +163,14 @@ spindb deps install --engine postgresql
109
163
  spindb deps install --engine mysql
110
164
  ```
111
165
 
166
+ **Note:** On Linux, package managers (apt, pacman, dnf) require `sudo` privileges. You may be prompted for your password when installing dependencies.
167
+
112
168
  ### Manual Installation
113
169
 
114
170
  #### PostgreSQL
115
171
 
116
172
  ```bash
117
- # macOS (Homebrew)
173
+ # macOS (Homebrew) - use the latest PostgreSQL version (currently 17)
118
174
  brew install postgresql@17
119
175
  brew link --overwrite postgresql@17
120
176
 
@@ -187,6 +243,18 @@ spindb start test-branch
187
243
  # Interactive shell (auto-detects engine)
188
244
  spindb connect mydb
189
245
 
246
+ # Use pgcli/mycli for enhanced shell (dropdown auto-completion)
247
+ spindb connect mydb --pgcli # PostgreSQL
248
+ spindb connect mydb --mycli # MySQL
249
+
250
+ # Install pgcli/mycli and connect in one command
251
+ spindb connect mydb --install-pgcli
252
+ spindb connect mydb --install-mycli
253
+
254
+ # Use usql for universal SQL client (works with both engines)
255
+ spindb connect mydb --tui
256
+ spindb connect mydb --install-tui
257
+
190
258
  # Or use connection string directly
191
259
  psql postgresql://postgres@localhost:5432/mydb
192
260
  mysql -u root -h 127.0.0.1 -P 3306 mydb
@@ -194,15 +262,59 @@ mysql -u root -h 127.0.0.1 -P 3306 mydb
194
262
 
195
263
  ### Manage installed engines
196
264
 
197
- The Engines menu shows installed PostgreSQL versions with disk usage:
265
+ View installed engines with disk usage (PostgreSQL) and system detection (MySQL):
266
+
267
+ ```bash
268
+ spindb engines
269
+ ```
198
270
 
199
271
  ```
200
- ENGINE VERSION PLATFORM SIZE
272
+ ENGINE VERSION SOURCE SIZE
201
273
  ────────────────────────────────────────────────────────
202
- postgresql 17 darwin-arm64 45.2 MB
203
- postgresql 16 darwin-arm64 44.8 MB
274
+ 🐘 postgresql 17.7 darwin-arm64 45.2 MB
275
+ 🐘 postgresql 16.8 darwin-arm64 44.8 MB
276
+ 🐬 mysql 8.0.35 system (system-installed)
204
277
  ────────────────────────────────────────────────────────
205
- 2 version(s) 90.0 MB
278
+
279
+ PostgreSQL: 2 version(s), 90.0 MB
280
+ MySQL: system-installed at /opt/homebrew/bin/mysqld
281
+ ```
282
+
283
+ Delete unused PostgreSQL versions to free disk space:
284
+
285
+ ```bash
286
+ spindb engines delete postgresql 16
287
+ ```
288
+
289
+ ### Container info and connection strings
290
+
291
+ ```bash
292
+ # View all container details
293
+ spindb info
294
+
295
+ # View specific container
296
+ spindb info mydb
297
+
298
+ # Get connection string for scripting
299
+ spindb url mydb
300
+ export DATABASE_URL=$(spindb url mydb)
301
+ psql $(spindb url mydb)
302
+
303
+ # Copy connection string to clipboard
304
+ spindb url mydb --copy
305
+ ```
306
+
307
+ ### Edit containers
308
+
309
+ ```bash
310
+ # Rename a container (must be stopped)
311
+ spindb edit mydb --name newname
312
+
313
+ # Change port
314
+ spindb edit mydb --port 5433
315
+
316
+ # Interactive mode
317
+ spindb edit mydb
206
318
  ```
207
319
 
208
320
  ## Running Tests
@@ -251,6 +363,73 @@ cat ~/.spindb/containers/mysql/mydb/mysql.log
251
363
  rm -rf ~/.spindb
252
364
  ```
253
365
 
366
+ ## Project Structure
367
+
368
+ ```
369
+ spindb/
370
+ β”œβ”€β”€ bin.ts # Entry point (#!/usr/bin/env tsx)
371
+ β”œβ”€β”€ cli/
372
+ β”‚ β”œβ”€β”€ index.ts # Commander setup, routes to commands
373
+ β”‚ β”œβ”€β”€ commands/ # CLI commands
374
+ β”‚ β”‚ β”œβ”€β”€ menu.ts # Interactive arrow-key menu
375
+ β”‚ β”‚ β”œβ”€β”€ create.ts # Create container command
376
+ β”‚ β”‚ β”œβ”€β”€ delete.ts # Delete container command
377
+ β”‚ β”‚ └── ... # Other commands
378
+ β”‚ └── ui/
379
+ β”‚ β”œβ”€β”€ prompts.ts # Inquirer prompts
380
+ β”‚ β”œβ”€β”€ spinner.ts # Ora spinner helpers
381
+ β”‚ └── theme.ts # Chalk color theme
382
+ β”œβ”€β”€ core/
383
+ β”‚ β”œβ”€β”€ binary-manager.ts # Downloads PostgreSQL from zonky.io
384
+ β”‚ β”œβ”€β”€ config-manager.ts # Manages ~/.spindb/config.json
385
+ β”‚ β”œβ”€β”€ container-manager.ts # CRUD for containers
386
+ β”‚ β”œβ”€β”€ port-manager.ts # Port availability checking
387
+ β”‚ β”œβ”€β”€ process-manager.ts # Process start/stop wrapper
388
+ β”‚ β”œβ”€β”€ dependency-manager.ts # Client tool detection
389
+ β”‚ β”œβ”€β”€ error-handler.ts # Centralized error handling
390
+ β”‚ └── transaction-manager.ts # Rollback support for operations
391
+ β”œβ”€β”€ config/
392
+ β”‚ β”œβ”€β”€ paths.ts # ~/.spindb/ path definitions
393
+ β”‚ β”œβ”€β”€ defaults.ts # Default values, platform mappings
394
+ β”‚ └── os-dependencies.ts # OS-specific dependency definitions
395
+ β”œβ”€β”€ engines/
396
+ β”‚ β”œβ”€β”€ base-engine.ts # Abstract base class
397
+ β”‚ β”œβ”€β”€ index.ts # Engine registry
398
+ β”‚ β”œβ”€β”€ postgresql/
399
+ β”‚ β”‚ β”œβ”€β”€ index.ts # PostgreSQL engine implementation
400
+ β”‚ β”‚ β”œβ”€β”€ binary-urls.ts # Zonky.io URL builder
401
+ β”‚ β”‚ β”œβ”€β”€ restore.ts # Backup detection and restore
402
+ β”‚ β”‚ └── version-validator.ts # Version compatibility checks
403
+ β”‚ └── mysql/
404
+ β”‚ β”œβ”€β”€ index.ts # MySQL engine implementation
405
+ β”‚ β”œβ”€β”€ binary-detection.ts # MySQL binary path detection
406
+ β”‚ β”œβ”€β”€ restore.ts # Backup detection and restore
407
+ β”‚ └── version-validator.ts # Version compatibility checks
408
+ β”œβ”€β”€ types/
409
+ β”‚ └── index.ts # TypeScript interfaces
410
+ └── tests/
411
+ β”œβ”€β”€ unit/ # Unit tests
412
+ β”œβ”€β”€ integration/ # Integration tests
413
+ └── fixtures/ # Test data
414
+ β”œβ”€β”€ postgresql/
415
+ β”‚ └── seeds/
416
+ └── mysql/
417
+ └── seeds/
418
+ ```
419
+
420
+ ## Contributing
421
+
422
+ ### Version Updates
423
+
424
+ SpinDB uses versioned PostgreSQL packages from Homebrew (e.g., `postgresql@17`). When new major versions are released:
425
+
426
+ 1. Check [PostgreSQL releases](https://www.postgresql.org/docs/release/) and [Homebrew formulae](https://formulae.brew.sh/formula/postgresql)
427
+ 2. Update `config/engine-defaults.ts`:
428
+ - Change `latestVersion` to the new version
429
+ - Add the new version to `supportedVersions`
430
+
431
+ See `CLAUDE.md` for detailed maintenance instructions.
432
+
254
433
  ## License
255
434
 
256
435
  MIT