Archived
1
0
Fork 0

refac: rename client mod

This commit is contained in:
Dmitriy Pleshevskiy 2021-06-07 23:57:32 +03:00
parent 6381c99727
commit 7f93215926
6 changed files with 18 additions and 20 deletions

View file

@ -1,10 +1,10 @@
use crate::app::App; use crate::app::App;
use crate::client::maybe_with_transaction; use crate::database;
use crate::opts::ApplyCommandOpt; use crate::opts::ApplyCommandOpt;
pub(crate) fn apply_sql(app: &App, cmd_opts: &ApplyCommandOpt) -> migra::StdResult<()> { pub(crate) fn apply_sql(app: &App, cmd_opts: &ApplyCommandOpt) -> migra::StdResult<()> {
let config = app.config()?; 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 let file_contents = cmd_opts
.file_paths .file_paths
@ -20,14 +20,14 @@ pub(crate) fn apply_sql(app: &App, cmd_opts: &ApplyCommandOpt) -> migra::StdResu
.map(std::fs::read_to_string) .map(std::fs::read_to_string)
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
maybe_with_transaction( database::maybe_with_transaction(
cmd_opts.transaction_opts.single_transaction, cmd_opts.transaction_opts.single_transaction,
&mut client, &mut client,
&mut |mut client| { &mut |mut client| {
file_contents file_contents
.iter() .iter()
.try_for_each(|content| { .try_for_each(|content| {
maybe_with_transaction( database::maybe_with_transaction(
!cmd_opts.transaction_opts.single_transaction, !cmd_opts.transaction_opts.single_transaction,
&mut client, &mut client,
&mut |client| client.apply_sql(content), &mut |client| client.apply_sql(content),

View file

@ -1,6 +1,5 @@
use crate::app::App; use crate::app::App;
use crate::client; use crate::database;
use crate::client::maybe_with_transaction;
use crate::opts::DowngradeCommandOpt; use crate::opts::DowngradeCommandOpt;
use std::cmp; use std::cmp;
@ -9,7 +8,7 @@ pub(crate) fn rollback_applied_migrations(
opts: &DowngradeCommandOpt, opts: &DowngradeCommandOpt,
) -> migra::StdResult<()> { ) -> migra::StdResult<()> {
let config = app.config()?; 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()?; client.create_migrations_table()?;
@ -25,7 +24,7 @@ pub(crate) fn rollback_applied_migrations(
dbg!(&rollback_migrations_number); dbg!(&rollback_migrations_number);
maybe_with_transaction( database::maybe_with_transaction(
opts.transaction_opts.single_transaction, opts.transaction_opts.single_transaction,
&mut client, &mut client,
&mut |mut client| { &mut |mut client| {
@ -34,7 +33,7 @@ pub(crate) fn rollback_applied_migrations(
.try_for_each(|applied_migration| { .try_for_each(|applied_migration| {
if all_migrations.contains_name(applied_migration.name()) { if all_migrations.contains_name(applied_migration.name()) {
println!("downgrade {}...", applied_migration.name()); println!("downgrade {}...", applied_migration.name());
maybe_with_transaction( database::maybe_with_transaction(
!opts.transaction_opts.single_transaction, !opts.transaction_opts.single_transaction,
&mut client, &mut client,
&mut |client| client.apply_downgrade_migration(&applied_migration), &mut |client| client.apply_downgrade_migration(&applied_migration),

View file

@ -1,5 +1,5 @@
use crate::app::App; use crate::app::App;
use crate::client; use crate::database;
use crate::error::Error; use crate::error::Error;
use migra::migration; use migra::migration;
@ -9,7 +9,7 @@ pub(crate) fn print_migration_lists(app: &App) -> migra::StdResult<()> {
let config = app.config()?; let config = app.config()?;
let applied_migrations = match config.database.connection_string() { let applied_migrations = match config.database.connection_string() {
Ok(ref database_connection_string) => { Ok(ref database_connection_string) => {
let mut client = client::create( let mut client = database::create_client(
&config.database.client(), &config.database.client(),
database_connection_string, database_connection_string,
&config.migrations.table_name(), &config.migrations.table_name(),

View file

@ -1,6 +1,5 @@
use crate::app::App; use crate::app::App;
use crate::client; use crate::database;
use crate::client::maybe_with_transaction;
use crate::opts::UpgradeCommandOpt; use crate::opts::UpgradeCommandOpt;
use migra::migration; use migra::migration;
@ -9,7 +8,7 @@ pub(crate) fn upgrade_pending_migrations(
opts: &UpgradeCommandOpt, opts: &UpgradeCommandOpt,
) -> migra::StdResult<()> { ) -> migra::StdResult<()> {
let config = app.config()?; 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()?; client.create_migrations_table()?;
@ -45,7 +44,7 @@ pub(crate) fn upgrade_pending_migrations(
.into() .into()
}; };
maybe_with_transaction( database::maybe_with_transaction(
opts.transaction_opts.single_transaction, opts.transaction_opts.single_transaction,
&mut client, &mut client,
&mut |mut client| { &mut |mut client| {
@ -53,7 +52,7 @@ pub(crate) fn upgrade_pending_migrations(
.iter() .iter()
.try_for_each(|migration| { .try_for_each(|migration| {
print_migration_info(migration); print_migration_info(migration);
maybe_with_transaction( database::maybe_with_transaction(
!opts.transaction_opts.single_transaction, !opts.transaction_opts.single_transaction,
&mut client, &mut client,
&mut |client| client.apply_upgrade_migration(migration), &mut |client| client.apply_upgrade_migration(migration),

View file

@ -8,7 +8,7 @@ use migra::clients::PostgresClient;
use migra::clients::SqliteClient; use migra::clients::SqliteClient;
use migra::clients::{AnyClient, OpenDatabaseConnection}; use migra::clients::{AnyClient, OpenDatabaseConnection};
pub fn create( pub fn create_client(
client_kind: &SupportedDatabaseClient, client_kind: &SupportedDatabaseClient,
connection_string: &str, connection_string: &str,
migrations_table_name: &str, migrations_table_name: &str,
@ -34,8 +34,8 @@ pub fn create(
Ok(client) Ok(client)
} }
pub fn create_from_config(config: &Config) -> migra::StdResult<AnyClient> { pub fn create_client_from_config(config: &Config) -> migra::StdResult<AnyClient> {
create( create_client(
&config.database.client(), &config.database.client(),
&config.database.connection_string()?, &config.database.connection_string()?,
&config.migrations.table_name(), &config.migrations.table_name(),

View file

@ -10,9 +10,9 @@ compile_error!(
); );
mod app; mod app;
mod client;
mod commands; mod commands;
mod config; mod config;
mod database;
mod error; mod error;
pub use error::Error; pub use error::Error;