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(
46 about = "Squash an extension's migrations 1..=N into a baseline at version 0 (dry-run by \
47 default)"
48 )]
49 MigrateSquash {
50 #[arg(long, help = "Extension ID whose migrations should be squashed")]
51 extension: String,
52 #[arg(
53 long,
54 help = "Squash migrations with version 1..=through into the baseline"
55 )]
56 through: u32,
57 #[arg(
58 long,
59 help = "Apply the squash (write baseline file + rewrite DB rows). Without this flag, \
60 the command is a dry-run."
61 )]
62 apply: bool,
63 },
64 #[command(about = "Show migration status and history")]
65 Migrations {
66 #[command(subcommand)]
67 cmd: MigrationsCommands,
68 },
69 #[command(
70 about = "Show pending migrations (dry-run / plan, no DB writes)",
71 name = "migrate-plan"
72 )]
73 MigratePlan {
74 #[arg(help = "Filter by extension ID (default: all extensions)")]
75 extension: Option<String>,
76 #[arg(long, help = "Emit JSON instead of a text table")]
77 json: bool,
78 },
79 #[command(
80 about = "Detailed introspectable migration status (applied, pending, drift)",
81 name = "migrate-status"
82 )]
83 MigrateStatus {
84 #[arg(help = "Filter by extension ID (default: all extensions)")]
85 extension: Option<String>,
86 #[arg(long, help = "Emit JSON instead of a text table")]
87 json: bool,
88 },
89 #[command(
90 about = "Repair migration checksum drift — re-applies edited migrations in place (no data \
91 loss)",
92 name = "migrate-repair"
93 )]
94 MigrateRepair {
95 #[arg(help = "Limit repair to a single extension (default: all extensions)")]
96 extension: Option<String>,
97 #[arg(
98 long,
99 help = "Apply the repair. Without this flag, the command is a dry-run that only lists \
100 drift."
101 )]
102 apply: bool,
103 #[arg(long, help = "Emit JSON instead of a text table")]
104 json: bool,
105 },
106 #[command(
107 about = "Record a migration as already applied without running its SQL (recovers partial \
108 state where schema is applied but tracking row is missing)",
109 name = "migrate-mark-applied"
110 )]
111 MigrateMarkApplied {
112 #[arg(long, help = "Extension ID owning the migration")]
113 extension: String,
114 #[arg(long, help = "Migration version to mark as applied")]
115 version: u32,
116 #[arg(long, help = "Emit JSON instead of a text summary")]
117 json: bool,
118 },
119 #[command(about = "Assign admin role to a user")]
120 AssignAdmin { user: String },
121 #[command(about = "Show database connection status")]
122 Status,
123 #[command(about = "Validate database schema against expected tables")]
124 Validate,
125 #[command(about = "Get row count for a table")]
126 Count { table_name: String },
127 #[command(about = "List all indexes")]
128 Indexes {
129 #[arg(long, help = "Filter by table name")]
130 table: Option<String>,
131 },
132 #[command(about = "Show database and table sizes")]
133 Size,
134 #[command(about = "Diff live schema against extension declarations")]
135 Doctor,
136}
137
138#[derive(Debug, Subcommand)]
139pub enum MigrationsCommands {
140 #[command(about = "Show migration status for all extensions", alias = "list")]
141 Status,
142 #[command(about = "Show migration history for an extension")]
143 History {
144 #[arg(help = "Extension ID")]
145 extension: String,
146 },
147}