Skip to content

Commit c5dd5ea

Browse files
committed
feat(sdk): multiple choices on failed migration
1 parent 332a629 commit c5dd5ea

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

meta-cli/src/deploy/push/migration_resolution.rs

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,7 @@ impl ConfirmHandler for ConfirmDatabaseResetRequired {
3131
fn on_confirm(&self) {
3232
let tg_path = self.typegraph_path.clone();
3333
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);
5035
}
5136
}
5237

@@ -61,10 +46,9 @@ pub struct ForceReset {
6146

6247
impl SelectOption for ForceReset {
6348
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);
6852
}
6953

7054
fn label(&self) -> OptionLabel<'_> {
@@ -92,16 +76,19 @@ impl RemoveLatestMigration {
9276
console: Addr<ConsoleActor>,
9377
loader: Addr<LoaderActor>,
9478
) -> Result<()> {
95-
tokio::fs::remove_dir_all(migration_path).await?;
79+
tokio::fs::remove_dir_all(migration_path).await?; // !
80+
9681
console.info(format!("Removed migration directory: {:?}", migration_path));
9782
console.info(format!(
9883
"You can now update your typegraph at {} to create an alternative non-breaking schema.",
9984
typegraph_path.display().to_string().bold()
10085
));
10186

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(())
10592
}
10693
}
10794

@@ -114,15 +101,19 @@ impl SelectOption for RemoveLatestMigration {
114101
let typegraph_path = self.typegraph_path.clone();
115102

116103
Arbiter::current().spawn(async move {
117-
Self::apply(
104+
if let Err(e) = Self::apply(
118105
&migration_path,
119106
&typegraph_path,
120107
runtime_name,
121-
console,
108+
console.clone(),
122109
loader,
123110
)
124111
.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+
}
126117
});
127118
}
128119

@@ -160,10 +151,7 @@ impl SelectOption for ManualResolution {
160151
Arbiter::current().spawn(async move {
161152
// TODO watch migration file??
162153
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);
167155
});
168156
}
169157

@@ -176,3 +164,22 @@ impl SelectOption for ManualResolution {
176164
}
177165
}
178166
}
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+
}

meta-cli/src/deploy/push/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
// TODO: rm?
54
pub mod migration_resolution;
65
pub mod pusher;

0 commit comments

Comments
 (0)