Commit 76318e4
authored
fix(fork): preserve folder structure across a fork edge for files, tables, and knowledge bases (#6752)
* fix(fork): carry folder structure across a fork edge for files, tables, and KBs
Only workflow folders were mirrored into the target workspace on fork
create and on sync. Copied files, tables, and knowledge bases were written
with a hardcoded `folderId: null`, so a push or pull flattened them all
into the target root and lost the source's grouping — visible as a fork
sync that drops folder structure when copying files to the parent.
`resolveForkFolderMapping` already did the real work (prune to folders
holding copied content plus ancestors, reuse same-named target folders,
remap parentId), but was pinned to `resourceType: 'workflow'` on both
reads and on the folder-ceiling check. Parameterize it by resource type
and run it per family, threading the resulting map into each copy instead
of nulling. The four folder-bearing families own disjoint trees and folder
ids are globally unique, so the per-family maps merge cleanly for the
`sim:folder/<id>` content rewrite, which previously resolved only for
workflow folders.
Existing forks are healed on their next sync rather than by a migration:
`rehomeFlattenedForkResources` re-homes mapped files/tables/KBs whose
target `folder_id` is still NULL — the exact signature of the old
flattening — so a placement chosen in the target is never overwritten and
the pass converges to a no-op.
`BlobCopyTask.targetFolderId` is optional so tasks queued by an earlier
deploy replay at the root exactly as before.
* refactor(fork): page the re-home lookups and reuse the plan's identity rows
Self-review of the folder-transit change surfaced two scaling problems in
the re-home pass, both of which grow with the size of the fork edge rather
than the size of the sync:
- The resource lookups built `IN (...)` lists straight from the edge's
mapping rows, so a large fork could hand Postgres a list approaching the
bind-parameter ceiling and a pathological query plan. Page them at 500,
matching the paging the rest of the fork copy already uses.
- The pass re-read the whole edge mapping via `getEdgeMappingRows`, which
the promote plan had already loaded in the same transaction — a second
full load of identical rows. Expose them on `ForkPromotePlan` and pass
them in, which also drops a mock from the re-home tests.
Also tally moved rows from `returning()` rather than the planned batch
size, so the log line reports what the `folder_id IS NULL` guard actually
wrote instead of what was attempted.
* fix(fork): drop the sync-time re-home pass, keep folder transit forward-only
Review surfaced three findings and every one of them was in the re-home
pass, none in the forward-looking fix:
- It keyed mapping orientation off `direction`, but the promote route
resolves the edge from whichever workspace the caller is acting in, so a
caller in the PARENT pushing to its child is `direction: 'push'` with the
parent as source. The plan derives this as
`sourceWorkspaceId === edge.parentWorkspaceId` for exactly that reason.
- Moving a file into a mirrored folder can violate
`workspace_files_workspace_folder_name_active_unique`, which would abort
the whole promote transaction and take the workflow sync down with it.
- `folder_id IS NULL` cannot distinguish "flattened by the old copy" from
"the user moved this to the root", so the pass re-applied on every sync
and would fight a deliberate placement indefinitely.
The first two are fixable; the third is not without a one-time marker per
edge, which means a migration. A heal that re-applies forever is worse
than no heal, so remove the pass entirely rather than ship it half-right.
Folder structure now transits correctly from this point forward, which is
the actual reported bug; healing already-flattened resources can be a
separate change with a marker to make it run exactly once.
Reverts the `ForkPromotePlan.mappingRows` field with it — it existed only
to feed this pass.1 parent 0077f6f commit 76318e4
10 files changed
Lines changed: 281 additions & 28 deletions
File tree
- apps/sim/ee/workspace-forking/lib
- copy
- promote
Lines changed: 92 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
237 | 238 | | |
238 | 239 | | |
239 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 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 | + | |
240 | 332 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
74 | 82 | | |
75 | 83 | | |
76 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
77 | 90 | | |
78 | 91 | | |
79 | 92 | | |
| |||
124 | 137 | | |
125 | 138 | | |
126 | 139 | | |
127 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
128 | 143 | | |
129 | 144 | | |
130 | 145 | | |
| |||
148 | 163 | | |
149 | 164 | | |
150 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
151 | 179 | | |
152 | 180 | | |
153 | 181 | | |
| |||
168 | 196 | | |
169 | 197 | | |
170 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
171 | 202 | | |
172 | 203 | | |
173 | 204 | | |
174 | | - | |
| 205 | + | |
175 | 206 | | |
176 | 207 | | |
177 | 208 | | |
| |||
269 | 300 | | |
270 | 301 | | |
271 | 302 | | |
272 | | - | |
| 303 | + | |
273 | 304 | | |
274 | 305 | | |
275 | 306 | | |
| |||
312 | 343 | | |
313 | 344 | | |
314 | 345 | | |
315 | | - | |
| 346 | + | |
316 | 347 | | |
317 | 348 | | |
318 | 349 | | |
| |||
Lines changed: 61 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
1343 | 1344 | | |
1344 | 1345 | | |
1345 | 1346 | | |
1346 | | - | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
1347 | 1357 | | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
1348 | 1361 | | |
1349 | 1362 | | |
1350 | 1363 | | |
1351 | | - | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
1352 | 1372 | | |
1353 | 1373 | | |
1354 | 1374 | | |
| |||
1437 | 1457 | | |
1438 | 1458 | | |
1439 | 1459 | | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1440 | 1499 | | |
1441 | 1500 | | |
1442 | 1501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
333 | 334 | | |
334 | 335 | | |
335 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
336 | 342 | | |
337 | 343 | | |
338 | 344 | | |
| |||
371 | 377 | | |
372 | 378 | | |
373 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
374 | 386 | | |
375 | 387 | | |
376 | 388 | | |
| |||
618 | 630 | | |
619 | 631 | | |
620 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
621 | 644 | | |
622 | 645 | | |
623 | 646 | | |
| |||
631 | 654 | | |
632 | 655 | | |
633 | 656 | | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
639 | 662 | | |
640 | | - | |
| 663 | + | |
641 | 664 | | |
642 | 665 | | |
643 | 666 | | |
| |||
674 | 697 | | |
675 | 698 | | |
676 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
677 | 711 | | |
678 | 712 | | |
679 | 713 | | |
| |||
682 | 716 | | |
683 | 717 | | |
684 | 718 | | |
685 | | - | |
686 | | - | |
| 719 | + | |
| 720 | + | |
687 | 721 | | |
688 | 722 | | |
689 | 723 | | |
| |||
741 | 775 | | |
742 | 776 | | |
743 | 777 | | |
744 | | - | |
| 778 | + | |
745 | 779 | | |
746 | 780 | | |
747 | 781 | | |
| |||
0 commit comments