systemprompt_cli/commands/infrastructure/db/
commands.rs1use clap::Subcommand;
7
8#[derive(Debug, Subcommand)]
9pub enum DbCommands {
10 #[command(about = "Execute SQL query (read-only)")]
11 Query {
12 sql: String,
13 #[arg(long)]
14 limit: Option<u32>,
15 #[arg(long)]
16 offset: Option<u32>,
17 },
18 #[command(about = "Execute write operation (INSERT, UPDATE, DELETE)")]
19 Execute { sql: String },
20 #[command(about = "List all tables with row counts and sizes")]
21 Tables {
22 #[arg(long, help = "Filter tables by pattern")]
23 filter: Option<String>,
24 },
25 #[command(about = "Describe table schema with columns and indexes")]
26 Describe { table_name: String },
27 #[command(about = "Show database information")]
28 Info,
29 #[command(about = "Run database migrations")]
30 Migrate {
31 #[arg(
32 long,
33 help = "Continue past migration checksum mismatches with a warning instead of \
34 erroring (use with caution)"
35 )]
36 allow_checksum_drift: bool,
37 },
38 #[command(about = "Revert the most recently applied migrations for an extension")]
39 MigrateDown {
40 #[arg(help = "Extension ID")]
41 extension: String,
42 #[arg(help = "Number of migrations to revert")]
43 count: u32,
44 },
45 #[command(about = "Show migration status and history")]
46 Migrations {
47 #[command(subcommand)]
48 cmd: MigrationsCommands,
49 },
50 #[command(
51 about = "Show pending migrations (dry-run / plan, no DB writes)",
52 name = "migrate-plan"
53 )]
54 MigratePlan {
55 #[arg(help = "Filter by extension ID (default: all extensions)")]
56 extension: Option<String>,
57 #[arg(long, help = "Emit JSON instead of a text table")]
58 json: bool,
59 },
60 #[command(
61 about = "Detailed introspectable migration status (applied, pending, drift)",
62 name = "migrate-status"
63 )]
64 MigrateStatus {
65 #[arg(help = "Filter by extension ID (default: all extensions)")]
66 extension: Option<String>,
67 #[arg(long, help = "Emit JSON instead of a text table")]
68 json: bool,
69 },
70 #[command(
71 about = "Repair migration checksum drift — re-applies edited migrations in place, or with \
72 --reconcile-only rewrites stored checksums without executing SQL",
73 name = "migrate-repair"
74 )]
75 MigrateRepair {
76 #[arg(help = "Limit repair to a single extension (default: all extensions)")]
77 extension: Option<String>,
78 #[arg(
79 long,
80 help = "Apply the repair. Without this flag, the command is a dry-run that only lists \
81 drift."
82 )]
83 apply: bool,
84 #[arg(
85 long,
86 help = "Rewrite stored checksums to match the current migration files without \
87 executing any SQL (for already-applied edited migrations)"
88 )]
89 reconcile_only: bool,
90 #[arg(long, help = "Emit JSON instead of a text table")]
91 json: bool,
92 },
93 #[command(
94 about = "Record a migration as already applied without running its SQL (recovers partial \
95 state where schema is applied but tracking row is missing)",
96 name = "migrate-mark-applied"
97 )]
98 MigrateMarkApplied {
99 #[arg(long, help = "Extension ID owning the migration")]
100 extension: String,
101 #[arg(long, help = "Migration version to mark as applied")]
102 version: u32,
103 #[arg(long, help = "Emit JSON instead of a text summary")]
104 json: bool,
105 },
106 #[command(about = "Assign admin role to a user")]
107 AssignAdmin { user: String },
108 #[command(about = "Show database connection status")]
109 Status,
110 #[command(about = "Get row count for a table")]
111 Count { table_name: String },
112 #[command(about = "List all indexes")]
113 Indexes {
114 #[arg(long, help = "Filter by table name")]
115 table: Option<String>,
116 },
117 #[command(about = "Show database and table sizes")]
118 Size,
119 #[command(about = "Diff live schema against extension declarations")]
120 Doctor,
121}
122
123#[derive(Debug, Subcommand)]
124pub enum MigrationsCommands {
125 #[command(about = "Show migration status for all extensions", alias = "list")]
126 Status,
127 #[command(about = "Show migration history for an extension")]
128 History {
129 #[arg(help = "Extension ID")]
130 extension: String,
131 },
132}