runtime: suppress silent-rebuild banner for empty projects
A fresh-launch temp project enters run() with no .db, calls rebuild_from_text on an empty schema, and used to surface a "[ok] rebuild — 0 tables and 0 rows will be reconstructed" note that conveyed no information. Now we only emit the note when the project actually has tables. The explicit `rebuild` command still always reports its summary — the user asked.
This commit is contained in:
+32
-3
@@ -133,14 +133,22 @@ 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.
|
||||
// *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
|
||||
// (we haven't entered the alternate screen
|
||||
@@ -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<String, String> {
|
||||
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())?;
|
||||
|
||||
Reference in New Issue
Block a user