mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-19 08:41:24 +01:00
add 'db migrate' subcommand
This commit is contained in:
parent
a2ed21f1c2
commit
6446822bf2
3 changed files with 133 additions and 1 deletions
33
src/cli.rs
33
src/cli.rs
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue