spindb 0.4.1 → 0.5.3
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 +207 -101
- package/cli/commands/clone.ts +3 -1
- package/cli/commands/connect.ts +54 -24
- package/cli/commands/create.ts +309 -189
- package/cli/commands/delete.ts +3 -1
- package/cli/commands/deps.ts +19 -4
- package/cli/commands/edit.ts +245 -0
- package/cli/commands/engines.ts +434 -0
- package/cli/commands/info.ts +279 -0
- package/cli/commands/list.ts +14 -3
- package/cli/commands/menu.ts +510 -198
- package/cli/commands/restore.ts +66 -43
- package/cli/commands/start.ts +50 -19
- package/cli/commands/stop.ts +3 -1
- package/cli/commands/url.ts +79 -0
- package/cli/index.ts +9 -3
- package/cli/ui/prompts.ts +99 -34
- package/config/defaults.ts +40 -15
- package/config/engine-defaults.ts +107 -0
- package/config/os-dependencies.ts +119 -124
- package/config/paths.ts +82 -56
- package/core/binary-manager.ts +44 -6
- package/core/config-manager.ts +17 -5
- package/core/container-manager.ts +124 -60
- package/core/dependency-manager.ts +9 -15
- package/core/error-handler.ts +336 -0
- package/core/platform-service.ts +634 -0
- package/core/port-manager.ts +51 -32
- package/core/process-manager.ts +26 -8
- package/core/start-with-retry.ts +167 -0
- package/core/transaction-manager.ts +170 -0
- package/engines/index.ts +7 -2
- package/engines/mysql/binary-detection.ts +325 -0
- package/engines/mysql/index.ts +808 -0
- package/engines/mysql/restore.ts +257 -0
- package/engines/mysql/version-validator.ts +373 -0
- package/{core/postgres-binary-manager.ts → engines/postgresql/binary-manager.ts} +63 -23
- package/engines/postgresql/binary-urls.ts +5 -3
- package/engines/postgresql/index.ts +17 -9
- package/engines/postgresql/restore.ts +54 -5
- package/engines/postgresql/version-validator.ts +262 -0
- package/package.json +9 -3
- package/types/index.ts +29 -5
- package/cli/commands/postgres-tools.ts +0 -216
package/README.md
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
# SpinDB
|
|
2
2
|
|
|
3
|
-
Spin up local PostgreSQL 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
|
|
|
7
|
-
- **No Docker required** - Downloads
|
|
8
|
-
- **Multiple
|
|
7
|
+
- **No Docker required** - Downloads PostgreSQL binaries directly, uses system MySQL
|
|
8
|
+
- **Multiple engines** - PostgreSQL and MySQL support
|
|
9
|
+
- **Multiple containers** - Run multiple isolated database instances on different ports
|
|
9
10
|
- **Interactive menu** - Arrow-key navigation for all operations
|
|
10
11
|
- **Auto port management** - Automatically finds available ports
|
|
11
12
|
- **Clone containers** - Duplicate databases with all data
|
|
12
|
-
- **Backup restore** - Restore pg_dump backups
|
|
13
|
+
- **Backup restore** - Restore pg_dump/mysqldump backups
|
|
13
14
|
- **Custom database names** - Specify database name separate from container name
|
|
14
15
|
- **Engine management** - View installed PostgreSQL versions and free up disk space
|
|
15
|
-
- **Dynamic version selection** - Fetches
|
|
16
|
+
- **Dynamic version selection** - Fetches available PostgreSQL versions from Maven Central
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -31,7 +32,8 @@ pnpm add -g spindb
|
|
|
31
32
|
spindb
|
|
32
33
|
|
|
33
34
|
# Or use commands directly
|
|
34
|
-
spindb create mydb
|
|
35
|
+
spindb create mydb # PostgreSQL (default)
|
|
36
|
+
spindb create mydb --engine mysql # MySQL
|
|
35
37
|
spindb list
|
|
36
38
|
spindb connect mydb
|
|
37
39
|
```
|
|
@@ -43,96 +45,115 @@ spindb connect mydb
|
|
|
43
45
|
| `spindb` | Open interactive menu |
|
|
44
46
|
| `spindb create [name]` | Create a new database container |
|
|
45
47
|
| `spindb list` | List all containers |
|
|
48
|
+
| `spindb info [name]` | Show container details (or all containers) |
|
|
46
49
|
| `spindb start [name]` | Start a container |
|
|
47
50
|
| `spindb stop [name]` | Stop a container |
|
|
48
|
-
| `spindb connect [name]` | Connect with psql |
|
|
51
|
+
| `spindb connect [name]` | Connect with psql/mysql shell |
|
|
52
|
+
| `spindb url [name]` | Output connection string |
|
|
53
|
+
| `spindb edit [name]` | Edit container properties (rename, port) |
|
|
49
54
|
| `spindb restore [name] [backup]` | Restore a backup file |
|
|
50
55
|
| `spindb clone [source] [target]` | Clone a container |
|
|
51
56
|
| `spindb delete [name]` | Delete a container |
|
|
57
|
+
| `spindb engines` | List installed database engines |
|
|
58
|
+
| `spindb engines delete` | Delete an installed engine version |
|
|
52
59
|
| `spindb config show` | Show configuration |
|
|
53
|
-
| `spindb config detect` | Auto-detect
|
|
60
|
+
| `spindb config detect` | Auto-detect database tools |
|
|
54
61
|
| `spindb deps check` | Check status of client tools |
|
|
55
62
|
| `spindb deps install` | Install missing client tools |
|
|
56
63
|
|
|
57
|
-
##
|
|
64
|
+
## Supported Engines
|
|
65
|
+
|
|
66
|
+
### PostgreSQL 🐘
|
|
67
|
+
|
|
68
|
+
- Downloads server binaries from [zonky.io embedded-postgres-binaries](https://github.com/zonkyio/embedded-postgres-binaries)
|
|
69
|
+
- Versions: 14, 15, 16, 17
|
|
70
|
+
- Requires system client tools (psql, pg_dump, pg_restore) for some operations
|
|
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
|
+
|
|
74
|
+
### MySQL 🐬
|
|
58
75
|
|
|
59
|
-
|
|
76
|
+
- Uses system-installed MySQL (via Homebrew, apt, etc.)
|
|
77
|
+
- Version determined by system installation
|
|
78
|
+
- Requires: mysqld, mysql, mysqldump, mysqladmin
|
|
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
|
+
|
|
89
|
+
## How It Works
|
|
60
90
|
|
|
61
91
|
Data is stored in `~/.spindb/`:
|
|
62
92
|
```
|
|
63
93
|
~/.spindb/
|
|
64
|
-
├── bin/
|
|
65
|
-
│ └── postgresql-
|
|
66
|
-
├── containers/
|
|
67
|
-
│
|
|
68
|
-
│
|
|
69
|
-
│ ├──
|
|
70
|
-
│
|
|
71
|
-
└──
|
|
94
|
+
├── bin/ # PostgreSQL server binaries
|
|
95
|
+
│ └── postgresql-17-darwin-arm64/
|
|
96
|
+
├── containers/
|
|
97
|
+
│ ├── postgresql/ # PostgreSQL containers
|
|
98
|
+
│ │ └── mydb/
|
|
99
|
+
│ │ ├── container.json
|
|
100
|
+
│ │ ├── data/
|
|
101
|
+
│ │ └── postgres.log
|
|
102
|
+
│ └── mysql/ # MySQL containers
|
|
103
|
+
│ └── mydb/
|
|
104
|
+
│ ├── container.json
|
|
105
|
+
│ ├── data/
|
|
106
|
+
│ └── mysql.log
|
|
107
|
+
└── config.json
|
|
72
108
|
```
|
|
73
109
|
|
|
74
|
-
##
|
|
110
|
+
## Client Tools
|
|
75
111
|
|
|
76
|
-
SpinDB bundles the PostgreSQL **server**
|
|
112
|
+
SpinDB bundles the PostgreSQL **server** but not client tools. For `connect` and `restore` commands, you need client tools installed.
|
|
77
113
|
|
|
78
114
|
### Automatic Installation
|
|
79
115
|
|
|
80
|
-
SpinDB can check and install client tools automatically:
|
|
81
|
-
|
|
82
116
|
```bash
|
|
83
117
|
# Check status of all client tools
|
|
84
118
|
spindb deps check
|
|
85
119
|
|
|
86
|
-
# Install missing tools
|
|
120
|
+
# Install missing tools
|
|
87
121
|
spindb deps install
|
|
88
122
|
|
|
89
123
|
# Install for a specific engine
|
|
90
124
|
spindb deps install --engine postgresql
|
|
91
125
|
spindb deps install --engine mysql
|
|
92
|
-
|
|
93
|
-
# Install all missing dependencies for all engines
|
|
94
|
-
spindb deps install --all
|
|
95
|
-
|
|
96
|
-
# List all supported dependencies
|
|
97
|
-
spindb deps list
|
|
98
126
|
```
|
|
99
127
|
|
|
128
|
+
**Note:** On Linux, package managers (apt, pacman, dnf) require `sudo` privileges. You may be prompted for your password when installing dependencies.
|
|
129
|
+
|
|
100
130
|
### Manual Installation
|
|
101
131
|
|
|
102
|
-
|
|
132
|
+
#### PostgreSQL
|
|
103
133
|
|
|
104
134
|
```bash
|
|
105
|
-
# macOS (Homebrew)
|
|
135
|
+
# macOS (Homebrew) - use the latest PostgreSQL version (currently 17)
|
|
106
136
|
brew install postgresql@17
|
|
107
137
|
brew link --overwrite postgresql@17
|
|
108
138
|
|
|
109
139
|
# Ubuntu/Debian
|
|
110
140
|
sudo apt install postgresql-client
|
|
111
141
|
|
|
112
|
-
# CentOS/RHEL
|
|
113
|
-
sudo yum install postgresql
|
|
114
|
-
|
|
115
|
-
# Fedora
|
|
116
|
-
sudo dnf install postgresql
|
|
117
|
-
|
|
118
142
|
# Arch
|
|
119
143
|
sudo pacman -S postgresql-libs
|
|
120
|
-
|
|
121
|
-
# Or use Postgres.app (macOS)
|
|
122
|
-
# Client tools are automatically detected
|
|
123
144
|
```
|
|
124
145
|
|
|
125
|
-
|
|
146
|
+
#### MySQL
|
|
126
147
|
|
|
127
148
|
```bash
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
# macOS (Homebrew)
|
|
150
|
+
brew install mysql
|
|
130
151
|
|
|
131
|
-
|
|
152
|
+
# Ubuntu/Debian
|
|
153
|
+
sudo apt install mysql-server
|
|
132
154
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
spindb config set pg_restore /path/to/pg_restore
|
|
155
|
+
# Arch
|
|
156
|
+
sudo pacman -S mysql
|
|
136
157
|
```
|
|
137
158
|
|
|
138
159
|
## Supported Platforms
|
|
@@ -140,53 +161,31 @@ spindb config set pg_restore /path/to/pg_restore
|
|
|
140
161
|
- macOS (Apple Silicon & Intel)
|
|
141
162
|
- Linux (x64 & ARM64)
|
|
142
163
|
|
|
143
|
-
## Supported PostgreSQL Versions
|
|
144
|
-
|
|
145
|
-
- PostgreSQL 14
|
|
146
|
-
- PostgreSQL 15
|
|
147
|
-
- PostgreSQL 16
|
|
148
|
-
- PostgreSQL 17
|
|
149
|
-
|
|
150
164
|
## Examples
|
|
151
165
|
|
|
152
|
-
### Create
|
|
166
|
+
### Create databases
|
|
153
167
|
|
|
154
168
|
```bash
|
|
155
|
-
#
|
|
156
|
-
spindb create mydb --
|
|
169
|
+
# PostgreSQL with specific version and port
|
|
170
|
+
spindb create mydb --engine postgresql --version 16 --port 5433
|
|
157
171
|
|
|
158
|
-
#
|
|
172
|
+
# MySQL
|
|
173
|
+
spindb create mydb --engine mysql --port 3307
|
|
174
|
+
|
|
175
|
+
# With custom database name
|
|
159
176
|
spindb create mydb --database my_app_db
|
|
160
|
-
# Connection string: postgresql://postgres@localhost:5432/my_app_db
|
|
161
177
|
```
|
|
162
178
|
|
|
163
179
|
### Create and restore in one command
|
|
164
180
|
|
|
165
181
|
```bash
|
|
166
|
-
# Create
|
|
182
|
+
# Create and restore from a dump file
|
|
167
183
|
spindb create mydb --from ./backup.dump
|
|
168
184
|
|
|
169
|
-
# Create
|
|
185
|
+
# Create and pull from a remote database
|
|
170
186
|
spindb create mydb --from "postgresql://user:pass@remote-host:5432/production_db"
|
|
171
|
-
|
|
172
|
-
# With specific version and database name
|
|
173
|
-
spindb create mydb --pg-version 17 --database myapp --from ./backup.dump
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
The `--from` option auto-detects whether the location is a file path or connection string.
|
|
177
|
-
|
|
178
|
-
### Restore to an existing container
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
# Restore from a dump file (supports .sql, custom format, and tar format)
|
|
182
|
-
spindb restore mydb ./backup.dump -d myapp
|
|
183
|
-
|
|
184
|
-
# Or pull directly from a remote database
|
|
185
|
-
spindb restore mydb --from-url "postgresql://user:pass@remote-host:5432/production_db" -d myapp
|
|
186
187
|
```
|
|
187
188
|
|
|
188
|
-
The interactive menu (`spindb` → "Restore backup") also offers an option to create a new container as part of the restore flow.
|
|
189
|
-
|
|
190
189
|
### Clone for testing
|
|
191
190
|
|
|
192
191
|
```bash
|
|
@@ -200,63 +199,102 @@ spindb clone production-copy test-branch
|
|
|
200
199
|
spindb start test-branch
|
|
201
200
|
```
|
|
202
201
|
|
|
203
|
-
### Connect
|
|
202
|
+
### Connect to databases
|
|
204
203
|
|
|
205
204
|
```bash
|
|
206
|
-
# Interactive
|
|
205
|
+
# Interactive shell (auto-detects engine)
|
|
207
206
|
spindb connect mydb
|
|
208
207
|
|
|
209
|
-
# Or use
|
|
208
|
+
# Or use connection string directly
|
|
210
209
|
psql postgresql://postgres@localhost:5432/mydb
|
|
210
|
+
mysql -u root -h 127.0.0.1 -P 3306 mydb
|
|
211
211
|
```
|
|
212
212
|
|
|
213
213
|
### Manage installed engines
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
View installed engines with disk usage (PostgreSQL) and system detection (MySQL):
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
spindb engines
|
|
219
|
+
```
|
|
216
220
|
|
|
217
221
|
```
|
|
218
|
-
ENGINE
|
|
222
|
+
ENGINE VERSION SOURCE SIZE
|
|
219
223
|
────────────────────────────────────────────────────────
|
|
220
|
-
postgresql
|
|
221
|
-
postgresql
|
|
222
|
-
|
|
224
|
+
🐘 postgresql 17.7 darwin-arm64 45.2 MB
|
|
225
|
+
🐘 postgresql 16.8 darwin-arm64 44.8 MB
|
|
226
|
+
🐬 mysql 8.0.35 system (system-installed)
|
|
223
227
|
────────────────────────────────────────────────────────
|
|
224
|
-
|
|
228
|
+
|
|
229
|
+
PostgreSQL: 2 version(s), 90.0 MB
|
|
230
|
+
MySQL: system-installed at /opt/homebrew/bin/mysqld
|
|
225
231
|
```
|
|
226
232
|
|
|
227
|
-
|
|
233
|
+
Delete unused PostgreSQL versions to free disk space:
|
|
228
234
|
|
|
229
|
-
|
|
235
|
+
```bash
|
|
236
|
+
spindb engines delete postgresql 16
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Container info and connection strings
|
|
230
240
|
|
|
231
241
|
```bash
|
|
232
|
-
#
|
|
233
|
-
spindb
|
|
242
|
+
# View all container details
|
|
243
|
+
spindb info
|
|
234
244
|
|
|
235
|
-
#
|
|
236
|
-
spindb
|
|
245
|
+
# View specific container
|
|
246
|
+
spindb info mydb
|
|
237
247
|
|
|
238
|
-
#
|
|
239
|
-
spindb
|
|
248
|
+
# Get connection string for scripting
|
|
249
|
+
spindb url mydb
|
|
250
|
+
export DATABASE_URL=$(spindb url mydb)
|
|
251
|
+
psql $(spindb url mydb)
|
|
240
252
|
|
|
241
|
-
#
|
|
242
|
-
spindb
|
|
253
|
+
# Copy connection string to clipboard
|
|
254
|
+
spindb url mydb --copy
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Edit containers
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# Rename a container (must be stopped)
|
|
261
|
+
spindb edit mydb --name newname
|
|
262
|
+
|
|
263
|
+
# Change port
|
|
264
|
+
spindb edit mydb --port 5433
|
|
265
|
+
|
|
266
|
+
# Interactive mode
|
|
267
|
+
spindb edit mydb
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Running Tests
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Run all tests (PostgreSQL + MySQL)
|
|
274
|
+
pnpm test
|
|
275
|
+
|
|
276
|
+
# Run individual test suites
|
|
277
|
+
pnpm test:pg
|
|
278
|
+
pnpm test:mysql
|
|
243
279
|
```
|
|
244
280
|
|
|
245
281
|
## Troubleshooting
|
|
246
282
|
|
|
247
283
|
### Port already in use
|
|
248
284
|
|
|
249
|
-
SpinDB automatically finds an available port
|
|
285
|
+
SpinDB automatically finds an available port. You can also specify one:
|
|
250
286
|
|
|
251
287
|
```bash
|
|
252
288
|
spindb create mydb --port 5433
|
|
253
289
|
```
|
|
254
290
|
|
|
255
|
-
###
|
|
291
|
+
### Client tool not found
|
|
256
292
|
|
|
257
|
-
Install
|
|
293
|
+
Install client tools or configure the path:
|
|
258
294
|
|
|
259
295
|
```bash
|
|
296
|
+
spindb deps install
|
|
297
|
+
# or
|
|
260
298
|
spindb config set psql /path/to/psql
|
|
261
299
|
```
|
|
262
300
|
|
|
@@ -265,7 +303,8 @@ spindb config set psql /path/to/psql
|
|
|
265
303
|
Check the logs:
|
|
266
304
|
|
|
267
305
|
```bash
|
|
268
|
-
cat ~/.spindb/containers/mydb/postgres.log
|
|
306
|
+
cat ~/.spindb/containers/postgresql/mydb/postgres.log
|
|
307
|
+
cat ~/.spindb/containers/mysql/mydb/mysql.log
|
|
269
308
|
```
|
|
270
309
|
|
|
271
310
|
### Reset everything
|
|
@@ -274,6 +313,73 @@ cat ~/.spindb/containers/mydb/postgres.log
|
|
|
274
313
|
rm -rf ~/.spindb
|
|
275
314
|
```
|
|
276
315
|
|
|
316
|
+
## Project Structure
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
spindb/
|
|
320
|
+
├── bin.ts # Entry point (#!/usr/bin/env tsx)
|
|
321
|
+
├── cli/
|
|
322
|
+
│ ├── index.ts # Commander setup, routes to commands
|
|
323
|
+
│ ├── commands/ # CLI commands
|
|
324
|
+
│ │ ├── menu.ts # Interactive arrow-key menu
|
|
325
|
+
│ │ ├── create.ts # Create container command
|
|
326
|
+
│ │ ├── delete.ts # Delete container command
|
|
327
|
+
│ │ └── ... # Other commands
|
|
328
|
+
│ └── ui/
|
|
329
|
+
│ ├── prompts.ts # Inquirer prompts
|
|
330
|
+
│ ├── spinner.ts # Ora spinner helpers
|
|
331
|
+
│ └── theme.ts # Chalk color theme
|
|
332
|
+
├── core/
|
|
333
|
+
│ ├── binary-manager.ts # Downloads PostgreSQL from zonky.io
|
|
334
|
+
│ ├── config-manager.ts # Manages ~/.spindb/config.json
|
|
335
|
+
│ ├── container-manager.ts # CRUD for containers
|
|
336
|
+
│ ├── port-manager.ts # Port availability checking
|
|
337
|
+
│ ├── process-manager.ts # Process start/stop wrapper
|
|
338
|
+
│ ├── dependency-manager.ts # Client tool detection
|
|
339
|
+
│ ├── error-handler.ts # Centralized error handling
|
|
340
|
+
│ └── transaction-manager.ts # Rollback support for operations
|
|
341
|
+
├── config/
|
|
342
|
+
│ ├── paths.ts # ~/.spindb/ path definitions
|
|
343
|
+
│ ├── defaults.ts # Default values, platform mappings
|
|
344
|
+
│ └── os-dependencies.ts # OS-specific dependency definitions
|
|
345
|
+
├── engines/
|
|
346
|
+
│ ├── base-engine.ts # Abstract base class
|
|
347
|
+
│ ├── index.ts # Engine registry
|
|
348
|
+
│ ├── postgresql/
|
|
349
|
+
│ │ ├── index.ts # PostgreSQL engine implementation
|
|
350
|
+
│ │ ├── binary-urls.ts # Zonky.io URL builder
|
|
351
|
+
│ │ ├── restore.ts # Backup detection and restore
|
|
352
|
+
│ │ └── version-validator.ts # Version compatibility checks
|
|
353
|
+
│ └── mysql/
|
|
354
|
+
│ ├── index.ts # MySQL engine implementation
|
|
355
|
+
│ ├── binary-detection.ts # MySQL binary path detection
|
|
356
|
+
│ ├── restore.ts # Backup detection and restore
|
|
357
|
+
│ └── version-validator.ts # Version compatibility checks
|
|
358
|
+
├── types/
|
|
359
|
+
│ └── index.ts # TypeScript interfaces
|
|
360
|
+
└── tests/
|
|
361
|
+
├── unit/ # Unit tests
|
|
362
|
+
├── integration/ # Integration tests
|
|
363
|
+
└── fixtures/ # Test data
|
|
364
|
+
├── postgresql/
|
|
365
|
+
│ └── seeds/
|
|
366
|
+
└── mysql/
|
|
367
|
+
└── seeds/
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Contributing
|
|
371
|
+
|
|
372
|
+
### Version Updates
|
|
373
|
+
|
|
374
|
+
SpinDB uses versioned PostgreSQL packages from Homebrew (e.g., `postgresql@17`). When new major versions are released:
|
|
375
|
+
|
|
376
|
+
1. Check [PostgreSQL releases](https://www.postgresql.org/docs/release/) and [Homebrew formulae](https://formulae.brew.sh/formula/postgresql)
|
|
377
|
+
2. Update `config/engine-defaults.ts`:
|
|
378
|
+
- Change `latestVersion` to the new version
|
|
379
|
+
- Add the new version to `supportedVersions`
|
|
380
|
+
|
|
381
|
+
See `CLAUDE.md` for detailed maintenance instructions.
|
|
382
|
+
|
|
277
383
|
## License
|
|
278
384
|
|
|
279
385
|
MIT
|
package/cli/commands/clone.ts
CHANGED
|
@@ -58,7 +58,9 @@ export const cloneCommand = new Command('clone')
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Check source is stopped
|
|
61
|
-
const running = await processManager.isRunning(sourceName
|
|
61
|
+
const running = await processManager.isRunning(sourceName, {
|
|
62
|
+
engine: sourceConfig.engine,
|
|
63
|
+
})
|
|
62
64
|
if (running) {
|
|
63
65
|
console.error(
|
|
64
66
|
error(
|
package/cli/commands/connect.ts
CHANGED
|
@@ -4,14 +4,15 @@ import chalk from 'chalk'
|
|
|
4
4
|
import { containerManager } from '../../core/container-manager'
|
|
5
5
|
import { processManager } from '../../core/process-manager'
|
|
6
6
|
import { getEngine } from '../../engines'
|
|
7
|
+
import { getEngineDefaults } from '../../config/defaults'
|
|
7
8
|
import { promptContainerSelect } from '../ui/prompts'
|
|
8
9
|
import { error, warning, info } from '../ui/theme'
|
|
9
10
|
|
|
10
11
|
export const connectCommand = new Command('connect')
|
|
11
|
-
.description('Connect to a container with
|
|
12
|
+
.description('Connect to a container with database client')
|
|
12
13
|
.argument('[name]', 'Container name')
|
|
13
|
-
.option('-d, --database <name>', 'Database name'
|
|
14
|
-
.action(async (name: string | undefined, options: { database
|
|
14
|
+
.option('-d, --database <name>', 'Database name')
|
|
15
|
+
.action(async (name: string | undefined, options: { database?: string }) => {
|
|
15
16
|
try {
|
|
16
17
|
let containerName = name
|
|
17
18
|
|
|
@@ -50,8 +51,17 @@ export const connectCommand = new Command('connect')
|
|
|
50
51
|
process.exit(1)
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
const { engine: engineName } = config
|
|
55
|
+
const engineDefaults = getEngineDefaults(engineName)
|
|
56
|
+
|
|
57
|
+
// Default database: container's database or superuser
|
|
58
|
+
const database =
|
|
59
|
+
options.database ?? config.database ?? engineDefaults.superuser
|
|
60
|
+
|
|
53
61
|
// Check if running
|
|
54
|
-
const running = await processManager.isRunning(containerName
|
|
62
|
+
const running = await processManager.isRunning(containerName, {
|
|
63
|
+
engine: engineName,
|
|
64
|
+
})
|
|
55
65
|
if (!running) {
|
|
56
66
|
console.error(
|
|
57
67
|
error(`Container "${containerName}" is not running. Start it first.`),
|
|
@@ -60,35 +70,55 @@ export const connectCommand = new Command('connect')
|
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
// Get engine
|
|
63
|
-
const engine = getEngine(
|
|
64
|
-
const connectionString = engine.getConnectionString(
|
|
65
|
-
config,
|
|
66
|
-
options.database,
|
|
67
|
-
)
|
|
73
|
+
const engine = getEngine(engineName)
|
|
74
|
+
const connectionString = engine.getConnectionString(config, database)
|
|
68
75
|
|
|
69
|
-
console.log(info(`Connecting to ${containerName}:${
|
|
76
|
+
console.log(info(`Connecting to ${containerName}:${database}...`))
|
|
70
77
|
console.log()
|
|
71
78
|
|
|
72
|
-
//
|
|
73
|
-
|
|
79
|
+
// Build client command based on engine
|
|
80
|
+
let clientCmd: string
|
|
81
|
+
let clientArgs: string[]
|
|
82
|
+
|
|
83
|
+
if (engineName === 'mysql') {
|
|
84
|
+
// MySQL: mysql -h 127.0.0.1 -P port -u root database
|
|
85
|
+
clientCmd = 'mysql'
|
|
86
|
+
clientArgs = [
|
|
87
|
+
'-h',
|
|
88
|
+
'127.0.0.1',
|
|
89
|
+
'-P',
|
|
90
|
+
String(config.port),
|
|
91
|
+
'-u',
|
|
92
|
+
engineDefaults.superuser,
|
|
93
|
+
database,
|
|
94
|
+
]
|
|
95
|
+
} else {
|
|
96
|
+
// PostgreSQL: psql connection_string
|
|
97
|
+
clientCmd = 'psql'
|
|
98
|
+
clientArgs = [connectionString]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const clientProcess = spawn(clientCmd, clientArgs, {
|
|
74
102
|
stdio: 'inherit',
|
|
75
103
|
})
|
|
76
104
|
|
|
77
|
-
|
|
105
|
+
clientProcess.on('error', (err: NodeJS.ErrnoException) => {
|
|
78
106
|
if (err.code === 'ENOENT') {
|
|
79
|
-
console.log(warning(
|
|
107
|
+
console.log(warning(`${clientCmd} not found on your system.`))
|
|
80
108
|
console.log()
|
|
81
|
-
console.log(
|
|
82
|
-
chalk.gray(
|
|
83
|
-
' Install PostgreSQL client tools or connect manually:',
|
|
84
|
-
),
|
|
85
|
-
)
|
|
109
|
+
console.log(chalk.gray(' Install client tools or connect manually:'))
|
|
86
110
|
console.log(chalk.cyan(` ${connectionString}`))
|
|
87
111
|
console.log()
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
chalk.
|
|
91
|
-
|
|
112
|
+
|
|
113
|
+
if (engineName === 'mysql') {
|
|
114
|
+
console.log(chalk.gray(' On macOS with Homebrew:'))
|
|
115
|
+
console.log(chalk.cyan(' brew install mysql-client'))
|
|
116
|
+
} else {
|
|
117
|
+
console.log(chalk.gray(' On macOS with Homebrew:'))
|
|
118
|
+
console.log(
|
|
119
|
+
chalk.cyan(' brew install libpq && brew link --force libpq'),
|
|
120
|
+
)
|
|
121
|
+
}
|
|
92
122
|
console.log()
|
|
93
123
|
} else {
|
|
94
124
|
console.error(error(err.message))
|
|
@@ -96,7 +126,7 @@ export const connectCommand = new Command('connect')
|
|
|
96
126
|
})
|
|
97
127
|
|
|
98
128
|
await new Promise<void>((resolve) => {
|
|
99
|
-
|
|
129
|
+
clientProcess.on('close', () => resolve())
|
|
100
130
|
})
|
|
101
131
|
} catch (err) {
|
|
102
132
|
const e = err as Error
|