Skip to content

Commit c8b9b6a

Browse files
authored
revert Transaction and AsyncTransaction function signatures update (#370)
1 parent 936af4c commit c8b9b6a

File tree

9 files changed

+36
-76
lines changed

9 files changed

+36
-76
lines changed

refinery_core/src/drivers/config.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ use std::convert::Infallible;
1818
impl Transaction for Config {
1919
type Error = Infallible;
2020

21-
fn execute<'a, T: Iterator<Item = &'a str>>(
22-
&mut self,
23-
_queries: T,
24-
) -> Result<usize, Self::Error> {
21+
fn execute(&mut self, _queries: &[&str]) -> Result<usize, Self::Error> {
2522
Ok(0)
2623
}
2724
}
@@ -36,10 +33,7 @@ impl Query<Vec<Migration>> for Config {
3633
impl AsyncTransaction for Config {
3734
type Error = Infallible;
3835

39-
async fn execute<'a, T: Iterator<Item = &'a str> + Send>(
40-
&mut self,
41-
_queries: T,
42-
) -> Result<usize, Self::Error> {
36+
async fn execute(&mut self, _queries: &[&str]) -> Result<usize, Self::Error> {
4337
Ok(0)
4438
}
4539
}

refinery_core/src/drivers/mysql.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ fn query_applied_migrations(
4343
impl Transaction for Conn {
4444
type Error = MError;
4545

46-
fn execute<'a, T: Iterator<Item = &'a str>>(
47-
&mut self,
48-
queries: T,
49-
) -> Result<usize, Self::Error> {
46+
fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
5047
let mut transaction = self.start_transaction(get_tx_opts())?;
5148
let mut count = 0;
52-
for query in queries {
49+
for query in queries.iter() {
5350
transaction.query_iter(query)?;
5451
count += 1;
5552
}
@@ -61,14 +58,11 @@ impl Transaction for Conn {
6158
impl Transaction for PooledConn {
6259
type Error = MError;
6360

64-
fn execute<'a, T: Iterator<Item = &'a str>>(
65-
&mut self,
66-
queries: T,
67-
) -> Result<usize, Self::Error> {
61+
fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
6862
let mut transaction = self.start_transaction(get_tx_opts())?;
6963
let mut count = 0;
7064

71-
for query in queries {
65+
for query in queries.iter() {
7266
transaction.query_iter(query)?;
7367
count += 1;
7468
}

refinery_core/src/drivers/mysql_async.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ async fn query_applied_migrations<'a>(
3939
impl AsyncTransaction for Pool {
4040
type Error = MError;
4141

42-
async fn execute<'a, T: Iterator<Item = &'a str> + Send>(
43-
&mut self,
44-
queries: T,
45-
) -> Result<usize, Self::Error> {
42+
async fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
4643
let mut conn = self.get_conn().await?;
4744
let mut options = TxOpts::new();
4845
options.with_isolation_level(Some(IsolationLevel::ReadCommitted));
4946

5047
let mut transaction = conn.start_transaction(options).await?;
5148
let mut count = 0;
5249
for query in queries {
53-
transaction.query_drop(query).await?;
50+
transaction.query_drop(*query).await?;
5451
count += 1;
5552
}
5653
transaction.commit().await?;

refinery_core/src/drivers/postgres.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ fn query_applied_migrations(
3333
impl Transaction for PgClient {
3434
type Error = PgError;
3535

36-
fn execute<'a, T: Iterator<Item = &'a str>>(
37-
&mut self,
38-
queries: T,
39-
) -> Result<usize, Self::Error> {
36+
fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
4037
let mut transaction = PgClient::transaction(self)?;
4138
let mut count = 0;
42-
for query in queries {
39+
for query in queries.iter() {
4340
PgTransaction::batch_execute(&mut transaction, query)?;
4441
count += 1;
4542
}

refinery_core/src/drivers/rusqlite.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@ fn query_applied_migrations(
3232

3333
impl Transaction for RqlConnection {
3434
type Error = RqlError;
35-
fn execute<'a, T: Iterator<Item = &'a str>>(
36-
&mut self,
37-
queries: T,
38-
) -> Result<usize, Self::Error> {
35+
fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
3936
let transaction = self.transaction()?;
4037
let mut count = 0;
41-
for query in queries {
38+
for query in queries.iter() {
4239
transaction.execute_batch(query)?;
4340
count += 1;
4441
}

refinery_core/src/drivers/tiberius.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ where
4646
{
4747
type Error = Error;
4848

49-
async fn execute<'a, T: Iterator<Item = &'a str> + Send>(
50-
&mut self,
51-
queries: T,
52-
) -> Result<usize, Self::Error> {
49+
async fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
5350
// Tiberius doesn't support transactions, see https://github.com/prisma/tiberius/issues/28
5451
self.simple_query("BEGIN TRAN T1;").await?;
5552
let mut count = 0;
5653
for query in queries {
5754
// Drop the returning `QueryStream<'a>` to avoid compiler complaning regarding lifetimes
58-
if let Err(err) = self.simple_query(query).await.map(drop) {
55+
if let Err(err) = self.simple_query(*query).await.map(drop) {
5956
if let Err(err) = self.simple_query("ROLLBACK TRAN T1").await {
6057
log::error!("could not ROLLBACK transaction, {}", err);
6158
}

refinery_core/src/drivers/tokio_postgres.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ async fn query_applied_migrations(
3535
impl AsyncTransaction for Client {
3636
type Error = PgError;
3737

38-
async fn execute<'a, T: Iterator<Item = &'a str> + Send>(
39-
&mut self,
40-
queries: T,
41-
) -> Result<usize, Self::Error> {
38+
async fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error> {
4239
let transaction = self.transaction().await?;
4340
let mut count = 0;
4441
for query in queries {

refinery_core/src/traits/async.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use std::string::ToString;
1212
pub trait AsyncTransaction {
1313
type Error: std::error::Error + Send + Sync + 'static;
1414

15-
async fn execute<'a, T: Iterator<Item = &'a str> + Send>(
16-
&mut self,
17-
queries: T,
18-
) -> Result<usize, Self::Error>;
15+
async fn execute(&mut self, query: &[&str]) -> Result<usize, Self::Error>;
1916
}
2017

2118
#[async_trait]
@@ -46,13 +43,10 @@ async fn migrate<T: AsyncTransaction>(
4643
migration.set_applied();
4744
let update_query = insert_migration_query(&migration, migration_table_name);
4845
transaction
49-
.execute(
50-
[
51-
migration.sql().as_ref().expect("sql must be Some!"),
52-
update_query.as_str(),
53-
]
54-
.into_iter(),
55-
)
46+
.execute(&[
47+
migration.sql().as_ref().expect("sql must be Some!"),
48+
&update_query,
49+
])
5650
.await
5751
.migration_err(
5852
&format!("error applying migration {}", migration),
@@ -111,10 +105,10 @@ async fn migrate_grouped<T: AsyncTransaction>(
111105
);
112106
}
113107

114-
let refs = grouped_migrations.iter().map(AsRef::as_ref);
108+
let refs: Vec<&str> = grouped_migrations.iter().map(AsRef::as_ref).collect();
115109

116110
transaction
117-
.execute(refs)
111+
.execute(refs.as_ref())
118112
.await
119113
.migration_err("error applying migrations", None)?;
120114

@@ -172,11 +166,9 @@ where
172166
target: Target,
173167
migration_table_name: &str,
174168
) -> Result<Report, Error> {
175-
self.execute(
176-
[Self::assert_migrations_table_query(migration_table_name).as_str()].into_iter(),
177-
)
178-
.await
179-
.migration_err("error asserting migrations table", None)?;
169+
self.execute(&[&Self::assert_migrations_table_query(migration_table_name)])
170+
.await
171+
.migration_err("error asserting migrations table", None)?;
180172

181173
let applied_migrations = self
182174
.get_applied_migrations(migration_table_name)

refinery_core/src/traits/sync.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ops::Deref;
2-
31
use crate::error::WrapMigrationError;
42
use crate::traits::{
53
insert_migration_query, verify_migrations, ASSERT_MIGRATIONS_TABLE_QUERY,
@@ -10,10 +8,7 @@ use crate::{Error, Migration, Report, Target};
108
pub trait Transaction {
119
type Error: std::error::Error + Send + Sync + 'static;
1210

13-
fn execute<'a, T: Iterator<Item = &'a str>>(
14-
&mut self,
15-
queries: T,
16-
) -> Result<usize, Self::Error>;
11+
fn execute(&mut self, queries: &[&str]) -> Result<usize, Self::Error>;
1712
}
1813

1914
pub trait Query<T>: Transaction {
@@ -25,7 +20,7 @@ pub fn migrate<T: Transaction>(
2520
migrations: Vec<Migration>,
2621
target: Target,
2722
migration_table_name: &str,
28-
grouped: bool,
23+
batched: bool,
2924
) -> Result<Report, Error> {
3025
let mut migration_batch = Vec::new();
3126
let mut applied_migrations = Vec::new();
@@ -54,7 +49,7 @@ pub fn migrate<T: Transaction>(
5449
migration_batch.push(insert_migration);
5550
}
5651

57-
match (target, grouped) {
52+
match (target, batched) {
5853
(Target::Fake | Target::FakeVersion(_), _) => {
5954
log::info!("not going to apply any migration as fake flag is enabled");
6055
}
@@ -73,14 +68,16 @@ pub fn migrate<T: Transaction>(
7368
}
7469
};
7570

76-
if grouped {
71+
let refs: Vec<&str> = migration_batch.iter().map(AsRef::as_ref).collect();
72+
73+
if batched {
7774
transaction
78-
.execute(migration_batch.iter().map(Deref::deref))
75+
.execute(refs.as_ref())
7976
.migration_err("error applying migrations", None)?;
8077
} else {
81-
for (i, update) in migration_batch.into_iter().enumerate() {
78+
for (i, update) in refs.iter().enumerate() {
8279
transaction
83-
.execute([update.as_str()].into_iter())
80+
.execute(&[update])
8481
.migration_err("error applying update", Some(&applied_migrations[0..i / 2]))?;
8582
}
8683
}
@@ -108,10 +105,8 @@ where
108105
fn assert_migrations_table(&mut self, migration_table_name: &str) -> Result<usize, Error> {
109106
// Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table,
110107
// thou on this case it's just to be consistent with the async trait `AsyncMigrate`
111-
self.execute(
112-
[Self::assert_migrations_table_query(migration_table_name).as_str()].into_iter(),
113-
)
114-
.migration_err("error asserting migrations table", None)
108+
self.execute(&[Self::assert_migrations_table_query(migration_table_name).as_str()])
109+
.migration_err("error asserting migrations table", None)
115110
}
116111

117112
fn get_last_applied_migration(

0 commit comments

Comments
 (0)