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)]
29pub struct MigrationCommand {
30 #[command(subcommand)]
31 subcommand: MigrationSubcommand,
32}
33
34#[derive(Parser, Debug)]
35enum MigrationSubcommand {
36 Apply(ApplyCommand),
38
39 Generate(GenerateCommand),
41
42 Snapshot(SnapshotCommand),
44
45 Drop(DropCommand),
47
48 Reset(ResetCommand),
50}
51
52impl MigrationCommand {
53 pub(crate) async fn run(self, db: &Db, config: &Config) -> Result<()> {
54 self.subcommand.run(db, config).await
55 }
56}
57
58impl MigrationSubcommand {
59 async fn run(self, db: &Db, config: &Config) -> Result<()> {
60 match self {
61 Self::Apply(cmd) => cmd.run(db, config).await,
62 Self::Generate(cmd) => cmd.run(db, config),
63 Self::Snapshot(cmd) => cmd.run(db, config),
64 Self::Drop(cmd) => cmd.run(db, config),
65 Self::Reset(cmd) => cmd.run(db, config).await,
66 }
67 }
68}