Skip to content

Commit 5559369

Browse files
authored
Merge pull request #5 from zcash/bugfixes-and-improvements
Bugfixes and improvements
2 parents 668f1ae + ba633c9 commit 5559369

File tree

9 files changed

+691
-194
lines changed

9 files changed

+691
-194
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ jobs:
4747
- uses: actions/checkout@v4
4848
- uses: Swatinem/rust-cache@v1
4949
- run: cargo clippy --all-features -- -D warnings
50-
- run: cargo fmt -- --check
5150

5251
fmt:
5352
name: Rustfmt

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemerz-postgres/src/lib.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
//! use postgres::{Client, NoTls, Transaction};
1616
//! use schemerz::{Migration, Migrator};
1717
//! use schemerz_postgres::{PostgresAdapter, PostgresAdapterError, PostgresMigration};
18-
//! use uuid::Uuid;
18+
//! use uuid::uuid;
1919
//!
2020
//! struct MyExampleMigration;
2121
//! migration!(
2222
//! MyExampleMigration,
23-
//! "4885e8ab-dafa-4d76-a565-2dee8b04ef60",
23+
//! uuid!("4885e8ab-dafa-4d76-a565-2dee8b04ef60"),
2424
//! [],
2525
//! "An example migration without dependencies.");
2626
//!
@@ -61,7 +61,7 @@ use uuid::Uuid;
6161
use schemerz::{Adapter, Migration};
6262

6363
/// PostgreSQL-specific trait for schema migrations.
64-
pub trait PostgresMigration: Migration {
64+
pub trait PostgresMigration: Migration<Uuid> {
6565
/// Apply a migration to the database using a transaction.
6666
fn up(&self, _transaction: &mut Transaction<'_>) -> Result<(), PostgresError> {
6767
Ok(())
@@ -127,8 +127,8 @@ impl<'a> PostgresAdapter<'a> {
127127
}
128128
}
129129

130-
impl<'a> Adapter for PostgresAdapter<'a> {
131-
type MigrationType = dyn PostgresMigration;
130+
impl<'a> Adapter<Uuid> for PostgresAdapter<'a> {
131+
type MigrationType = Box<dyn PostgresMigration>;
132132

133133
type Error = PostgresAdapterError;
134134

@@ -176,10 +176,10 @@ mod tests {
176176
use schemerz::test_schemerz_adapter;
177177
use schemerz::testing::*;
178178

179-
impl PostgresMigration for TestMigration {}
179+
impl PostgresMigration for TestMigration<Uuid> {}
180180

181-
impl<'a> TestAdapter for PostgresAdapter<'a> {
182-
fn mock(id: Uuid, dependencies: HashSet<Uuid>) -> Box<Self::MigrationType> {
181+
impl<'a> TestAdapter<Uuid> for PostgresAdapter<'a> {
182+
fn mock(id: Uuid, dependencies: HashSet<Uuid>) -> Self::MigrationType {
183183
Box::new(TestMigration::new(id, dependencies))
184184
}
185185
}
@@ -196,7 +196,13 @@ mod tests {
196196
adapter
197197
}
198198

199+
fn uuid_iter() -> impl Iterator<Item = Uuid> {
200+
(0..).map(|v| Uuid::from_fields(v as u32, v, v, &[0; 8]))
201+
}
202+
199203
test_schemerz_adapter!(
200204
let mut conn = build_test_connection(),
201-
build_test_adapter(&mut conn));
205+
build_test_adapter(&mut conn),
206+
uuid_iter(),
207+
);
202208
}

schemerz-rusqlite/src/lib.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
//! use rusqlite::{params, Connection, Transaction, Error as RusqliteError};
1616
//! use schemerz::{Migration, Migrator};
1717
//! use schemerz_rusqlite::{RusqliteAdapter, RusqliteAdapterError, RusqliteMigration};
18-
//! use uuid::Uuid;
18+
//! use uuid::uuid;
1919
//!
2020
//! struct MyExampleMigration;
2121
//! migration!(
2222
//! MyExampleMigration,
23-
//! "4885e8ab-dafa-4d76-a565-2dee8b04ef60",
23+
//! uuid!("4885e8ab-dafa-4d76-a565-2dee8b04ef60"),
2424
//! [],
2525
//! "An example migration without dependencies.");
2626
//!
@@ -62,7 +62,7 @@ use uuid::Uuid;
6262
use schemerz::{Adapter, Migration};
6363

6464
/// SQlite-specific trait for schema migrations.
65-
pub trait RusqliteMigration: Migration {
65+
pub trait RusqliteMigration: Migration<Uuid> {
6666
type Error: From<RusqliteError>;
6767

6868
/// Apply a migration to the database using a transaction.
@@ -137,10 +137,11 @@ impl<'a, E> RusqliteAdapter<'a, E> {
137137
}
138138
}
139139

140-
impl<'a, E: From<RusqliteError> + Sync + Send + Error + 'static> Adapter
141-
for RusqliteAdapter<'a, E>
140+
impl<'a, E> Adapter<Uuid> for RusqliteAdapter<'a, E>
141+
where
142+
E: From<RusqliteError> + Sync + Send + Error + 'static,
142143
{
143-
type MigrationType = dyn RusqliteMigration<Error = E>;
144+
type MigrationType = Box<dyn RusqliteMigration<Error = E>>;
144145

145146
type Error = E;
146147

@@ -197,12 +198,12 @@ mod tests {
197198
use schemerz::test_schemerz_adapter;
198199
use schemerz::testing::*;
199200

200-
impl RusqliteMigration for TestMigration {
201+
impl RusqliteMigration for TestMigration<Uuid> {
201202
type Error = RusqliteError;
202203
}
203204

204-
impl<'a> TestAdapter for RusqliteAdapter<'a, RusqliteError> {
205-
fn mock(id: Uuid, dependencies: HashSet<Uuid>) -> Box<Self::MigrationType> {
205+
impl<'a> TestAdapter<Uuid> for RusqliteAdapter<'a, RusqliteError> {
206+
fn mock(id: Uuid, dependencies: HashSet<Uuid>) -> Self::MigrationType {
206207
Box::new(TestMigration::new(id, dependencies))
207208
}
208209
}
@@ -217,7 +218,13 @@ mod tests {
217218
adapter
218219
}
219220

221+
fn uuid_iter() -> impl Iterator<Item = Uuid> {
222+
(0..).map(|v| Uuid::from_fields(v as u32, v, v, &[0; 8]))
223+
}
224+
220225
test_schemerz_adapter!(
221226
let mut conn = build_test_connection(),
222-
build_test_adapter(&mut conn));
227+
build_test_adapter(&mut conn),
228+
uuid_iter(),
229+
);
223230
}

schemerz/CHANGELOG.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,57 @@ and this library adheres to Rust's notion of
99
<!-- next-header -->
1010
## [Unreleased]
1111

12+
### Fixed
13+
- `schemerz::Migrator::{register, register_multiple}` can now register dependent
14+
migrations before their dependencies. Previously this would result in a graph
15+
with missing edges, leading to some migrations not being applied.
16+
- `schemerz::Migrator::{up, down}` now reliably run migrations in the correct
17+
order.
18+
1219
### Added
1320
- `schemerz::test_schemerz_adapter`
21+
- Compared to the previous `test_schemer_adapter`, this requires an additional
22+
argument with an infinite iterator of valid indices for the tests to use.
23+
- Blanket implementation of `schemerz::Migration` for the following types:
24+
- `Box<T>`
25+
- `Rc<T>`
26+
- `Arc<T>`
27+
28+
### Changed
29+
- `schemerz::Migrator` no longer uses `Box` in its API:
30+
- `schemerz::Adapter::MigrationType` must now be `Sized`.
31+
- `schemerz::Migrator::{register, register_multiple}` now take the migrations
32+
without a `Box` wrapper`.
33+
- `schemerz::TestAdapter::mock` now returns the migration without a `Box`
34+
wrapper.
35+
- `schemerz::Migration` is now generic over its index type, to make writing
36+
tests easier (as they can now use an alternative index type like `usize`).
37+
Production migrations should still use `uuid::Uuid` for resiliency.
38+
- The following traits and structs now have a generic parameter `I`:
39+
- `Migration`
40+
- `Adapter`
41+
- `testing::TestAdapter`
42+
- `testing::TestMigration`
43+
- The `Migrator` struct now has an `I: Clone + Display + Hash + Eq` parameter.
44+
- The following methods now take `I` as an argument instead of `uuid::Uuid`:
45+
- `Migrator::up`
46+
- `Migrator::down`
47+
- The return types of the following methods now involve `I` instead of
48+
`uuid::Uuid`:
49+
- `Migration::id`
50+
- `Migration::dependencies`
51+
- `Adapter::applied_migrations`
52+
- `testing::TestAdapter::mock`
53+
- `testing::TestMigration::new`
54+
- The `schemerz::{DependencyError, MigratorError>` enums now have a generic
55+
parameter `I` that replaces uses of `uuid::Uuid`.
56+
- The `schemerz::migration` macro now supports an optional initial argument
57+
with the index type (which defaults to `uuid::Uuid`).
58+
- The individual tests in the `schemerz::testing` module now require an
59+
adapter with an `I: Clone + FromStr + Debug + Display + Hash + Eq` bound,
60+
and each take an additional argument `T: Iterator<Item = I>`.
61+
- `schemerz::Migrator::register_multiple` now takes an iterator of migrations
62+
instead of a `Vec`.
1463

1564
### Removed
1665
- `schemerz::test_schemer_adapter` (use `test_schemerz_adapter` instead).

schemerz/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ daggy = "0.8"
1919
log = "0.4"
2020
thiserror = "1.0"
2121
uuid = { version = "1" }
22+
indexmap = "1"

0 commit comments

Comments
 (0)