Commit 960c46d
authored
impr (cli + hql): fixing upserts, updates, and unique edges + improving CLI init command (#880)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes three core correctness issues — unique edge enforcement,
update-from-variable codegen, and upsert default-value handling — and
improves the CLI `init` command.
**Key changes:**
- **`add_e.rs`**: Rewrites unique-edge enforcement from the overly
strict `PutFlags::NO_OVERWRITE` (which blocked any second same-label
edge from a node regardless of target) to an explicit scan of existing
`out_edges_db` entries. The new logic correctly enforces uniqueness only
on the `(from, label, to)` triple. Tests confirm multiple targets and
sources are allowed.
- **`upsert.rs` / `traversal_steps.rs` / `traversal_validation.rs`**:
Adds `upsert_*_with_defaults` variants that apply schema-defined
`DEFAULT` values only during creation; updates correctly ignore them.
The code generator now emits `upsert_*_with_defaults(...)` calls with
defaults extracted from schema at analysis time. `TraversalType::Update`
refactored to carry `source`/`source_is_plural`, enabling direct
variable-to-update codegen without an intermediate read-only traversal.
- **`init.rs`**: Changes `.gitignore` creation from unconditional
overwrite to append with line deduplication. However, two bugs remain:
(1) unconditional cleanup tracking even when file pre-existed, risking
deletion of user content on failure; (2) no guard newline when appending
to files lacking a trailing newline, potentially corrupting the last
entry.
- **Test additions**: New unit tests for unique-edge semantics,
`upsert_*_with_defaults` behaviour, and two HQL integration test suites
(`update_from_var`, `user_test_13`).
**Findings:**
- `.gitignore` append logic has two correctness issues that can result
in data loss or file corruption.
<details><summary><h3>Flowchart</h3></summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["add_edge called"] --> B{is_unique flag set?}
B -->|Yes| C["Scan out_edges_db for from+label key"]
C --> D{Duplicate to_node found?}
D -->|Yes| E["Return DuplicateKey error"]
D -->|No| F["Allocate Edge with v6 UUID"]
B -->|No| F
F --> G["Write to edges_db with APPEND"]
G --> H["Write to out_edges_db with APPEND_DUP"]
H --> I["Write to in_edges_db with APPEND_DUP"]
I --> J["Return Ok with Edge value"]
K["upsert_n_with_defaults called"] --> L{Iterator yields item?}
L -->|Node exists| M["Update path: apply props only\nignore create_defaults"]
L -->|Empty iterator| N["Create path: merge_create_props\nprops take priority over defaults"]
L -->|Error| O["Propagate error"]
N --> P["Insert new node with merged props"]
M --> Q["Persist updated node"]
R["UPDATE from variable"] --> S{Source variable type?}
S -->|Single node var| T["G::new_mut_from with cloned var"]
S -->|Collection var| U["G::new_mut_from_iter with cloned iter"]
S -->|Inline traversal| V["Read-only traversal first then write"]
T --> W[".update then collect_to_obj"]
U --> W
V --> W
```
</details>
<sub>Last reviewed commit: 4e46111</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->32 files changed
Lines changed: 3484 additions & 1100 deletions
File tree
- helix-cli
- src
- commands
- integrations
- tests
- helix-db
- src
- helix_engine
- bm25
- storage_core
- tests/traversal_tests
- traversal_core/ops
- source
- util
- helixc
- analyzer/methods
- generator
- hql-tests/tests
- update_from_var
- user_test_12
- user_test_13
- user_test_14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
338 | 339 | | |
339 | 340 | | |
340 | 341 | | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
| 342 | + | |
| 343 | + | |
346 | 344 | | |
347 | | - | |
348 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
349 | 372 | | |
350 | 373 | | |
351 | 374 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
45 | 73 | | |
46 | 74 | | |
47 | 75 | | |
| |||
58 | 86 | | |
59 | 87 | | |
60 | 88 | | |
61 | | - | |
| 89 | + | |
62 | 90 | | |
63 | 91 | | |
64 | 92 | | |
| |||
140 | 168 | | |
141 | 169 | | |
142 | 170 | | |
143 | | - | |
| 171 | + | |
144 | 172 | | |
145 | 173 | | |
146 | 174 | | |
| |||
241 | 269 | | |
242 | 270 | | |
243 | 271 | | |
244 | | - | |
245 | | - | |
| 272 | + | |
| 273 | + | |
246 | 274 | | |
247 | 275 | | |
248 | 276 | | |
249 | 277 | | |
250 | 278 | | |
251 | 279 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
260 | 288 | | |
261 | 289 | | |
262 | 290 | | |
| |||
525 | 553 | | |
526 | 554 | | |
527 | 555 | | |
528 | | - | |
| 556 | + | |
529 | 557 | | |
530 | 558 | | |
531 | 559 | | |
| |||
540 | 568 | | |
541 | 569 | | |
542 | 570 | | |
543 | | - | |
544 | | - | |
| 571 | + | |
545 | 572 | | |
546 | 573 | | |
547 | 574 | | |
| |||
682 | 709 | | |
683 | 710 | | |
684 | 711 | | |
685 | | - | |
| 712 | + | |
686 | 713 | | |
687 | 714 | | |
688 | 715 | | |
689 | 716 | | |
690 | 717 | | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
0 commit comments