mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
feat: adds the setup command to the sqlx-cli
The reset command is the equivalent of `sqlx db create`, and `sqlx migrate run`.
This commit is contained in:
parent
916f1fccf2
commit
2e1658e08b
3 changed files with 15 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
|||
use crate::migrate;
|
||||
use console::style;
|
||||
use dialoguer::Confirm;
|
||||
use sqlx::any::Any;
|
||||
|
@ -30,3 +31,13 @@ pub async fn drop(uri: &str, confirm: bool) -> anyhow::Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn reset(uri: &str, confirm: bool) -> anyhow::Result<()> {
|
||||
drop(uri, confirm).await?;
|
||||
setup(uri).await
|
||||
}
|
||||
|
||||
pub async fn setup(uri: &str) -> anyhow::Result<()> {
|
||||
create(uri).await?;
|
||||
migrate::run(uri).await
|
||||
}
|
||||
|
|
|
@ -39,11 +39,8 @@ hint: This command only works in the manifest directory of a Cargo package."#
|
|||
Command::Database(database) => match database.command {
|
||||
DatabaseCommand::Create => database::create(&database_url).await?,
|
||||
DatabaseCommand::Drop { yes } => database::drop(&database_url, !yes).await?,
|
||||
DatabaseCommand::Reset { yes } => {
|
||||
database::drop(&database_url, yes).await?;
|
||||
database::create(&database_url).await?;
|
||||
migrate::run(&database_url).await?;
|
||||
}
|
||||
DatabaseCommand::Reset { yes } => database::reset(&database_url, yes).await?,
|
||||
DatabaseCommand::Setup => database::setup(&database_url).await?,
|
||||
},
|
||||
|
||||
Command::Prepare { check: false, args } => prepare::run(&database_url, args)?,
|
||||
|
|
|
@ -64,6 +64,8 @@ pub enum DatabaseCommand {
|
|||
#[clap(short)]
|
||||
yes: bool,
|
||||
},
|
||||
/// Creates the database specified in your DATABASE_URL and runs any pending migrations.
|
||||
Setup,
|
||||
}
|
||||
|
||||
/// Group of commands for creating and running migrations.
|
||||
|
|
Loading…
Reference in a new issue