Skip to main content

systemprompt_cli/commands/infrastructure/db/
commands.rs

1use 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(
108        about = "Record a migration as already applied without running its SQL (recovers partial \
109                 state where schema is applied but tracking row is missing)",
110        name = "migrate-mark-applied"
111    )]
112    MigrateMarkApplied {
113        #[arg(long, help = "Extension ID owning the migration")]
114        extension: String,
115        #[arg(long, help = "Migration version to mark as applied")]
116        version: u32,
117        #[arg(long, help = "Emit JSON instead of a text summary")]
118        json: bool,
119    },
120    #[command(about = "Assign admin role to a user")]
121    AssignAdmin { user: String },
122    #[command(about = "Show database connection status")]
123    Status,
124    #[command(about = "Validate database schema against expected tables")]
125    Validate,
126    #[command(about = "Get row count for a table")]
127    Count { table_name: String },
128    #[command(about = "List all indexes")]
129    Indexes {
130        #[arg(long, help = "Filter by table name")]
131        table: Option<String>,
132    },
133    #[command(about = "Show database and table sizes")]
134    Size,
135    #[command(about = "Diff live schema against extension declarations")]
136    Doctor,
137}
138
139#[derive(Debug, Subcommand)]
140pub enum MigrationsCommands {
141    #[command(about = "Show migration status for all extensions", alias = "list")]
142    Status,
143    #[command(about = "Show migration history for an extension")]
144    History {
145        #[arg(help = "Extension ID")]
146        extension: String,
147    },
148}