Skip to content

Commit 5b2c823

Browse files
committed
Add CLI with alias management and database migrations
- Multi-backend support via aliases (API and DB) - Config stored in ~/.openworkers/config.json - Database migrations using sqlx (with checksums) - Split enum migrations to fix PostgreSQL transaction issue
1 parent 0a23255 commit 5b2c823

18 files changed

Lines changed: 2763 additions & 14 deletions

Cargo.lock

Lines changed: 2070 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@ version = "0.1.0"
44
edition = "2024"
55
license = "MIT"
66

7+
[[bin]]
8+
name = "ow"
9+
path = "src/main.rs"
10+
711
[dependencies]
12+
clap = { version = "4", features = ["derive"] }
13+
serde = { version = "1", features = ["derive"] }
14+
serde_json = "1"
15+
dirs = "6"
16+
thiserror = "2"
17+
colored = "3"
18+
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
19+
sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "chrono"] }
20+
chrono = { version = "0.4", features = ["serde"] }

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# OpenWorkers CLI
2+
3+
Command-line interface for managing OpenWorkers deployments.
4+
5+
## Installation
6+
7+
```bash
8+
cargo install --path .
9+
```
10+
11+
## Configuration
12+
13+
The CLI uses aliases to connect to different backends. Config is stored in `~/.openworkers/config.json`.
14+
15+
### Alias Types
16+
17+
- **API**: Connect via REST API (hosted or self-hosted)
18+
- **DB**: Direct PostgreSQL connection (for infra/migrations)
19+
20+
### Managing Aliases
21+
22+
```bash
23+
# Add API alias
24+
ow alias set cloud --api https://dash.openworkers.com/api/v1 --token <token>
25+
ow alias set local --api http://localhost:3000 --token dev
26+
27+
# Add DB alias
28+
ow alias set infra --db postgres://user:pass@host/db
29+
30+
# List aliases
31+
ow alias list
32+
33+
# Set default
34+
ow alias set-default cloud
35+
36+
# Remove alias
37+
ow alias rm old-alias
38+
```
39+
40+
### Default Alias
41+
42+
On first run, a `cloud` alias pointing to `https://dash.openworkers.com/api/v1` is created as default.
43+
44+
## Commands
45+
46+
### Database Operations
47+
48+
Requires a `db` type alias.
49+
50+
```bash
51+
# Run pending migrations
52+
ow --alias infra db migrate
53+
54+
# Check migration status
55+
ow --alias infra db status
56+
```
57+
58+
### Using Aliases
59+
60+
```bash
61+
# Use default alias
62+
ow db status
63+
64+
# Use specific alias
65+
ow --alias infra db migrate
66+
```
67+
68+
## Config File Format
69+
70+
```json
71+
{
72+
"version": 1,
73+
"default": "cloud",
74+
"aliases": {
75+
"cloud": {
76+
"type": "api",
77+
"url": "https://dash.openworkers.com/api/v1",
78+
"token": "owk_xxx"
79+
},
80+
"infra": {
81+
"type": "db",
82+
"database_url": "postgres://user:pass@host/db"
83+
}
84+
}
85+
}
86+
```
87+
88+
## Development
89+
90+
```bash
91+
# Build
92+
cargo build
93+
94+
# Run
95+
cargo run -- alias list
96+
cargo run -- --alias infra db status
97+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- OpenWorkers Database Schema - Add 'database' binding type
3+
--
4+
-- Must be separate from 09b because PostgreSQL cannot use
5+
-- a newly added enum value in the same transaction.
6+
--
7+
8+
ALTER TYPE enum_binding_type ADD VALUE 'database';
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
-- - postgres: direct connection (can be Supabase, PlanetScale, Neon, etc.)
77
--
88

9-
-- ============================================================================
10-
-- UPDATE ENUM: Add 'database' to binding types
11-
-- ============================================================================
12-
13-
ALTER TYPE enum_binding_type ADD VALUE 'database';
14-
159
-- ============================================================================
1610
-- TABLE: database_configs
1711
-- ============================================================================
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--
2+
-- OpenWorkers Database Schema - Add 'worker' binding type
3+
--
4+
-- Must be separate from 11b because PostgreSQL cannot use
5+
-- a newly added enum value in the same transaction.
6+
--
7+
8+
ALTER TYPE enum_binding_type ADD VALUE 'worker';
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
-- The binding value references workers.id directly (no config table needed)
66
--
77

8-
-- ============================================================================
9-
-- UPDATE ENUM: Add 'worker' to binding types
10-
-- ============================================================================
11-
12-
ALTER TYPE enum_binding_type ADD VALUE 'worker';
13-
148
-- ============================================================================
159
-- UPDATE CONSTRAINT: Add 'worker' to environment_values check
1610
-- ============================================================================

0 commit comments

Comments
 (0)