Persistence: empty table -> no CSV (per Iteration 2 follow-up)
The Iteration-2 rule wrote a header-only CSV for every existing table, which surprised users who created a table and saw a file appear before any data went in. Tighten the rule: a CSV exists iff the table has rows. Persistence::write_table_data now delegates to delete_table_data when the snapshot is empty, removing any prior CSV. The schema-only invariant (YAML knows the table; CSV knows its rows) is preserved. The cascade-delete integration test was rewritten to assert the CSVs vanish; two new tests pin the rule (create -> no CSV; delete --all-rows -> CSV removed). Tests: 291 passing (256 lib + 9 + 9 + 17), 0 failing, 0 skipped.
This commit is contained in:
@@ -155,7 +155,19 @@ impl Persistence {
|
||||
/// Write `data/<table>.csv` from a table snapshot. Atomic
|
||||
/// per file. Creates the `data/` directory if missing
|
||||
/// (tolerant of fresh projects).
|
||||
///
|
||||
/// **Empty tables produce no CSV.** A header-only file
|
||||
/// would carry no information beyond what `project.yaml`
|
||||
/// already records, so an empty snapshot is treated
|
||||
/// identically to "drop this table's data file": the CSV
|
||||
/// is removed if it exists, no file is created if it
|
||||
/// doesn't. This keeps the rule "data lives in CSV; no
|
||||
/// data, no CSV" consistent and avoids surprising users
|
||||
/// with files they didn't ask for.
|
||||
pub fn write_table_data(&self, table: &TableSnapshot) -> Result<(), PersistenceError> {
|
||||
if table.rows.is_empty() {
|
||||
return self.delete_table_data(&table.name);
|
||||
}
|
||||
let data_dir = self.project_path.join(DATA_DIR);
|
||||
fs::create_dir_all(&data_dir).map_err(|source| PersistenceError::Io {
|
||||
operation: "create",
|
||||
|
||||
Reference in New Issue
Block a user