refac: rename client mod
This commit is contained in:
parent
6381c99727
commit
7f93215926
6 changed files with 18 additions and 20 deletions
|
@ -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::<Result<Vec<_>, _>>()?;
|
||||
|
||||
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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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<AnyClient> {
|
||||
create(
|
||||
pub fn create_client_from_config(config: &Config) -> migra::StdResult<AnyClient> {
|
||||
create_client(
|
||||
&config.database.client(),
|
||||
&config.database.connection_string()?,
|
||||
&config.migrations.table_name(),
|
|
@ -10,9 +10,9 @@ compile_error!(
|
|||
);
|
||||
|
||||
mod app;
|
||||
mod client;
|
||||
mod commands;
|
||||
mod config;
|
||||
mod database;
|
||||
mod error;
|
||||
pub use error::Error;
|
||||
|
||||
|
|
Reference in a new issue