Commit 57b7ef5
authored
Limit update() to only work on primary keys (#4279)
## Summary
- Restricts `update()` across all three server-side SDKs (Rust, C#,
TypeScript) to only work on primary key columns, not all unique columns
- Calling `update()` on a non-PK unique column is semantically a
delete+insert — clients won't see it as a row update unless the primary
key stays the same
- Fresh re-implementation of #1862, extended to cover C# and TypeScript
bindings
### Design principle
Primary key is a constraint on columns, not a property of indexes. An
index is unique or not unique — whether `update()` is available is
derived from the column's attributes at the point of use, not stored on
the index.
This differs from #1862 which introduced a `Uniqueness` enum (`No |
Unique | PrimaryKey`) on the index itself. Instead, we keep `is_unique:
bool` and check the column metadata where needed.
### Rust changes
- Add `PrimaryKey` marker trait and `where Col: PrimaryKey` bound on
`UniqueColumn::update()`
- `marker_type()` receives `primary_key_column` and checks the column
directly — no `is_pk` field on the index
- `sdk-test` unique tables use `update_non_pk_by` (delete+insert)
instead of `update_by`
- Benchmarks that used `update()` on `#[unique]` columns changed to
either `#[primary_key]` or delete+insert
### C# changes
- Only emit `Update()` on `UniqueIndex` when the column has `PrimaryKey`
attrs
- Update `unique_*` test reducers in `sdk-test-cs` to use
`Delete()`+`Insert()` instead
### TypeScript changes
- `UniqueIndex` now has only `find` + `delete` (no `update`)
- `AllColumnsPrimaryKey` type-level helper checks column metadata from
the `TableDef`
- `Index` routing conditionally intersects `{ update() }` when columns
are PK
- Runtime only attaches `update` method for PK unique indexes
- `sdk-test-ts` unique tables use delete+insert instead of update
- Type-level test in `schema.test-d.ts` verifies `id.update()` compiles
(PK) and `name2.update` errors (non-PK unique)
## Test plan
- [x] C# codegen tests pass (`dotnet test
crates/bindings-csharp/Codegen.Tests`)
- [x] Rust SDK test module compiles
- [x] Benchmarks compile
- [x] TypeScript type checks pass (`npx tsc --noEmit`)
- [ ] CI passes
Closes #18621 parent 626e209 commit 57b7ef5
17 files changed
Lines changed: 201 additions & 117 deletions
File tree
- crates
- bindings-csharp
- Codegen.Tests/fixtures
- diag/snapshots
- server/snapshots
- Codegen
- bindings-macro/src
- bindings-typescript/src
- lib
- server
- bindings/src
- modules
- benchmarks-cs
- benchmarks-ts/src
- benchmarks/src
- sdk-test-cs
- sdk-test-ts/src
- sdk-test-view/src
- sdk-test/src
Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 0 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1256 | 1256 | | |
1257 | 1257 | | |
1258 | 1258 | | |
1259 | | - | |
1260 | | - | |
1261 | 1259 | | |
1262 | 1260 | | |
1263 | 1261 | | |
| |||
1482 | 1480 | | |
1483 | 1481 | | |
1484 | 1482 | | |
1485 | | - | |
1486 | | - | |
1487 | | - | |
1488 | | - | |
1489 | 1483 | | |
1490 | 1484 | | |
1491 | 1485 | | |
| |||
1506 | 1500 | | |
1507 | 1501 | | |
1508 | 1502 | | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
1512 | | - | |
1513 | 1503 | | |
1514 | 1504 | | |
1515 | 1505 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
501 | 504 | | |
502 | 505 | | |
503 | 506 | | |
504 | 507 | | |
505 | 508 | | |
506 | 509 | | |
507 | 510 | | |
508 | | - | |
| 511 | + | |
509 | 512 | | |
510 | 513 | | |
511 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
502 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
503 | 508 | | |
504 | 509 | | |
505 | 510 | | |
| |||
560 | 565 | | |
561 | 566 | | |
562 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
563 | 571 | | |
564 | 572 | | |
565 | 573 | | |
| |||
824 | 832 | | |
825 | 833 | | |
826 | 834 | | |
827 | | - | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
828 | 839 | | |
829 | 840 | | |
830 | 841 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
50 | 65 | | |
51 | 66 | | |
52 | 67 | | |
| 68 | + | |
53 | 69 | | |
54 | 70 | | |
55 | 71 | | |
56 | 72 | | |
57 | 73 | | |
58 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
59 | 79 | | |
60 | 80 | | |
61 | 81 | | |
| |||
103 | 123 | | |
104 | 124 | | |
105 | 125 | | |
106 | | - | |
107 | 126 | | |
108 | 127 | | |
109 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
541 | 546 | | |
542 | 547 | | |
543 | 548 | | |
| |||
574 | 579 | | |
575 | 580 | | |
576 | 581 | | |
577 | | - | |
| 582 | + | |
578 | 583 | | |
579 | 584 | | |
580 | 585 | | |
| |||
595 | 600 | | |
596 | 601 | | |
597 | 602 | | |
598 | | - | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
599 | 606 | | |
600 | 607 | | |
601 | 608 | | |
| |||
607 | 614 | | |
608 | 615 | | |
609 | 616 | | |
610 | | - | |
611 | | - | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
612 | 620 | | |
613 | 621 | | |
614 | | - | |
| 622 | + | |
615 | 623 | | |
616 | 624 | | |
617 | 625 | | |
| |||
638 | 646 | | |
639 | 647 | | |
640 | 648 | | |
641 | | - | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
642 | 652 | | |
643 | 653 | | |
644 | 654 | | |
| |||
650 | 660 | | |
651 | 661 | | |
652 | 662 | | |
653 | | - | |
654 | | - | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
655 | 666 | | |
656 | 667 | | |
657 | 668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
48 | 62 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
277 | 282 | | |
278 | 283 | | |
279 | 284 | | |
| |||
358 | 363 | | |
359 | 364 | | |
360 | 365 | | |
361 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
362 | 372 | | |
363 | 373 | | |
364 | 374 | | |
365 | 375 | | |
366 | 376 | | |
367 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
368 | 381 | | |
369 | 382 | | |
370 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
0 commit comments