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