Repository navigation
Conversation
Migration Safety CheckFound 7 potential issues: 20261028_180035_add_media_folders.ts Warning (line 10): DELETE keyword detected - review for data loss FOREIGN KEY (\`parent_id\`) REFERENCES \`payload_folders\`(\`id\`) ON UPDATE no action ON DELETE cascadeWarning (line 27): DELETE keyword detected - review for data loss FOREIGN KEY (\`tenant_id\`) REFERENCES \`tenants\`(\`id\`) ON UPDATE no action ON DELETE set null,Warning (line 28): DELETE keyword detected - review for data loss FOREIGN KEY (\`folder_id\`) REFERENCES \`payload_folders\`(\`id\`) ON UPDATE no action ON DELETE set nullWarning (line 45): DELETE keyword detected - review for data loss sql`ALTER TABLE \`media\` ADD \`folder_id\` integer REFERENCES payload_folders(id) ON DELETE set null;`,Warning (line 45): ALTER keyword detected - review for data loss sql`ALTER TABLE \`media\` ADD \`folder_id\` integer REFERENCES payload_folders(id) ON DELETE set null;`,Warning (line 49): DELETE keyword detected - review for data loss sql`ALTER TABLE \`payload_locked_documents_rels\` ADD \`payload_folders_id\` integer REFERENCES payload_folders(id) ON DELETE cascade;`,Warning (line 49): ALTER keyword detected - review for data loss sql`ALTER TABLE \`payload_locked_documents_rels\` ADD \`payload_folders_id\` integer REFERENCES payload_folders(id) ON DELETE cascade;`,Review these patterns and add backup/restore logic if needed. See |
6f9c9aa to
88ae737
Compare
a3f9b83 to
1c1a485
Compare
1c1a485 to
b369b9c
Compare
b369b9c to
50f4fc0
Compare
Deleting a tenant failed on SQLite's NOT NULL constraint because these three tenant-scoped collections were missing from the deprovision list. Form submissions go before forms, which they reference. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Enables Payload's folders on Media and folds the generated payload-folders collection into our tenancy through the root folders config's collectionOverrides: - a tenant field, and a selected-tenant base filter by tenant ID, which Payload's folder joins can query (they cannot query tenant.slug) - folder access on Media permissions, narrowed to the selected tenant so the REST API cannot list or edit another center's folders - validateFolderTenant on folders and Media, refusing a folder, parent folder or tenant change that would mix tenants; keepFolderTenant keeps a folder's tenant fixed - folders deleted with their tenant, seeded as a Brand folder per center, and left out of the MCP server ADR 026 records the design. Fixes #307 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Payload's bulk edit skips only fields with a top-level `hidden`, not `admin.hidden`, so Media offered Content Hash, Blur Data Url, Prefix and the storage plugin's _objectKey. Changing Prefix or _objectKey in bulk would break file URLs. A last-run plugin sets `admin.disableBulkEdit` on every field hidden from the admin, including those other plugins add. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Folder cards show only a name, so with no center selected every center's same-named folders looked identical. Folders now match nothing until a center is selected. The cross-collection Browse by Folder view and its nav button are off, since Media is the only folder-enabled collection. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Hiding folders until a center was selected left By Folder empty, which Payload gives no way to explain or hide. Revert to listing every center's folders. Add Folder to Media's default columns so the Choose-from-existing picker, which has no folder browsing, shows each item's folder. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The snapshot predated main's station-columns migration, so the next migrate:create would have re-emitted it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Payload's Folder list column (FolderTableCellClient in @payloadcms/ui) fetched each row's folder in its own request, and rows with no folder fetched the whole folder list. On the preview a 10-row Media page sent 10 extra requests at about 1.7s each. The cell also kept the first folder name it loaded, so after a bulk Edit → Folder → Save the column showed the old folder until a full reload. The patch loads every row's folder through the list's batched relationship loader (one request per page), skips the request for rows with no folder, and derives the shown folder from the row data, keeping a local value only for a move made from the cell itself. The code is unchanged in Payload 3.91.0, so delete the patch and its test once a Payload release includes the fix. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main landed 20261027_230050_add_provider_curriculum, so the folders migration moves to 20261028_180035 and its snapshot carries the providers curriculum tables. migrate:create --skip-empty generates nothing. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
50f4fc0 to
97ab816
Compare
rchlfryn
left a comment
There was a problem hiding this comment.
LG - bummer about not being able to expose the tenant name on the By Folder view. Claude suggested adding the tenant to the title but I don't think its worth it since only super admins see this view. And there is a fix with using the tenant dropdown. Hopefully Payload fixes this 🤷🏼♀️
|
|
||
| ## Conclusion | ||
|
|
||
| Additive only. Existing media keep `folder_id` null, which Payload shows at the root of the folder view. The `migrate:check` warnings are the `ON DELETE` clauses and the two `ALTER TABLE ... ADD` statements, which drop nothing. `migrate:create` omits `ON DELETE` on `ALTER ... REFERENCES`, so it was added by hand (`set null` on `media.folder_id`, `cascade` on the locked-documents rel) to match the schema push mode creates. |
There was a problem hiding this comment.
This says exsisting media shows “at the root of the folder view”. The PR description says it appears under All Media, not at the root of By Folder. Could this line say that? Worth getting right here, since this file is what we read later.
| + const populatedName = !moved && folderValue && typeof folderValue === 'object' ? folderValue.name : undefined; | ||
| + const loadedFolder = fromFolderID ? documents?.[folderCollectionSlug]?.[fromFolderID] : undefined; | ||
| + useEffect(() => { | ||
| + if (moved || !fromFolderID || populatedName || loadedFolder !== undefined || typeof getRelationships !== 'function') { |
There was a problem hiding this comment.
If this cell ever renders outside a RelationshipProvider, getRelationships is undefined. This early return then skips the request, and the name falls through to Loading... (line 67) with nothing left to resolve it. The list view and join tables provide the loader today. But folders are beta, and this is a patched copy that’ll be easy to forget. Could we fall back to the old single-folder fetch, or at least to folder:noFolder, when there’s no loader?
| * Returns the ID of the tenant selected by the 'payload-tenant' cookie, or null when no tenant is | ||
| * selected or the slug has no tenant document. | ||
| */ | ||
| export async function getTenantIDFromCookie(req: PayloadRequest): Promise<number | null> { |
There was a problem hiding this comment.
Claude comment I am unsure about using caching here:
Each call here queries the tenants table, and it now runs on every folder read/update/delete access check plus Media’s baseListFilter. Payload works out permissions on every admin page load, and since the DB is remote libSQL, each lookup is a round trip. You mentioned folder pages are already the slow ones.
Could we cache it on the request? Payload passes the same req to all of a request’s access checks, and the cookie can’t change mid-request. Since getAccessResults runs collections in parallel, cache the promise so concurrent checks share one query:
req.context.selectedTenantID ??= lookUpTenantID(req, tenantSlug)
return req.context.selectedTenantID as Promise<number | null>
tenantField’s beforeChange does the same slug→ID lookup and could use this too.
Description
Editors can organize Media into folders in the admin (the SAC use case in #307:
Bios/,Blog Images/), and each avalanche center sees and uses only its own folders.Payload generates a single
payload-folderscollection with no tenant field, readable and writable by any logged-in user. This PR makes it tenant-scoped through the rootfoldersconfig'scollectionOverrides. ADR 023 explains each piece. Payload marks folders beta, so re-check folder browsing after Payload upgrades.This replaces #1147 (Add tenant-scoped folder organization to Media), which was far behind
mainand scoped only the folder list views.Payload patch: Folder column
Payload's Folder list column (
FolderTableCellClientin@payloadcms/ui) had two problems that showed up on the preview:patches/@[email protected]rewrites that one file. It loads every row's folder in one batched request (the loader relationship columns already use), skips the request for rows with no folder, and shows the row's current folder after a refresh.__tests__/client/patches/folderTableCell.client.test.tsxcovers all three.This follows the same pattern as #1253 — Patch Payload to parse multipart saves that arrive without Content-Length: report it upstream, open the fix as a PR against Payload's
3.xbranch, and delete the patch and its test once a Payload release includes it.Folder pages are still slower than other admin pages on the preview (about 2.2s against 1.1–1.6s). Most of every admin page's time is Payload reloading the logged-in user about five times per request, which this PR doesn't change.
Related Issues
Fixes #307
Supersedes #1147
Key Changes
src/collections/Folders/): tenant field, selected-tenant base filter, and access on Media permissions narrowed to the selected tenant. Without the narrowing, a SAC admin could list, rename and delete NWAC's folders over REST.validateFolderTenant(on folders and Media) refuses filing media in, or nesting a folder under, another center's folder, and moving filed media to another center.keepFolderTenantkeeps a folder's tenant fixed.browseByFolderis off, which removes the nav button (it also showed on the dashboard) and the cross-collection/admin/browse-by-folderview. Media is the only folder-enabled collection, so Media → By Folder covers it. Turn it back on if Documents gets folders.filterByTenantID: inside a folder, Payload loads contents through a join that can't querytenant.slug, so opening any folder threwQueryError. Media and folders now filter by tenant ID.src/plugins/disableBulkEditOfHiddenFields.ts): bulk edit offered Content Hash, Blur Data Url, Prefix and_objectKey, and bulk-changing Prefix or_objectKeywould break file URLs. Fields hidden from the admin are now excluded everywhere, so Media's bulk edit offers Avalanche Center, Alt and Folder.stationPages,galleriesandform-submissions, which were missing, so deleting any tenant failed onmain.patches/@[email protected], registered inpackage.json/pnpm-lock.yaml): one batched folder lookup per page instead of one per row, and the column follows bulk edits. See Payload patch: Folder column.add_media_foldersmigration.How to test
rm -f dev.db*,pnpm seed, and log in as[email protected]/localpass.[email protected]with NWAC selected, only NWAC's folders show in Media → By Folder. The nav has no Browse by Folder button, and/admin/browse-by-folderreturns 404./api/payload-folderslists only SAC folders,PATCH/DELETEon an NWAC folder returns 403, andPATCH /api/media/<id>with an NWACfolderreturns 400.pnpm test(2407 passing, including newfolders,folderAccess,disableBulkEditOfHiddenFieldsandfolderTableCellsuites),tsc,lint,fallow:auditanddrift:checkpass. A Local API script on a seeded copy also confirmed every cross-tenant write is refused and deleting a tenant removes its folders cleanly.Screenshots / Demo video
Demo: https://www.loom.com/share/e7193d714db84bc2b7f2283fea5ba2c2
Each center sees only its own folders
Filing a media item
Bulk filing with Edit → Folder
Migration Explanation
20261019_180035_add_media_foldersis additive: it createspayload_foldersandpayload_folders_folder_type, and adds a nullablefolder_idtomedia(plus a rel column onpayload_locked_documents_rels). Existing media keeps working everywhere and starts unfiled; it appears under All Media, not at the root of By Folder.migrate:createdropsON DELETEfromALTER ... REFERENCES, so it was added by hand to match push mode.down()thenup()on a seeded copy kept every media row. Themigrate:checkwarnings are only thoseON DELETEclauses and the twoADDstatements. Details are in the_explanation.md.Future enhancements / Questions
byTenantRolereturnstruefor the selected tenant, so a SAC admin can list other centers' redirects over REST, and REST creates accept an explicit foreigntenant. Fixed for folders only; the general fix deserves its own issue.folders: true,filterByTenantID,validateFolderTenant).🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.