diff --git a/src/runtime.rs b/src/runtime.rs index 7beed1b..7477b9f 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -133,13 +133,21 @@ pub async fn run(args: Args) -> Result<()> { match database.rebuild_from_text(project_path.clone(), None).await { Ok(()) => { // Surface the silent rebuild as a system note - // so the user sees that the .db was - // reconstructed rather than wondering whether - // anything happened. - let summary = summarize_project(&project_path).unwrap_or_else(|_| { - "rebuilt playground.db from project.yaml + data/".to_string() - }); - initial_events.push(AppEvent::RebuildSucceeded { summary }); + // *only* when there was something material to + // reconstruct. A fresh-launch temp project + // hits this branch with zero tables and zero + // rows — the rebuild ran, but nothing + // reconstructable existed, so there's nothing + // worth telling the user. The explicit + // `rebuild` command still always reports its + // summary (see spawn_rebuild) since the user + // asked. + if project_has_content(&project_path) { + let summary = summarize_project(&project_path).unwrap_or_else(|_| { + "rebuilt playground.db from project.yaml + data/".to_string() + }); + initial_events.push(AppEvent::RebuildSucceeded { summary }); + } } Err(e) => { // The terminal is still in cooked mode here @@ -813,6 +821,27 @@ fn spawn_prepare_rebuild( }); } +/// Does the project at `project_path` actually have any +/// schema or data? +/// +/// "Has content" means at least one table is declared in +/// `project.yaml` OR at least one CSV row exists under +/// `data/`. A brand-new auto-named temp project, having +/// neither, returns `false`. Errors reading the project +/// (corrupt YAML, missing dir) also return `false` — +/// suppressing a misleading "0 tables reconstructed" +/// message for a project we can't read is the right default. +fn project_has_content(project_path: &std::path::Path) -> bool { + let yaml_path = project_path.join(crate::project::PROJECT_YAML); + let Ok(yaml) = std::fs::read_to_string(&yaml_path) else { + return false; + }; + let Ok(snapshot) = crate::persistence::parse_schema(&yaml) else { + return false; + }; + !snapshot.tables.is_empty() +} + fn summarize_project(project_path: &std::path::Path) -> Result { let yaml_path = project_path.join(crate::project::PROJECT_YAML); let yaml = std::fs::read_to_string(&yaml_path).map_err(|e| e.to_string())?;