Skip to content

Commit c146cfe

Browse files
committed
[tyler/fix-on-conflict]: try revert
1 parent 4724cb8 commit c146cfe

1 file changed

Lines changed: 47 additions & 48 deletions

File tree

crates/cli/src/subcommands/publish.rs

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ i.e. only lowercase ASCII letters and numbers, separated by dashes."),
102102
.after_help("Run `spacetime help publish` for more detailed information.")
103103
}
104104

105+
fn prompt_and_clear(
106+
name_or_identity: &str,
107+
force: bool,
108+
mut builder: reqwest::RequestBuilder,
109+
) -> Result<reqwest::RequestBuilder, anyhow::Error> {
110+
println!(
111+
"This will DESTROY the current {} module, and ALL corresponding data.",
112+
name_or_identity
113+
);
114+
if !y_or_n(
115+
force,
116+
format!("Are you sure you want to proceed? [deleting {}]", name_or_identity).as_str(),
117+
)? {
118+
anyhow::bail!("Aborted.");
119+
}
120+
121+
builder = builder.query(&[("clear", true)]);
122+
Ok(builder)
123+
}
124+
105125
pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
106126
let server = args.get_one::<String>("server").map(|s| s.as_str());
107127
let name_or_identity = args.get_one::<String>("name|identity");
@@ -175,20 +195,24 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
175195
let domain = percent_encoding::percent_encode(name_or_identity.as_bytes(), encode_set);
176196
let mut builder = client.put(format!("{database_host}/v1/database/{domain}"));
177197

178-
builder = apply_pre_publish_if_needed(
179-
builder,
180-
&client,
181-
&database_host,
182-
name_or_identity,
183-
&domain.to_string(),
184-
host_type,
185-
&program_bytes,
186-
&auth_header,
187-
clear_database,
188-
force_break_clients,
189-
force,
190-
)
191-
.await?;
198+
if clear_database == ClearMode::Always {
199+
builder = prompt_and_clear(name_or_identity, force, builder)?;
200+
} else {
201+
builder = apply_pre_publish_if_needed(
202+
builder,
203+
&client,
204+
&database_host,
205+
&name_or_identity,
206+
&domain.to_string(),
207+
host_type,
208+
&program_bytes,
209+
&auth_header,
210+
clear_database,
211+
force_break_clients,
212+
force,
213+
)
214+
.await?;
215+
}
192216

193217
builder
194218
} else {
@@ -323,6 +347,9 @@ async fn apply_pre_publish_if_needed(
323347
force_break_clients: bool,
324348
force: bool,
325349
) -> Result<reqwest::RequestBuilder, anyhow::Error> {
350+
// The caller enforces this
351+
assert!(clear_database != ClearMode::Always);
352+
326353
if let Some(pre) = call_pre_publish(
327354
client,
328355
base_url,
@@ -335,48 +362,20 @@ async fn apply_pre_publish_if_needed(
335362
{
336363
match pre {
337364
PrePublishResult::ManualMigrate(manual) => {
338-
if clear_database == ClearMode::OnConflict {
339-
println!("{}", manual.reason);
340-
println!("Proceeding with database clear due to --delete-data=on-conflict.");
341-
}
342365
if clear_database == ClearMode::Never {
343366
println!("{}", manual.reason);
344367
println!("Aborting publish due to required manual migration.");
345368
anyhow::bail!("Aborting because publishing would require manual migration or deletion of data and --delete-data was not specified.");
346369
}
347-
if clear_database == ClearMode::Always {
348-
println!("{}", manual.reason);
349-
println!("Proceeding with database clear due to --delete-data=always.");
350-
}
351-
println!(
352-
"This will DESTROY the current {} module, and ALL corresponding data.",
353-
name_or_identity
354-
);
355-
if !y_or_n(
356-
force,
357-
format!("Are you sure you want to proceed? [deleting {}]", name_or_identity).as_str(),
358-
)? {
359-
anyhow::bail!("Aborting");
360-
}
361-
builder = builder.query(&[("clear", true)]);
370+
println!("{}", manual.reason);
371+
println!("Proceeding with database clear due to --delete-data=on-conflict.");
372+
373+
builder = prompt_and_clear(name_or_identity, force, builder)?;
362374
}
363375
PrePublishResult::AutoMigrate(auto) => {
364-
if clear_database == ClearMode::Always {
365-
println!("Auto-migration, does NOT require clearing the database, but proceeding with database clear due to --delete-data=always.");
366-
println!(
367-
"This will DESTROY the current {} module, and ALL corresponding data.",
368-
name_or_identity
369-
);
370-
if !y_or_n(
371-
force,
372-
format!("Are you sure you want to proceed? [deleting {}]", name_or_identity).as_str(),
373-
)? {
374-
anyhow::bail!("Aborting");
375-
}
376-
builder = builder.query(&[("clear", true)]);
377-
return Ok(builder);
378-
}
379376
println!("{}", auto.migrate_plan);
377+
// We only arrive here if you have not specified ClearMode::Always AND there was no
378+
// conflict that required manual migration.
380379
if auto.break_clients
381380
&& !y_or_n(
382381
force_break_clients || force,

0 commit comments

Comments
 (0)