add 'db migrate' subcommand

This commit is contained in:
Benjamin Lee 2024-09-13 14:44:51 -07:00
parent a2ed21f1c2
commit 6446822bf2
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
3 changed files with 133 additions and 1 deletions

View file

@ -9,6 +9,7 @@ use clap::{Parser, Subcommand};
use crate::error;
mod migrate_db;
mod serve;
/// Command line arguments
@ -26,6 +27,10 @@ pub(crate) struct Args {
pub(crate) enum Command {
/// Run the server.
Serve(ServeArgs),
/// Commands for interacting with the database.
#[clap(subcommand)]
Db(DbCommand),
}
/// Wrapper for the `--config` arg.
@ -57,10 +62,38 @@ pub(crate) struct ServeArgs {
pub(crate) config: ConfigArg,
}
#[derive(Subcommand)]
pub(crate) enum DbCommand {
/// Migrate database from one server implementation to another.
///
/// This command is not protected against symlink-swapping attacks. Do not
/// use it when any subdirectories or parents of the `--in`, `--out`, or
/// `--inplace` directories may be written by an untrusted user during
/// execution.
Migrate(MigrateDbArgs),
}
#[derive(clap::Args)]
pub(crate) struct MigrateDbArgs {
#[clap(flatten)]
config: ConfigArg,
/// Path to read database from.
#[clap(long = "in", short)]
pub(crate) in_path: PathBuf,
/// Path to write migrated database to.
#[clap(long = "out", short)]
pub(crate) out_path: PathBuf,
}
impl Args {
pub(crate) async fn run(self) -> Result<(), error::Main> {
match self.command {
Command::Serve(args) => serve::run(args).await?,
Command::Db(DbCommand::Migrate(args)) => {
migrate_db::run(args).await?;
}
}
Ok(())
}