Same as [`run_cli`] where you provide the function to create the [`DbConn`]. This allows configuring the database connection as you see fit. E.g. you can change settings in [`ConnectOptions`] or you can load sqlite extensions.
(migrator: M, make_connection: F)
| 25 | /// E.g. you can change settings in [`ConnectOptions`] or you can load sqlite |
| 26 | /// extensions. |
| 27 | pub async fn run_cli_with_connection<M, F, Fut>(migrator: M, make_connection: F) |
| 28 | where |
| 29 | M: MigratorTrait, |
| 30 | F: FnOnce(ConnectOptions) -> Fut, |
| 31 | Fut: Future<Output = Result<DbConn, DbErr>>, |
| 32 | { |
| 33 | dotenv().ok(); |
| 34 | let cli = Cli::parse(); |
| 35 | |
| 36 | let url = cli |
| 37 | .database_url |
| 38 | .expect("Environment variable 'DATABASE_URL' not set"); |
| 39 | let schema = cli.database_schema.unwrap_or_else(|| "public".to_owned()); |
| 40 | |
| 41 | let connect_options = ConnectOptions::new(url) |
| 42 | .set_schema_search_path(schema) |
| 43 | .to_owned(); |
| 44 | |
| 45 | let db = make_connection(connect_options) |
| 46 | .await |
| 47 | .expect("Fail to acquire database connection"); |
| 48 | |
| 49 | run_migrate(migrator, &db, cli.command, cli.verbose) |
| 50 | .await |
| 51 | .unwrap_or_else(handle_error); |
| 52 | } |
| 53 | |
| 54 | pub async fn run_migrate<M>( |
| 55 | _: M, |
no test coverage detected