Skip to content

Commit 0d0592e

Browse files
committed
Rename db command to migrate for clarity
- db → migrate (run, status, baseline) - Add command shortcuts table to README - Update examples to use new command names
1 parent 3416b18 commit 0d0592e

4 files changed

Lines changed: 64 additions & 38 deletions

File tree

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@ ow alias rm old-alias
4141

4242
On first run, a `default` alias pointing to `https://dash.openworkers.com/api/v1` is created as default.
4343

44+
## Command Shortcuts
45+
46+
| Command | Alias | Description |
47+
|---------|-------|-------------|
48+
| `workers list` | `workers ls` | List all workers |
49+
| `workers delete` | `workers rm` | Delete a worker |
50+
| `env list` | `env ls` | List environments |
51+
| `env delete` | `env rm` | Delete environment |
52+
| `kv list` | `kv ls` | List KV namespaces |
53+
| `kv delete` | `kv rm` | Delete KV namespace |
54+
| `storage list` | `storage ls` | List storage configs |
55+
| `storage delete` | `storage rm` | Delete storage config |
56+
| `databases list` | `databases ls` | List databases |
57+
| `databases delete` | `databases rm` | Delete database |
58+
| `alias list` | `alias ls` | List aliases |
59+
| `alias remove` | `alias rm` | Remove alias |
60+
4461
## Commands
4562

4663
### Login
@@ -170,19 +187,19 @@ ow databases create my-pg --provider postgres \
170187
ow databases delete my-db
171188
```
172189

173-
### Infra
190+
### Migrations
174191

175-
Database migrations (requires `db` type alias).
192+
Database schema migrations (requires `db` type alias).
176193

177194
```bash
178-
# Run pending migrations
179-
ow infra db migrate
180-
181195
# Check migration status
182-
ow infra db status
196+
ow local migrate status
197+
198+
# Run pending migrations
199+
ow local migrate run
183200

184201
# Baseline existing database (mark all migrations as applied)
185-
ow infra db baseline
202+
ow local migrate baseline
186203
```
187204

188205
### Using Aliases
@@ -194,7 +211,7 @@ ow workers list
194211
# Use specific alias as first argument
195212
ow prod workers list
196213
ow dev workers get my-api
197-
ow infra db migrate
214+
ow local migrate run
198215

199216
# Or use --alias flag
200217
ow --alias prod workers list
@@ -217,9 +234,10 @@ ow --alias prod workers list
217234
"url": "http://localhost:7000",
218235
"token": "ow_xxx"
219236
},
220-
"infra": {
237+
"local": {
221238
"type": "db",
222-
"database_url": "postgres://user:pass@host/db"
239+
"database_url": "postgres://user:pass@host/db",
240+
"user": "admin@example.com"
223241
}
224242
}
225243
}
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sqlx::{PgPool, Row};
88
static MIGRATOR: Migrator = sqlx::migrate!();
99

1010
#[derive(Debug, thiserror::Error)]
11-
pub enum DbError {
11+
pub enum MigrateError {
1212
#[error("Config error: {0}")]
1313
Config(#[from] ConfigError),
1414

@@ -18,54 +18,62 @@ pub enum DbError {
1818
#[error("Migration error: {0}")]
1919
Migrate(#[from] sqlx::migrate::MigrateError),
2020

21-
#[error("Alias '{0}' is not a database alias. Use --db or configure a db alias.")]
21+
#[error("Alias '{0}' is not a database alias. Use --db when creating the alias.")]
2222
NotDbAlias(String),
2323

2424
#[error("No alias specified and no default alias configured")]
2525
NoAlias,
2626
}
2727

2828
#[derive(Subcommand)]
29-
pub enum DbCommand {
30-
/// Run pending migrations
31-
Migrate,
29+
pub enum MigrateCommand {
30+
/// Run all pending migrations
31+
#[command(after_help = "Example:\n ow local migrate run")]
32+
Run,
3233

33-
/// Show migration status
34+
/// Show which migrations are applied or pending
35+
#[command(after_help = "Example:\n ow local migrate status")]
3436
Status,
3537

36-
/// Mark all migrations as applied without running them (for existing databases)
38+
/// Mark all migrations as applied without running them
39+
#[command(
40+
after_help = "Use this for existing databases that already have the schema.\n\n\
41+
Example:\n ow local migrate baseline"
42+
)]
3743
Baseline,
3844
}
3945

40-
impl DbCommand {
41-
pub async fn run(self, alias: Option<String>) -> Result<(), DbError> {
46+
impl MigrateCommand {
47+
pub async fn run(self, alias: Option<String>) -> Result<(), MigrateError> {
4248
let database_url = resolve_database_url(alias)?;
4349
let pool = connect(&database_url).await?;
4450

4551
match self {
46-
Self::Migrate => cmd_migrate(&pool).await,
52+
Self::Run => cmd_run(&pool).await,
4753
Self::Status => cmd_status(&pool).await,
4854
Self::Baseline => cmd_baseline(&pool).await,
4955
}
5056
}
5157
}
5258

53-
fn resolve_database_url(alias: Option<String>) -> Result<String, DbError> {
59+
fn resolve_database_url(alias: Option<String>) -> Result<String, MigrateError> {
5460
let config = Config::load()?;
5561

56-
let alias_name = alias.or(config.default.clone()).ok_or(DbError::NoAlias)?;
62+
let alias_name = alias
63+
.or(config.default.clone())
64+
.ok_or(MigrateError::NoAlias)?;
5765

5866
let alias_config = config
5967
.get_alias(&alias_name)
6068
.ok_or_else(|| ConfigError::AliasNotFound(alias_name.clone()))?;
6169

6270
match alias_config {
6371
AliasConfig::Db { database_url, .. } => Ok(database_url.clone()),
64-
AliasConfig::Api { .. } => Err(DbError::NotDbAlias(alias_name)),
72+
AliasConfig::Api { .. } => Err(MigrateError::NotDbAlias(alias_name)),
6573
}
6674
}
6775

68-
async fn connect(database_url: &str) -> Result<PgPool, DbError> {
76+
async fn connect(database_url: &str) -> Result<PgPool, MigrateError> {
6977
let pool = PgPoolOptions::new()
7078
.max_connections(1)
7179
.connect(database_url)
@@ -74,7 +82,7 @@ async fn connect(database_url: &str) -> Result<PgPool, DbError> {
7482
Ok(pool)
7583
}
7684

77-
async fn cmd_migrate(pool: &PgPool) -> Result<(), DbError> {
85+
async fn cmd_run(pool: &PgPool) -> Result<(), MigrateError> {
7886
println!("Running migrations...\n");
7987

8088
MIGRATOR.run(pool).await?;
@@ -84,7 +92,7 @@ async fn cmd_migrate(pool: &PgPool) -> Result<(), DbError> {
8492
Ok(())
8593
}
8694

87-
async fn cmd_status(pool: &PgPool) -> Result<(), DbError> {
95+
async fn cmd_status(pool: &PgPool) -> Result<(), MigrateError> {
8896
// Get applied migrations from DB
8997
let applied: Vec<(i64, Vec<u8>)> =
9098
sqlx::query("SELECT version, checksum FROM _sqlx_migrations ORDER BY version")
@@ -135,14 +143,14 @@ async fn cmd_status(pool: &PgPool) -> Result<(), DbError> {
135143
println!(
136144
"{} pending migration(s). Run '{}' to apply.",
137145
pending_count.to_string().yellow(),
138-
"ow db migrate".cyan()
146+
"ow migrate run".cyan()
139147
);
140148
}
141149

142150
Ok(())
143151
}
144152

145-
async fn cmd_baseline(pool: &PgPool) -> Result<(), DbError> {
153+
async fn cmd_baseline(pool: &PgPool) -> Result<(), MigrateError> {
146154
// Create _sqlx_migrations table if it doesn't exist
147155
sqlx::query(
148156
r#"
@@ -170,7 +178,7 @@ async fn cmd_baseline(pool: &PgPool) -> Result<(), DbError> {
170178
"Warning:".yellow().bold(),
171179
count
172180
);
173-
println!("Use '{}' to check status.", "ow db status".cyan());
181+
println!("Use '{}' to check status.", "ow migrate status".cyan());
174182
return Ok(());
175183
}
176184

src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pub mod alias;
22
pub mod databases;
3-
pub mod db;
43
pub mod env;
54
pub mod kv;
65
pub mod login;
6+
pub mod migrate;
77
pub mod storage;
88
pub mod workers;

src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use backend::api::ApiBackend;
1212
use backend::db::DbBackend;
1313
use commands::alias::AliasCommand;
1414
use commands::databases::DatabasesCommand;
15-
use commands::db::DbCommand;
1615
use commands::env::EnvCommand;
1716
use commands::kv::KvCommand;
17+
use commands::migrate::MigrateCommand;
1818
use commands::storage::StorageCommand;
1919
use commands::workers::WorkersCommand;
2020
use config::{AliasConfig, Config, PlatformStorageConfig};
@@ -77,13 +77,13 @@ enum Commands {
7777
ow prod login Login to 'prod' alias")]
7878
Login,
7979

80-
/// Direct database operations (requires db alias with --user)
80+
/// Run database migrations (requires db alias)
8181
#[command(after_help = "Examples:\n \
82-
ow local db migrate Run migrations\n \
83-
ow local db seed Seed initial data")]
84-
Db {
82+
ow local migrate status Show migration status\n \
83+
ow local migrate run Run pending migrations")]
84+
Migrate {
8585
#[command(subcommand)]
86-
command: DbCommand,
86+
command: MigrateCommand,
8787
},
8888

8989
/// Create, deploy, and manage workers
@@ -189,7 +189,7 @@ fn extract_alias_from_args() -> (Option<String>, Vec<String>) {
189189
let known_commands = [
190190
"alias",
191191
"login",
192-
"db",
192+
"migrate",
193193
"workers",
194194
"env",
195195
"storage",
@@ -469,7 +469,7 @@ async fn main() {
469469
.ok_or("No alias specified and no default configured".to_string())?;
470470
commands::login::run(&alias_name).map_err(|e| e.to_string())
471471
})(),
472-
Commands::Db { command } => command.run(alias).await.map_err(|e| e.to_string()),
472+
Commands::Migrate { command } => command.run(alias).await.map_err(|e| e.to_string()),
473473
Commands::Workers { command } => run_workers_command(alias, command).await,
474474
Commands::Env { command } => run_env_command(alias, command).await,
475475
Commands::Storage { command } => run_storage_command(alias, command).await,

0 commit comments

Comments
 (0)