Commit 32fa1ad
committed
feat(driver-sql)!: NULL-safe organization uniques + declared-index 'organization' scope (ADR-0120 D3/D4, #5030)
Every organization-scoped unique index now materializes its organization key
part as COALESCE(organization_id, '__global__') instead of the bare column:
SQL UNIQUE is NULL-distinct, so the #3696 composite enforced nothing on
NULL-organization rows — on a single-tenant stack, every row (#5030, measured).
- uniqueIndexesFromFields / legacy replacements emit the NULL-safe key part;
field-level unique: 'organization' accepted as the explicit synonym of true.
- normalizeDeclaredIndex / expectedIndexes / syncDeclaredIndexes learn declared
unique: 'organization' (prepend the org key part; degrade with no tenant
column; a listed tenant column is made NULL-safe in place). 'global' / bare
true stays VERBATIM — the #3696 contract, now the 'global' arm (spec token
lands separately via #4986; driver deliberately merges first).
- Drift both sides share one normalization: physical COALESCE(col, <literal>)
attributes to col, compared literal-agnostically; the org key part is the
sync's own vocabulary (isSyncReproducibleIndex + tenantField), scoped so the
ADR-0048 overlay indexes keep their #4884 protection.
- D4 ceremony: the bare-composite tightening is a recreate_index gated by a
duplicate pre-flight probe — clean → safe (dev autoMigrate applies), dirty →
BLOCKED with a row report, old index kept; apply re-probes so even
--allow-destructive cannot drop a constraint whose replacement fails.
- plugin-auth: '__global__' reserved as organization id/slug at the
beforeCreateOrganization seam (ADR-0120 D3 guardrail).
- Tests per ADR-0120 D6.6: contract header rewritten, #5030 probe graduated as
a permanent regression, NULL-bucket semantics, declared 'organization'
pins, pre-flight both states; 'exactly as authored' retained for 'global'.
- ADR anchors for schema-drift.ts / sql-driver.ts (PD #13).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Akrzh2mHi2siSNVPPtfTw71 parent e96ad55 commit 32fa1ad
10 files changed
Lines changed: 1225 additions & 131 deletions
File tree
- .changeset
- packages/plugins
- driver-sql/src
- plugin-auth/src
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| |||
Large diffs are not rendered by default.
Lines changed: 37 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
68 | 81 | | |
69 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
70 | 91 | | |
71 | 92 | | |
72 | 93 | | |
73 | | - | |
74 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
75 | 105 | | |
76 | 106 | | |
77 | 107 | | |
| |||
185 | 215 | | |
186 | 216 | | |
187 | 217 | | |
188 | | - | |
| 218 | + | |
189 | 219 | | |
190 | 220 | | |
191 | 221 | | |
| |||
260 | 290 | | |
261 | 291 | | |
262 | 292 | | |
263 | | - | |
| 293 | + | |
264 | 294 | | |
265 | 295 | | |
266 | 296 | | |
| |||
281 | 311 | | |
282 | 312 | | |
283 | 313 | | |
284 | | - | |
| 314 | + | |
285 | 315 | | |
286 | 316 | | |
287 | 317 | | |
| |||
298 | 328 | | |
299 | 329 | | |
300 | 330 | | |
301 | | - | |
| 331 | + | |
302 | 332 | | |
303 | 333 | | |
304 | 334 | | |
| |||
Lines changed: 87 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
357 | 357 | | |
358 | 358 | | |
359 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
360 | 447 | | |
0 commit comments