From 7f9321592680cb02b1452b7eb77916fb9d763927 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Mon, 7 Jun 2021 23:57:32 +0300 Subject: [PATCH] refac: rename client mod --- migra_cli/src/commands/apply.rs | 8 ++++---- migra_cli/src/commands/downgrade.rs | 9 ++++----- migra_cli/src/commands/list.rs | 4 ++-- migra_cli/src/commands/upgrade.rs | 9 ++++----- migra_cli/src/{client.rs => database.rs} | 6 +++--- migra_cli/src/main.rs | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) rename migra_cli/src/{client.rs => database.rs} (94%) diff --git a/migra_cli/src/commands/apply.rs b/migra_cli/src/commands/apply.rs index 70ea777..e6ec4c9 100644 --- a/migra_cli/src/commands/apply.rs +++ b/migra_cli/src/commands/apply.rs @@ -1,10 +1,10 @@ use crate::app::App; -use crate::client::maybe_with_transaction; +use crate::database; use crate::opts::ApplyCommandOpt; pub(crate) fn apply_sql(app: &App, cmd_opts: &ApplyCommandOpt) -> migra::StdResult<()> { let config = app.config()?; - let mut client = crate::client::create_from_config(&config)?; + let mut client = database::create_client_from_config(&config)?; let file_contents = cmd_opts .file_paths @@ -20,14 +20,14 @@ pub(crate) fn apply_sql(app: &App, cmd_opts: &ApplyCommandOpt) -> migra::StdResu .map(std::fs::read_to_string) .collect::, _>>()?; - maybe_with_transaction( + database::maybe_with_transaction( cmd_opts.transaction_opts.single_transaction, &mut client, &mut |mut client| { file_contents .iter() .try_for_each(|content| { - maybe_with_transaction( + database::maybe_with_transaction( !cmd_opts.transaction_opts.single_transaction, &mut client, &mut |client| client.apply_sql(content), diff --git a/migra_cli/src/commands/downgrade.rs b/migra_cli/src/commands/downgrade.rs index b85c284..5630dfc 100644 --- a/migra_cli/src/commands/downgrade.rs +++ b/migra_cli/src/commands/downgrade.rs @@ -1,6 +1,5 @@ use crate::app::App; -use crate::client; -use crate::client::maybe_with_transaction; +use crate::database; use crate::opts::DowngradeCommandOpt; use std::cmp; @@ -9,7 +8,7 @@ pub(crate) fn rollback_applied_migrations( opts: &DowngradeCommandOpt, ) -> migra::StdResult<()> { let config = app.config()?; - let mut client = client::create_from_config(&config)?; + let mut client = database::create_client_from_config(&config)?; client.create_migrations_table()?; @@ -25,7 +24,7 @@ pub(crate) fn rollback_applied_migrations( dbg!(&rollback_migrations_number); - maybe_with_transaction( + database::maybe_with_transaction( opts.transaction_opts.single_transaction, &mut client, &mut |mut client| { @@ -34,7 +33,7 @@ pub(crate) fn rollback_applied_migrations( .try_for_each(|applied_migration| { if all_migrations.contains_name(applied_migration.name()) { println!("downgrade {}...", applied_migration.name()); - maybe_with_transaction( + database::maybe_with_transaction( !opts.transaction_opts.single_transaction, &mut client, &mut |client| client.apply_downgrade_migration(&applied_migration), diff --git a/migra_cli/src/commands/list.rs b/migra_cli/src/commands/list.rs index e7af72a..8858b3b 100644 --- a/migra_cli/src/commands/list.rs +++ b/migra_cli/src/commands/list.rs @@ -1,5 +1,5 @@ use crate::app::App; -use crate::client; +use crate::database; use crate::error::Error; use migra::migration; @@ -9,7 +9,7 @@ pub(crate) fn print_migration_lists(app: &App) -> migra::StdResult<()> { let config = app.config()?; let applied_migrations = match config.database.connection_string() { Ok(ref database_connection_string) => { - let mut client = client::create( + let mut client = database::create_client( &config.database.client(), database_connection_string, &config.migrations.table_name(), diff --git a/migra_cli/src/commands/upgrade.rs b/migra_cli/src/commands/upgrade.rs index ab52a6d..a6c01e4 100644 --- a/migra_cli/src/commands/upgrade.rs +++ b/migra_cli/src/commands/upgrade.rs @@ -1,6 +1,5 @@ use crate::app::App; -use crate::client; -use crate::client::maybe_with_transaction; +use crate::database; use crate::opts::UpgradeCommandOpt; use migra::migration; @@ -9,7 +8,7 @@ pub(crate) fn upgrade_pending_migrations( opts: &UpgradeCommandOpt, ) -> migra::StdResult<()> { let config = app.config()?; - let mut client = client::create_from_config(&config)?; + let mut client = database::create_client_from_config(&config)?; client.create_migrations_table()?; @@ -45,7 +44,7 @@ pub(crate) fn upgrade_pending_migrations( .into() }; - maybe_with_transaction( + database::maybe_with_transaction( opts.transaction_opts.single_transaction, &mut client, &mut |mut client| { @@ -53,7 +52,7 @@ pub(crate) fn upgrade_pending_migrations( .iter() .try_for_each(|migration| { print_migration_info(migration); - maybe_with_transaction( + database::maybe_with_transaction( !opts.transaction_opts.single_transaction, &mut client, &mut |client| client.apply_upgrade_migration(migration), diff --git a/migra_cli/src/client.rs b/migra_cli/src/database.rs similarity index 94% rename from migra_cli/src/client.rs rename to migra_cli/src/database.rs index cf0a272..c0bd188 100644 --- a/migra_cli/src/client.rs +++ b/migra_cli/src/database.rs @@ -8,7 +8,7 @@ use migra::clients::PostgresClient; use migra::clients::SqliteClient; use migra::clients::{AnyClient, OpenDatabaseConnection}; -pub fn create( +pub fn create_client( client_kind: &SupportedDatabaseClient, connection_string: &str, migrations_table_name: &str, @@ -34,8 +34,8 @@ pub fn create( Ok(client) } -pub fn create_from_config(config: &Config) -> migra::StdResult { - create( +pub fn create_client_from_config(config: &Config) -> migra::StdResult { + create_client( &config.database.client(), &config.database.connection_string()?, &config.migrations.table_name(), diff --git a/migra_cli/src/main.rs b/migra_cli/src/main.rs index 99f9d71..804d779 100644 --- a/migra_cli/src/main.rs +++ b/migra_cli/src/main.rs @@ -10,9 +10,9 @@ compile_error!( ); mod app; -mod client; mod commands; mod config; +mod database; mod error; pub use error::Error;