Skip to content

Commit 8da2299

Browse files
committed
fix: name the created query ID and fetch command after a collision
1 parent 64bd6bf commit 8da2299

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎src/commands/deploy.rs‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ fn ambiguous_query_files_message(
163163
)
164164
}
165165

166+
fn created_query_collision_message(created_id: u64, new_base: &Path) -> String {
167+
format!(
168+
"Query {created_id} was created on Redash, but local files already exist at {}.*; the draft files were preserved. Run `stmo-cli fetch {created_id}` to pull the Redash copy.",
169+
new_base.display()
170+
)
171+
}
172+
166173
async fn ensure_unambiguous_query_files(client: &RedashClient, id: u64) -> Result<()> {
167174
let file_sets = crate::commands::query_file_sets_by_id(Path::new("queries"), id)?;
168175
if file_sets.len() <= 1 {
@@ -425,11 +432,7 @@ pub async fn deploy_one(client: &RedashClient, id: u64, name: &str) -> Result<Qu
425432
let fetched = client.get_query(created.id).await?;
426433
let new_base = Path::new("queries").join(fetched.id.to_string());
427434
if new_base.with_extension("sql").exists() || new_base.with_extension("yaml").exists() {
428-
bail!(
429-
"Query {} was created, but local files already exist at {}.*; the draft files were preserved",
430-
fetched.id,
431-
new_base.display()
432-
);
435+
bail!(created_query_collision_message(fetched.id, &new_base));
433436
}
434437
println!(" ✓ Created new query: {} - {name}", fetched.id);
435438
(fetched, new_base)
@@ -973,6 +976,17 @@ mod tests {
973976
assert!(err_msg.contains("second-example-query.yaml"));
974977
}
975978

979+
#[test]
980+
fn created_query_collision_message_names_the_created_id_and_suggests_fetch() {
981+
let message =
982+
created_query_collision_message(1_200_000_001, Path::new("queries/1200000001"));
983+
984+
assert!(message.contains("Query 1200000001 was created"));
985+
assert!(message.contains("queries/1200000001.*"));
986+
assert!(message.contains("the draft files were preserved"));
987+
assert!(message.contains(&format!("stmo-cli fetch {}", 1_200_000_001)));
988+
}
989+
976990
#[test]
977991
fn ambiguous_query_files_message_names_the_base_matching_the_server_copy() {
978992
let file_sets = vec![

0 commit comments

Comments
 (0)