Skip to content

Commit 10fdca6

Browse files
authored
Merge branch 'main' into use_tls
2 parents d0bd62e + cbdece5 commit 10fdca6

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,12 @@ jobs:
174174
strategy:
175175
matrix:
176176
rust: ${{ fromJson(needs.set-rust-versions.outputs.versions) }}
177-
services:
178-
mssql:
179-
image: mcr.microsoft.com/mssql/server:2017-latest
180-
ports:
181-
- 1433:1433
182-
env:
183-
ACCEPT_EULA: yes
184-
SA_PASSWORD: Passw0rd
185177
steps:
186178
- uses: actions/checkout@v2
179+
- uses: potatoqualitee/[email protected]
180+
with:
181+
install: sqlengine, sqlpackage
182+
sa-password: Passw0rd
187183
- uses: actions-rs/toolchain@v1
188184
with:
189185
toolchain: ${{ matrix.rust }}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ let client = conn.deref_mut().deref_mut();
7474
let report = embedded::migrations::runner().run_async(client).await?;
7575
```
7676

77+
### Example: bb8
78+
79+
```rust
80+
let mut client = pool.dedicated_connection().await?;
81+
let report = embedded::migrations::runner().run_async(&mut client).await?;
82+
```
83+
7784
### Non-contiguous VS Contiguous migrations
7885

7986
Depending on how your project/team has been structured will define whether you want to use contiguous (adjacent) migrations `V{1}__{2}.[sql|rs]` or non-contiguous (not adjacent) migrations `U{1}__{2}.[sql|rs]`.

refinery_core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ url = "2.0"
2929
walkdir = "2.3.1"
3030

3131
# allow multiple versions of the same dependency if API is similar
32-
rusqlite = { version = ">= 0.23, <= 0.32", optional = true }
32+
rusqlite = { version = ">= 0.23, <= 0.33", optional = true }
3333
postgres = { version = ">=0.17, <= 0.19", optional = true }
3434
native-tls = { version = "0.2", optional = true }
3535
postgres-native-tls = { version = "0.5", optional = true}
3636
tokio-postgres = { version = ">= 0.5, <= 0.7", optional = true }
3737
mysql = { version = ">= 21.0.0, <= 25", optional = true, default-features = false, features = ["minimal"] }
38-
mysql_async = { version = ">= 0.28, <= 0.34", optional = true, default-features = false, features = ["minimal"] }
38+
mysql_async = { version = ">= 0.28, <= 0.35", optional = true, default-features = false, features = ["minimal"] }
3939
tiberius = { version = ">= 0.7, <= 0.12", optional = true, default-features = false }
4040
tokio = { version = "1.0", optional = true }
4141
futures = { version = "0.3.16", optional = true, features = ["async-await"] }

refinery_core/src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct Report {
204204

205205
impl Report {
206206
/// Instantiate a new Report
207-
pub(crate) fn new(applied_migrations: Vec<Migration>) -> Report {
207+
pub fn new(applied_migrations: Vec<Migration>) -> Report {
208208
Report { applied_migrations }
209209
}
210210

refinery_core/src/traits/async.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,20 @@ where
132132
ASSERT_MIGRATIONS_TABLE_QUERY.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
133133
}
134134

135+
fn get_last_applied_migration_query(migration_table_name: &str) -> String {
136+
GET_LAST_APPLIED_MIGRATION_QUERY.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
137+
}
138+
139+
fn get_applied_migrations_query(migration_table_name: &str) -> String {
140+
GET_APPLIED_MIGRATIONS_QUERY.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
141+
}
142+
135143
async fn get_last_applied_migration(
136144
&mut self,
137145
migration_table_name: &str,
138146
) -> Result<Option<Migration>, Error> {
139147
let mut migrations = self
140-
.query(
141-
&GET_LAST_APPLIED_MIGRATION_QUERY
142-
.replace("%MIGRATION_TABLE_NAME%", migration_table_name),
143-
)
148+
.query(Self::get_last_applied_migration_query(migration_table_name).as_str())
144149
.await
145150
.migration_err("error getting last applied migration", None)?;
146151

@@ -152,10 +157,7 @@ where
152157
migration_table_name: &str,
153158
) -> Result<Vec<Migration>, Error> {
154159
let migrations = self
155-
.query(
156-
&GET_APPLIED_MIGRATIONS_QUERY
157-
.replace("%MIGRATION_TABLE_NAME%", migration_table_name),
158-
)
160+
.query(Self::get_applied_migrations_query(migration_table_name).as_str())
159161
.await
160162
.migration_err("error getting applied migrations", None)?;
161163

@@ -178,10 +180,7 @@ where
178180
.migration_err("error asserting migrations table", None)?;
179181

180182
let applied_migrations = self
181-
.query(
182-
&GET_APPLIED_MIGRATIONS_QUERY
183-
.replace("%MIGRATION_TABLE_NAME%", migration_table_name),
184-
)
183+
.get_applied_migrations(migration_table_name)
185184
.await
186185
.migration_err("error getting current schema version", None)?;
187186

refinery_core/src/traits/sync.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,24 @@ pub trait Migrate: Query<Vec<Migration>>
9292
where
9393
Self: Sized,
9494
{
95+
// Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table
96+
fn assert_migrations_table_query(migration_table_name: &str) -> String {
97+
ASSERT_MIGRATIONS_TABLE_QUERY.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
98+
}
99+
100+
fn get_last_applied_migration_query(migration_table_name: &str) -> String {
101+
GET_LAST_APPLIED_MIGRATION_QUERY.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
102+
}
103+
104+
fn get_applied_migrations_query(migration_table_name: &str) -> String {
105+
GET_APPLIED_MIGRATIONS_QUERY.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
106+
}
107+
95108
fn assert_migrations_table(&mut self, migration_table_name: &str) -> Result<usize, Error> {
96109
// Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table,
97110
// thou on this case it's just to be consistent with the async trait `AsyncMigrate`
98111
self.execute(
99-
[ASSERT_MIGRATIONS_TABLE_QUERY
100-
.replace("%MIGRATION_TABLE_NAME%", migration_table_name)
101-
.as_str()]
102-
.into_iter(),
112+
[Self::assert_migrations_table_query(migration_table_name).as_str()].into_iter(),
103113
)
104114
.migration_err("error asserting migrations table", None)
105115
}
@@ -109,10 +119,7 @@ where
109119
migration_table_name: &str,
110120
) -> Result<Option<Migration>, Error> {
111121
let mut migrations = self
112-
.query(
113-
&GET_LAST_APPLIED_MIGRATION_QUERY
114-
.replace("%MIGRATION_TABLE_NAME%", migration_table_name),
115-
)
122+
.query(Self::get_last_applied_migration_query(migration_table_name).as_str())
116123
.migration_err("error getting last applied migration", None)?;
117124

118125
Ok(migrations.pop())
@@ -123,10 +130,7 @@ where
123130
migration_table_name: &str,
124131
) -> Result<Vec<Migration>, Error> {
125132
let migrations = self
126-
.query(
127-
&GET_APPLIED_MIGRATIONS_QUERY
128-
.replace("%MIGRATION_TABLE_NAME%", migration_table_name),
129-
)
133+
.query(Self::get_applied_migrations_query(migration_table_name).as_str())
130134
.migration_err("error getting applied migrations", None)?;
131135

132136
Ok(migrations)

0 commit comments

Comments
 (0)