From 1b16aff6e59036c9abde67e3f9d53d3274107bf2 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 14 Feb 2021 12:10:12 +0300 Subject: [PATCH] refac: rename database connection to postgres --- migra-cli/src/commands/apply.rs | 4 ++-- migra-cli/src/commands/downgrade.rs | 4 ++-- migra-cli/src/commands/list.rs | 4 ++-- migra-cli/src/commands/upgrade.rs | 4 ++-- migra-cli/src/database.rs | 14 +++++++------- migra-cli/src/migration.rs | 10 +++++----- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/migra-cli/src/commands/apply.rs b/migra-cli/src/commands/apply.rs index e2b5ee7..b64f52c 100644 --- a/migra-cli/src/commands/apply.rs +++ b/migra-cli/src/commands/apply.rs @@ -1,12 +1,12 @@ use crate::config::Config; -use crate::database::DatabaseConnection; +use crate::database::PostgresConnection; use crate::opts::ApplyCommandOpt; use crate::path::PathBuilder; use crate::StdResult; use std::convert::TryFrom; pub(crate) fn apply_sql(config: Config, opts: ApplyCommandOpt) -> StdResult<()> { - let mut connection = DatabaseConnection::try_from(&config)?; + let mut connection = PostgresConnection::try_from(&config)?; let file_path = PathBuilder::from(config.directory_path()) .append(opts.file_name) diff --git a/migra-cli/src/commands/downgrade.rs b/migra-cli/src/commands/downgrade.rs index c891252..d50377e 100644 --- a/migra-cli/src/commands/downgrade.rs +++ b/migra-cli/src/commands/downgrade.rs @@ -1,11 +1,11 @@ use crate::config::Config; -use crate::database::DatabaseConnection; +use crate::database::PostgresConnection; use crate::migration::Downgrade; use crate::StdResult; use std::convert::TryFrom; pub(crate) fn downgrade_applied_migrations(config: Config) -> StdResult<()> { - let mut connection = DatabaseConnection::try_from(&config)?; + let mut connection = PostgresConnection::try_from(&config)?; let applied_migrations = connection.applied_migration_names()?; let migrations = config.migrations()?; diff --git a/migra-cli/src/commands/list.rs b/migra-cli/src/commands/list.rs index a5f6473..ae3fdcf 100644 --- a/migra-cli/src/commands/list.rs +++ b/migra-cli/src/commands/list.rs @@ -1,5 +1,5 @@ use crate::config::Config; -use crate::database::DatabaseConnection; +use crate::database::PostgresConnection; use crate::error::{ErrorKind, StdResult}; const EM_DASH: char = '—'; @@ -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::open(database_connection_string)?; + let mut connection = PostgresConnection::open(database_connection_string)?; let applied_migrations = connection.applied_migration_names()?; println!("Applied migrations:"); diff --git a/migra-cli/src/commands/upgrade.rs b/migra-cli/src/commands/upgrade.rs index 4b9c49d..17fe2d8 100644 --- a/migra-cli/src/commands/upgrade.rs +++ b/migra-cli/src/commands/upgrade.rs @@ -1,11 +1,11 @@ -use crate::database::DatabaseConnection; +use crate::database::PostgresConnection; use crate::migration::{Migration, Upgrade}; use crate::Config; use crate::StdResult; use std::convert::TryFrom; pub(crate) fn upgrade_pending_migrations(config: Config) -> StdResult<()> { - let mut connection = DatabaseConnection::try_from(&config)?; + let mut connection = PostgresConnection::try_from(&config)?; let applied_migration_names = connection.applied_migration_names()?; let migrations = config.migrations()?; diff --git a/migra-cli/src/database.rs b/migra-cli/src/database.rs index 7c98e16..e66332a 100644 --- a/migra-cli/src/database.rs +++ b/migra-cli/src/database.rs @@ -3,22 +3,22 @@ use crate::StdResult; use postgres::{Client, Error, NoTls}; use std::convert::TryFrom; -pub struct DatabaseConnection { +pub struct PostgresConnection { client: Client, } -impl TryFrom<&Config> for DatabaseConnection { +impl TryFrom<&Config> for PostgresConnection { type Error = Box; fn try_from(config: &Config) -> Result { - DatabaseConnection::open(&config.database_connection_string()?) + PostgresConnection::open(&config.database_connection_string()?) } } -impl DatabaseConnection { - pub fn open(connection_string: &str) -> StdResult { +impl PostgresConnection { + pub fn open(connection_string: &str) -> StdResult { let client = Client::connect(connection_string, NoTls)?; - Ok(DatabaseConnection { client }) + Ok(PostgresConnection { client }) } } @@ -27,7 +27,7 @@ pub fn is_migrations_table_not_found(e: &Error) -> bool { .contains(r#"relation "migrations" does not exist"#) } -impl DatabaseConnection { +impl PostgresConnection { pub fn apply_sql(&mut self, sql_content: &str) -> Result<(), Error> { self.client.batch_execute(sql_content) } diff --git a/migra-cli/src/migration.rs b/migra-cli/src/migration.rs index 4da540b..ff53640 100644 --- a/migra-cli/src/migration.rs +++ b/migra-cli/src/migration.rs @@ -1,15 +1,15 @@ -use crate::database::DatabaseConnection; +use crate::database::PostgresConnection; use crate::path::PathBuilder; use crate::StdResult; use std::fs; use std::path::PathBuf; pub trait Upgrade { - fn upgrade(&self, connection: &mut DatabaseConnection) -> StdResult<()>; + fn upgrade(&self, connection: &mut PostgresConnection) -> StdResult<()>; } pub trait Downgrade { - fn downgrade(&self, connection: &mut DatabaseConnection) -> StdResult<()>; + fn downgrade(&self, connection: &mut PostgresConnection) -> StdResult<()>; } #[derive(Debug)] @@ -49,7 +49,7 @@ impl Migration { } impl Upgrade for Migration { - fn upgrade(&self, connection: &mut DatabaseConnection) -> StdResult<()> { + fn upgrade(&self, connection: &mut PostgresConnection) -> StdResult<()> { let content = fs::read_to_string(&self.upgrade_sql)?; connection.create_migrations_table()?; @@ -61,7 +61,7 @@ impl Upgrade for Migration { } impl Downgrade for Migration { - fn downgrade(&self, connection: &mut DatabaseConnection) -> StdResult<()> { + fn downgrade(&self, connection: &mut PostgresConnection) -> StdResult<()> { let content = fs::read_to_string(&self.downgrade_sql)?; connection.apply_sql(&content)?;