@@ -102,26 +102,6 @@ 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 confirm_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-
125105pub async fn exec ( mut config : Config , args : & ArgMatches ) -> Result < ( ) , anyhow:: Error > {
126106 let server = args. get_one :: < String > ( "server" ) . map ( |s| s. as_str ( ) ) ;
127107 let name_or_identity = args. get_one :: < String > ( "name|identity" ) ;
@@ -195,24 +175,20 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
195175 let domain = percent_encoding:: percent_encode ( name_or_identity. as_bytes ( ) , encode_set) ;
196176 let mut builder = client. put ( format ! ( "{database_host}/v1/database/{domain}" ) ) ;
197177
198- if clear_database == ClearMode :: Always {
199- builder = confirm_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- }
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 ?;
216192
217193 builder
218194 } else {
@@ -347,9 +323,6 @@ async fn apply_pre_publish_if_needed(
347323 force_break_clients : bool ,
348324 force : bool ,
349325) -> Result < reqwest:: RequestBuilder , anyhow:: Error > {
350- // The caller enforces this
351- assert ! ( clear_database != ClearMode :: Always ) ;
352-
353326 if let Some ( pre) = call_pre_publish (
354327 client,
355328 base_url,
@@ -362,20 +335,48 @@ async fn apply_pre_publish_if_needed(
362335 {
363336 match pre {
364337 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+ }
365342 if clear_database == ClearMode :: Never {
366343 println ! ( "{}" , manual. reason) ;
367344 println ! ( "Aborting publish due to required manual migration." ) ;
368345 anyhow:: bail!( "Aborting because publishing would require manual migration or deletion of data and --delete-data was not specified." ) ;
369346 }
370- println ! ( "{}" , manual. reason) ;
371- println ! ( "Proceeding with database clear due to --delete-data=on-conflict." ) ;
372-
373- builder = confirm_and_clear ( name_or_identity, force, builder) ?;
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 ) ] ) ;
374362 }
375363 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+ }
376379 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.
379380 if auto. break_clients
380381 && !y_or_n (
381382 force_break_clients || force,
0 commit comments