@@ -31,22 +31,7 @@ impl ConfirmHandler for ConfirmDatabaseResetRequired {
31
31
fn on_confirm ( & self ) {
32
32
let tg_path = self . typegraph_path . clone ( ) ;
33
33
let runtime_name = self . runtime_name . clone ( ) ;
34
-
35
- // reset
36
- let glob_cfg = ServerStore :: get_migration_action_glob ( ) ;
37
- ServerStore :: set_migration_action (
38
- tg_path. clone ( ) ,
39
- RuntimeMigrationAction {
40
- runtime_name,
41
- action : MigrationAction {
42
- reset : true , // !
43
- create : glob_cfg. create ,
44
- } ,
45
- } ,
46
- ) ;
47
-
48
- // reload
49
- self . loader . do_send ( LoadModule ( tg_path. into ( ) ) ) ;
34
+ do_force_reset ( & self . loader , tg_path, runtime_name) ;
50
35
}
51
36
}
52
37
@@ -61,10 +46,9 @@ pub struct ForceReset {
61
46
62
47
impl SelectOption for ForceReset {
63
48
fn on_select ( & self ) {
64
- // force reload
65
- // set_file_mtime(self.typegraph_path.clone(), FileTime::now()).unwrap();
66
- self . loader
67
- . do_send ( LoadModule ( self . typegraph_path . clone ( ) . into ( ) ) ) ;
49
+ let tg_path = self . typegraph_path . clone ( ) ;
50
+ let runtime_name = self . runtime_name . clone ( ) ;
51
+ do_force_reset ( & self . loader , tg_path, runtime_name) ;
68
52
}
69
53
70
54
fn label ( & self ) -> OptionLabel < ' _ > {
@@ -92,16 +76,19 @@ impl RemoveLatestMigration {
92
76
console : Addr < ConsoleActor > ,
93
77
loader : Addr < LoaderActor > ,
94
78
) -> Result < ( ) > {
95
- tokio:: fs:: remove_dir_all ( migration_path) . await ?;
79
+ tokio:: fs:: remove_dir_all ( migration_path) . await ?; // !
80
+
96
81
console. info ( format ! ( "Removed migration directory: {:?}" , migration_path) ) ;
97
82
console. info ( format ! (
98
83
"You can now update your typegraph at {} to create an alternative non-breaking schema." ,
99
84
typegraph_path. display( ) . to_string( ) . bold( )
100
85
) ) ;
101
86
102
- loader. do_send ( LoadModule ( typegraph_path. to_path_buf ( ) . into ( ) ) ) ;
103
- // QUESTION: Reload or is there anything else more to do??
104
- todo ! ( "OneTimePushOption::ForceReset {runtime_name}" ) ;
87
+ let tg_path = typegraph_path. to_path_buf ( ) ;
88
+ let runtime_name = runtime_name. clone ( ) ;
89
+ do_force_reset ( & loader, tg_path, runtime_name) ;
90
+
91
+ Ok ( ( ) )
105
92
}
106
93
}
107
94
@@ -114,15 +101,19 @@ impl SelectOption for RemoveLatestMigration {
114
101
let typegraph_path = self . typegraph_path . clone ( ) ;
115
102
116
103
Arbiter :: current ( ) . spawn ( async move {
117
- Self :: apply (
104
+ if let Err ( e ) = Self :: apply (
118
105
& migration_path,
119
106
& typegraph_path,
120
107
runtime_name,
121
- console,
108
+ console. clone ( ) ,
122
109
loader,
123
110
)
124
111
. await
125
- . unwrap ( ) ; // TODO handle error
112
+ {
113
+ console. warning ( format ! ( "Migration Path {}" , migration_path. display( ) ) ) ;
114
+ console. error ( e. to_string ( ) ) ;
115
+ panic ! ( "{}" , e. to_string( ) ) ; // may occur if the latest migration does not match
116
+ }
126
117
} ) ;
127
118
}
128
119
@@ -160,10 +151,7 @@ impl SelectOption for ManualResolution {
160
151
Arbiter :: current ( ) . spawn ( async move {
161
152
// TODO watch migration file??
162
153
console. read_line ( ) . await ;
163
-
164
- loader. do_send ( LoadModule ( typegraph_path. into ( ) ) ) ;
165
- // QUESTION: Reload or is there anything else more to do??
166
- todo ! ( "OneTimePushOption::ForceReset {runtime_name}" ) ;
154
+ do_force_reset ( & loader, typegraph_path, runtime_name) ;
167
155
} ) ;
168
156
}
169
157
@@ -176,3 +164,22 @@ impl SelectOption for ManualResolution {
176
164
}
177
165
}
178
166
}
167
+
168
+ /// Set `reset` to `true` for the specified prisma runtime + re-run the typegraph
169
+ fn do_force_reset ( loader : & Addr < LoaderActor > , tg_path : PathBuf , runtime_name : String ) {
170
+ // reset
171
+ let glob_cfg = ServerStore :: get_migration_action_glob ( ) ;
172
+ ServerStore :: set_migration_action (
173
+ tg_path. clone ( ) ,
174
+ RuntimeMigrationAction {
175
+ runtime_name,
176
+ action : MigrationAction {
177
+ reset : true , // !
178
+ create : glob_cfg. create ,
179
+ } ,
180
+ } ,
181
+ ) ;
182
+
183
+ // reload
184
+ loader. do_send ( LoadModule ( tg_path. into ( ) ) ) ;
185
+ }
0 commit comments