Commit 4b45c54
feat(seed): per-organization seed replay for multi-tenant SaaS
Every newly created sys_organization now gets its own private copy of
the artifact's demo data (Salesforce-sandbox style) — independent of
other tenants, populated automatically on org creation regardless of
whether the org was auto-created by signup or manually via the
better-auth createOrganization API.
Pipeline:
- SeedLoaderConfig gains optional 'organizationId' — when set, each
record is stamped with that org and existing-record lookups
(loadExistingRecords / resolveFromDatabase) are scoped to that org
so upsert produces an independent per-tenant copy.
- AppPlugin registers two kernel services at start: 'seed-datasets'
(the parsed array) and 'seed-replayer' (a (orgId) => summary
closure that wraps SeedLoaderService). In multi-tenant mode it
also SKIPS the inline AppPlugin seed-insert — replay happens
per-org instead, eliminating NULL-org rows that previously needed
the orphan-claim hack.
- SecurityPlugin's sys_organization insert middleware now calls the
'seed-replayer' service for every new org (first or Nth). When the
replayer is unavailable it falls back to the legacy
claimOrphanTenantRows (first org) or cloneTenantSeedData (Nth org)
paths for backwards compatibility.
Fixes the reported issue where signing up a second user on
crm.objectos.app produced an empty CRM dashboard — the demo
accounts/contacts/leads/etc. were claimed by the first org and
invisible to all subsequent tenants.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1a14174 commit 4b45c54
4 files changed
Lines changed: 239 additions & 22 deletions
File tree
- packages
- plugins/plugin-security/src
- runtime/src
- spec/src/data
Lines changed: 107 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
412 | 429 | | |
413 | 430 | | |
414 | 431 | | |
| |||
420 | 437 | | |
421 | 438 | | |
422 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
423 | 454 | | |
424 | 455 | | |
425 | 456 | | |
| |||
431 | 462 | | |
432 | 463 | | |
433 | 464 | | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
438 | 483 | | |
439 | | - | |
440 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
441 | 489 | | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
442 | 495 | | |
443 | 496 | | |
444 | | - | |
| 497 | + | |
| 498 | + | |
445 | 499 | | |
446 | 500 | | |
447 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
448 | 541 | | |
449 | 542 | | |
450 | 543 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
279 | 353 | | |
280 | 354 | | |
281 | 355 | | |
| |||
321 | 395 | | |
322 | 396 | | |
323 | 397 | | |
| 398 | + | |
324 | 399 | | |
325 | 400 | | |
326 | 401 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
191 | 194 | | |
192 | 195 | | |
193 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
194 | 201 | | |
195 | 202 | | |
196 | 203 | | |
| |||
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
219 | 235 | | |
220 | 236 | | |
221 | 237 | | |
| |||
233 | 249 | | |
234 | 250 | | |
235 | 251 | | |
236 | | - | |
| 252 | + | |
237 | 253 | | |
238 | 254 | | |
239 | 255 | | |
| |||
339 | 355 | | |
340 | 356 | | |
341 | 357 | | |
| 358 | + | |
342 | 359 | | |
343 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
344 | 367 | | |
345 | | - | |
| 368 | + | |
346 | 369 | | |
347 | 370 | | |
348 | 371 | | |
| |||
361 | 384 | | |
362 | 385 | | |
363 | 386 | | |
| 387 | + | |
364 | 388 | | |
365 | 389 | | |
366 | 390 | | |
| |||
370 | 394 | | |
371 | 395 | | |
372 | 396 | | |
373 | | - | |
| 397 | + | |
374 | 398 | | |
375 | 399 | | |
376 | 400 | | |
| |||
637 | 661 | | |
638 | 662 | | |
639 | 663 | | |
| 664 | + | |
640 | 665 | | |
641 | 666 | | |
642 | 667 | | |
643 | | - | |
| 668 | + | |
644 | 669 | | |
645 | 670 | | |
646 | | - | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
647 | 677 | | |
648 | 678 | | |
649 | 679 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
215 | 234 | | |
216 | 235 | | |
217 | 236 | | |
| |||
0 commit comments