1mod apply;
2mod config;
3mod drop;
4mod generate;
5mod reset;
6mod snapshot;
7mod snapshot_file;
8
9pub use apply::ApplyCommand;
10pub use config::{MigrationConfig, MigrationPrefixStyle};
11pub use drop::DropCommand;
12pub use generate::GenerateCommand;
13pub use reset::ResetCommand;
14pub use snapshot::SnapshotCommand;
15pub use snapshot_file::SnapshotFile;
16
17use crate::Config;
18use anyhow::Result;
19use clap::Parser;
20use toasty::Db;
21
22#[derive(Parser, Debug)]
27pub struct MigrationCommand {
28 #[command(subcommand)]
29 subcommand: MigrationSubcommand,
30}
31
32#[derive(Parser, Debug)]
33enum MigrationSubcommand {
34 Apply(ApplyCommand),
36
37 Generate(GenerateCommand),
39
40 Snapshot(SnapshotCommand),
42
43 Drop(DropCommand),
45
46 Reset(ResetCommand),
48}
49
50impl MigrationCommand {
51 pub(crate) async fn run(self, db: &Db, config: &Config) -> Result<()> {
52 self.subcommand.run(db, config).await
53 }
54}
55
56impl MigrationSubcommand {
57 async fn run(self, db: &Db, config: &Config) -> Result<()> {
58 match self {
59 Self::Apply(cmd) => cmd.run(db, config).await,
60 Self::Generate(cmd) => cmd.run(db, config),
61 Self::Snapshot(cmd) => cmd.run(db, config),
62 Self::Drop(cmd) => cmd.run(db, config),
63 Self::Reset(cmd) => cmd.run(db, config).await,
64 }
65 }
66}