prax-orm-cli 0.9.2

CLI tool for the Prax ORM
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
//! CLI argument definitions using clap.

use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;

/// Prax CLI - A modern ORM for Rust
#[derive(Parser, Debug)]
#[command(name = "prax")]
#[command(author = "Pegasus Heavy Industries LLC")]
#[command(version)]
#[command(about = "Prax CLI - A modern ORM for Rust", long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
    /// Subcommand to execute
    #[command(subcommand)]
    pub command: Command,
}

/// Available CLI commands
#[derive(Subcommand, Debug)]
pub enum Command {
    /// Initialize a new Prax project
    Init(InitArgs),

    /// Generate Rust client code from schema
    Generate(GenerateArgs),

    /// Schema validation and formatting
    Validate(ValidateArgs),

    /// Format schema file
    Format(FormatArgs),

    /// Database migration commands
    Migrate(MigrateArgs),

    /// Direct database operations
    Db(DbArgs),

    /// Import schema from Prisma or Diesel
    Import(ImportArgs),

    /// Display version information
    Version,
}

// =============================================================================
// Init Command
// =============================================================================

/// Arguments for the `init` command
#[derive(Args, Debug)]
pub struct InitArgs {
    /// Path to initialize the project (defaults to current directory)
    #[arg(default_value = ".")]
    pub path: PathBuf,

    /// Database provider to use
    #[arg(short, long, default_value = "postgresql")]
    pub provider: DatabaseProvider,

    /// Database connection URL
    #[arg(short, long)]
    pub url: Option<String>,

    /// Skip generating example schema
    #[arg(long)]
    pub no_example: bool,

    /// Accept all defaults without prompting
    #[arg(short, long)]
    pub yes: bool,
}

/// Supported database providers
#[derive(ValueEnum, Debug, Clone, Copy, Default)]
pub enum DatabaseProvider {
    #[default]
    Postgresql,
    Mysql,
    Sqlite,
}

impl std::fmt::Display for DatabaseProvider {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            DatabaseProvider::Postgresql => write!(f, "postgresql"),
            DatabaseProvider::Mysql => write!(f, "mysql"),
            DatabaseProvider::Sqlite => write!(f, "sqlite"),
        }
    }
}

// =============================================================================
// Generate Command
// =============================================================================

/// Arguments for the `generate` command
#[derive(Args, Debug)]
pub struct GenerateArgs {
    /// Path to schema file
    #[arg(short, long)]
    pub schema: Option<PathBuf>,

    /// Output directory for generated code
    #[arg(short, long)]
    pub output: Option<PathBuf>,

    /// Features to generate (e.g., serde, graphql)
    #[arg(short, long, value_delimiter = ',')]
    pub features: Vec<String>,

    /// Watch for schema changes and regenerate
    #[arg(short, long)]
    pub watch: bool,
}

// =============================================================================
// Validate Command
// =============================================================================

/// Arguments for the `validate` command
#[derive(Args, Debug)]
pub struct ValidateArgs {
    /// Path to schema file
    #[arg(short, long)]
    pub schema: Option<PathBuf>,
}

// =============================================================================
// Format Command
// =============================================================================

/// Arguments for the `format` command
#[derive(Args, Debug)]
pub struct FormatArgs {
    /// Path to schema file
    #[arg(short, long)]
    pub schema: Option<PathBuf>,

    /// Check formatting without writing changes
    #[arg(short, long)]
    pub check: bool,
}

// =============================================================================
// Migrate Command
// =============================================================================

/// Arguments for the `migrate` command
#[derive(Args, Debug)]
pub struct MigrateArgs {
    #[command(subcommand)]
    pub command: MigrateSubcommand,
}

/// Migrate subcommands
#[derive(Subcommand, Debug)]
pub enum MigrateSubcommand {
    /// Create and apply migrations during development
    Dev(MigrateDevArgs),

    /// Deploy pending migrations to production
    Deploy,

    /// Reset database and re-apply all migrations
    Reset(MigrateResetArgs),

    /// Show migration status
    Status,

    /// Resolve migration issues
    Resolve(MigrateResolveArgs),

    /// Generate migration diff without applying
    Diff(MigrateDiffArgs),

    /// Rollback the last applied migration
    Rollback(MigrateRollbackArgs),

    /// View migration history
    History(MigrateHistoryArgs),
}

/// Arguments for `migrate dev`
#[derive(Args, Debug)]
pub struct MigrateDevArgs {
    /// Name for the migration
    #[arg(short, long)]
    pub name: Option<String>,

    /// Create migration without applying
    #[arg(long)]
    pub create_only: bool,

    /// Skip seed after migration
    #[arg(long)]
    pub skip_seed: bool,

    /// Path to schema file
    #[arg(short, long)]
    pub schema: Option<PathBuf>,
}

/// Arguments for `migrate reset`
#[derive(Args, Debug)]
pub struct MigrateResetArgs {
    /// Skip confirmation prompt
    #[arg(short, long)]
    pub force: bool,

    /// Run seed after reset
    #[arg(long)]
    pub seed: bool,

    /// Skip applying migrations (just reset)
    #[arg(long)]
    pub skip_migrations: bool,
}

/// Arguments for `migrate resolve`
#[derive(Args, Debug)]
pub struct MigrateResolveArgs {
    /// Name of the migration to resolve
    pub migration: String,

    /// Mark migration as applied
    #[arg(long)]
    pub applied: bool,

    /// Mark migration as rolled back
    #[arg(long)]
    pub rolled_back: bool,
}

/// Arguments for `migrate diff`
#[derive(Args, Debug)]
pub struct MigrateDiffArgs {
    /// Path to schema file
    #[arg(short, long)]
    pub schema: Option<PathBuf>,

    /// Output path for generated SQL
    #[arg(short, long)]
    pub output: Option<PathBuf>,

    /// Compare against a specific migration
    #[arg(long)]
    pub from_migration: Option<String>,
}

/// Arguments for `migrate rollback`
#[derive(Args, Debug)]
pub struct MigrateRollbackArgs {
    /// Reason for rollback
    #[arg(long)]
    pub reason: Option<String>,

    /// User performing the rollback
    #[arg(long)]
    pub user: Option<String>,

    /// Rollback to a specific migration
    #[arg(long)]
    pub to: Option<String>,
}

/// Arguments for `migrate history`
#[derive(Args, Debug)]
pub struct MigrateHistoryArgs {
    /// Show history for a specific migration
    #[arg(long)]
    pub migration: Option<String>,
}

// =============================================================================
// Db Command
// =============================================================================

/// Arguments for the `db` command
#[derive(Args, Debug)]
pub struct DbArgs {
    #[command(subcommand)]
    pub command: DbSubcommand,
}

/// Db subcommands
#[derive(Subcommand, Debug)]
pub enum DbSubcommand {
    /// Push schema to database without migrations
    Push(DbPushArgs),

    /// Introspect database and generate schema
    Pull(DbPullArgs),

    /// Seed database with initial data
    Seed(DbSeedArgs),

    /// Execute raw SQL
    Execute(DbExecuteArgs),
}

/// Arguments for `db push`
#[derive(Args, Debug)]
pub struct DbPushArgs {
    /// Path to schema file
    #[arg(short, long)]
    pub schema: Option<PathBuf>,

    /// Accept data loss from destructive changes
    #[arg(long)]
    pub accept_data_loss: bool,

    /// Skip confirmation prompts
    #[arg(short, long)]
    pub force: bool,

    /// Reset database before push
    #[arg(long)]
    pub reset: bool,
}

/// Arguments for `db pull`
#[derive(Args, Debug)]
pub struct DbPullArgs {
    /// Output path for generated schema
    #[arg(short, long)]
    pub output: Option<PathBuf>,

    /// Overwrite existing schema without prompting
    #[arg(short, long)]
    pub force: bool,

    /// Include views in introspection
    #[arg(long)]
    pub include_views: bool,

    /// Include materialized views in introspection
    #[arg(long)]
    pub include_materialized_views: bool,

    /// Schema/namespace to introspect (default: public for PostgreSQL, dbo for MSSQL)
    #[arg(long)]
    pub schema: Option<String>,

    /// Filter tables by pattern (glob-style, e.g., "user*")
    #[arg(long)]
    pub tables: Option<String>,

    /// Exclude tables by pattern (glob-style, e.g., "_prisma*")
    #[arg(long)]
    pub exclude: Option<String>,

    /// Print schema to stdout instead of writing to file
    #[arg(long)]
    pub print: bool,

    /// Output format
    #[arg(long, default_value = "prax")]
    pub format: OutputFormat,

    /// Number of documents to sample for MongoDB schema inference
    #[arg(long, default_value = "100")]
    pub sample_size: usize,

    /// Include column comments in schema
    #[arg(long)]
    pub comments: bool,
}

/// Output format for schema introspection
#[derive(ValueEnum, Debug, Clone, Copy, Default)]
pub enum OutputFormat {
    /// Prax schema format (.prax)
    #[default]
    Prax,
    /// JSON format
    Json,
    /// SQL DDL format
    Sql,
}

/// Arguments for `db seed`
#[derive(Args, Debug)]
pub struct DbSeedArgs {
    /// Path to seed file
    #[arg(short, long)]
    pub seed_file: Option<PathBuf>,

    /// Reset database before seeding
    #[arg(long)]
    pub reset: bool,

    /// Environment to run seed for (development, staging, production)
    #[arg(short, long, default_value = "development")]
    pub environment: String,

    /// Force seeding even if environment config says not to
    #[arg(short, long)]
    pub force: bool,
}

/// Arguments for `db execute`
#[derive(Args, Debug)]
pub struct DbExecuteArgs {
    /// SQL to execute
    #[arg(short, long)]
    pub sql: Option<String>,

    /// Path to SQL file
    #[arg(short, long)]
    pub file: Option<PathBuf>,

    /// Read SQL from stdin
    #[arg(long)]
    pub stdin: bool,

    /// Skip confirmation prompt
    #[arg(short = 'y', long)]
    pub force: bool,
}

// =============================================================================
// Import Command
// =============================================================================

/// Arguments for the `import` command
#[derive(Args, Debug)]
pub struct ImportArgs {
    /// Source ORM to import from
    #[arg(long, value_enum)]
    pub from: ImportSource,

    /// Input schema file path
    #[arg(short, long)]
    pub input: PathBuf,

    /// Output Prax schema file path
    #[arg(short, long)]
    pub output: Option<PathBuf>,

    /// Database provider for the imported schema
    #[arg(short = 'P', long)]
    pub provider: Option<DatabaseProvider>,

    /// Database connection URL for the imported schema
    #[arg(short, long)]
    pub url: Option<String>,

    /// Print to stdout instead of writing to file
    #[arg(long)]
    pub print: bool,

    /// Overwrite existing output file without prompting
    #[arg(short, long)]
    pub force: bool,
}

/// Source ORM for import
#[derive(ValueEnum, Debug, Clone, Copy)]
pub enum ImportSource {
    /// Prisma schema (.prisma files)
    Prisma,
    /// Diesel schema (schema.rs files with table! macros)
    Diesel,
    /// SeaORM entity (entity files with DeriveEntityModel)
    SeaOrm,
}