@@ -42,14 +42,11 @@ impl<'u> MigrationsBuilder<'u> {
42
42
///
43
43
/// Panics if no migration with the `id` provided exists.
44
44
#[ must_use]
45
- pub fn edit ( mut self , id : usize , f : impl Fn ( & mut M ) ) -> Self {
45
+ pub fn edit ( mut self , id : usize , f : impl Fn ( M ) -> M ) -> Self {
46
46
if id < 1 {
47
47
panic ! ( "id cannot be equal to 0" ) ;
48
48
}
49
- f ( self
50
- . migrations
51
- . get_mut ( id - 1 )
52
- . expect ( "No migration with the given index" ) ) ;
49
+ self . migrations [ id - 1 ] = f ( self . migrations [ id - 1 ] . clone ( ) ) ;
53
50
self
54
51
}
55
52
@@ -76,8 +73,9 @@ impl<'u> M<'u> {
76
73
/// Use [`M::up_with_hook`] instead if you're creating a new migration.
77
74
/// This method is meant for editing existing transactions
78
75
/// when using the [`MigrationsBuilder`].
79
- pub fn set_up_hook ( & mut self , hook : impl MigrationHook + ' static ) {
76
+ pub fn set_up_hook ( mut self , hook : impl MigrationHook + ' static ) -> Self {
80
77
self . up_hook = Some ( hook. clone_box ( ) ) ;
78
+ self
81
79
}
82
80
83
81
/// Replace the `down_hook` in the given migration with the provided one.
@@ -87,7 +85,8 @@ impl<'u> M<'u> {
87
85
/// Use [`M::down_with_hook`] instead if you're creating a new migration.
88
86
/// This method is meant for editing existing transactions
89
87
/// when using the [`MigrationsBuilder`].
90
- pub fn set_down_hook ( & mut self , hook : impl MigrationHook + ' static ) {
88
+ pub fn set_down_hook ( mut self , hook : impl MigrationHook + ' static ) -> Self {
91
89
self . down_hook = Some ( hook. clone_box ( ) ) ;
90
+ self
92
91
}
93
92
}
0 commit comments