refac: rename method
... to open database connection
This commit is contained in:
parent
8f834264d8
commit
1d8993d1f0
3 changed files with 8 additions and 9 deletions
|
@ -7,7 +7,7 @@ const EM_DASH: char = '—';
|
|||
pub(crate) fn print_migration_lists(config: Config) -> StdResult<()> {
|
||||
let applied_migrations = match config.database_connection_string() {
|
||||
Ok(ref database_connection_string) => {
|
||||
let mut connection = DatabaseConnection::connect(database_connection_string)?;
|
||||
let mut connection = DatabaseConnection::open(database_connection_string)?;
|
||||
let applied_migrations = connection.applied_migration_names()?;
|
||||
|
||||
println!("Applied migrations:");
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use crate::database;
|
||||
use crate::database::DatabaseConnection;
|
||||
use crate::migration::Migration;
|
||||
use crate::Config;
|
||||
use crate::StdResult;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
pub(crate) fn upgrade_pending_migrations(config: Config) -> StdResult<()> {
|
||||
let database_connection_string = &config.database_connection_string()?;
|
||||
let mut client = database::connect(database_connection_string)?;
|
||||
|
||||
let applied_migration_names = database::applied_migration_names(&mut client)?;
|
||||
let mut connection = DatabaseConnection::try_from(&config)?;
|
||||
|
||||
let applied_migration_names = connection.applied_migration_names()?;
|
||||
let migrations = config.migrations()?;
|
||||
|
||||
if is_up_to_date_migrations(&migrations, &applied_migration_names) {
|
||||
|
@ -18,7 +17,7 @@ pub(crate) fn upgrade_pending_migrations(config: Config) -> StdResult<()> {
|
|||
|
||||
for migration in pending_migrations.iter() {
|
||||
println!("upgrade {}...", migration.name());
|
||||
migration.upgrade(&mut client)?;
|
||||
migration.upgrade(&mut connection)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,12 @@ impl TryFrom<&Config> for DatabaseConnection {
|
|||
type Error = Box<dyn std::error::Error>;
|
||||
|
||||
fn try_from(config: &Config) -> Result<Self, Self::Error> {
|
||||
DatabaseConnection::connect(&config.database_connection_string()?)
|
||||
DatabaseConnection::open(&config.database_connection_string()?)
|
||||
}
|
||||
}
|
||||
|
||||
impl DatabaseConnection {
|
||||
pub fn connect(connection_string: &str) -> StdResult<DatabaseConnection> {
|
||||
pub fn open(connection_string: &str) -> StdResult<DatabaseConnection> {
|
||||
let client = Client::connect(connection_string, NoTls)?;
|
||||
Ok(DatabaseConnection { client })
|
||||
}
|
||||
|
|
Reference in a new issue