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