mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-30 21:31:22 +00:00
- adds a -r flag whihc will create a reversible migration - add revert subcommand, which reverts the last migration - add --dry-run flag to migration run command, which list the migrations that will be applied - updates add migration to check if all migration are of same type, i.e cannot mix and match reversible and simple migrations
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use crate::migrate;
|
|
use console::style;
|
|
use dialoguer::Confirm;
|
|
use sqlx::any::Any;
|
|
use sqlx::migrate::MigrateDatabase;
|
|
|
|
pub async fn create(uri: &str) -> anyhow::Result<()> {
|
|
if !Any::database_exists(uri).await? {
|
|
Any::create_database(uri).await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn drop(uri: &str, confirm: bool) -> anyhow::Result<()> {
|
|
if confirm
|
|
&& !Confirm::new()
|
|
.with_prompt(format!(
|
|
"\nAre you sure you want to drop the database at {}?",
|
|
style(uri).cyan()
|
|
))
|
|
.wait_for_newline(true)
|
|
.default(false)
|
|
.interact()?
|
|
{
|
|
return Ok(());
|
|
}
|
|
|
|
if Any::database_exists(uri).await? {
|
|
Any::drop_database(uri).await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn reset(migration_source: &str, uri: &str, confirm: bool) -> anyhow::Result<()> {
|
|
drop(uri, confirm).await?;
|
|
setup(migration_source, uri).await
|
|
}
|
|
|
|
pub async fn setup(migration_source: &str, uri: &str) -> anyhow::Result<()> {
|
|
create(uri).await?;
|
|
migrate::run(migration_source, uri, false).await
|
|
}
|