Skip to content

Commit 1ff6a8a

Browse files
committed
feat: teach sqlx-cli about migrate.migrations-dir
1 parent 367f2cc commit 1ff6a8a

File tree

9 files changed

+162
-90
lines changed

9 files changed

+162
-90
lines changed

Cargo.lock

Lines changed: 56 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlx-cli/src/database.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::migrate;
2-
use crate::opt::ConnectOpts;
1+
use crate::{migrate, Config};
2+
use crate::opt::{ConnectOpts, MigrationSourceOpt};
33
use console::style;
44
use promptly::{prompt, ReadlineError};
55
use sqlx::any::Any;
@@ -44,18 +44,19 @@ pub async fn drop(connect_opts: &ConnectOpts, confirm: bool, force: bool) -> any
4444
}
4545

4646
pub async fn reset(
47-
migration_source: &str,
47+
config: &Config,
48+
migration_source: &MigrationSourceOpt,
4849
connect_opts: &ConnectOpts,
4950
confirm: bool,
5051
force: bool,
5152
) -> anyhow::Result<()> {
5253
drop(connect_opts, confirm, force).await?;
53-
setup(migration_source, connect_opts).await
54+
setup(config, migration_source, connect_opts).await
5455
}
5556

56-
pub async fn setup(migration_source: &str, connect_opts: &ConnectOpts) -> anyhow::Result<()> {
57+
pub async fn setup(config: &Config, migration_source: &MigrationSourceOpt, connect_opts: &ConnectOpts) -> anyhow::Result<()> {
5758
create(connect_opts).await?;
58-
migrate::run(migration_source, connect_opts, false, false, None).await
59+
migrate::run(config, migration_source, connect_opts, false, false, None).await
5960
}
6061

6162
fn ask_to_continue_drop(db_url: &str) -> bool {

sqlx-cli/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub async fn run(opt: Opt) -> Result<()> {
3939
connect_opts.populate_db_url(config)?;
4040

4141
migrate::run(
42+
config,
4243
&source,
4344
&connect_opts,
4445
dry_run,
@@ -57,6 +58,7 @@ pub async fn run(opt: Opt) -> Result<()> {
5758
connect_opts.populate_db_url(config)?;
5859

5960
migrate::revert(
61+
config,
6062
&source,
6163
&connect_opts,
6264
dry_run,
@@ -71,9 +73,9 @@ pub async fn run(opt: Opt) -> Result<()> {
7173
} => {
7274
connect_opts.populate_db_url(config)?;
7375

74-
migrate::info(&source, &connect_opts).await?
76+
migrate::info(config, &source, &connect_opts).await?
7577
},
76-
MigrateCommand::BuildScript { source, force } => migrate::build_script(&source, force)?,
78+
MigrateCommand::BuildScript { source, force } => migrate::build_script(config, &source, force)?,
7779
},
7880

7981
Command::Database(database) => match database.command {
@@ -96,14 +98,14 @@ pub async fn run(opt: Opt) -> Result<()> {
9698
force,
9799
} => {
98100
connect_opts.populate_db_url(config)?;
99-
database::reset(&source, &connect_opts, !confirmation.yes, force).await?
101+
database::reset(config, &source, &connect_opts, !confirmation.yes, force).await?
100102
},
101103
DatabaseCommand::Setup {
102104
source,
103105
mut connect_opts,
104106
} => {
105107
connect_opts.populate_db_url(config)?;
106-
database::setup(&source, &connect_opts).await?
108+
database::setup(config, &source, &connect_opts).await?
107109
},
108110
},
109111

0 commit comments

Comments
 (0)