Repository navigation
test: cover upload file versioning - #18547
Closed
nathanlentz wants to merge 25 commits into
Closed
nathanlentz wants to merge 25 commits into
nathanlentz wants to merge 25 commits into
Conversation
nathanlentz
requested review from
AlessioGr,
JarrodMFlesch,
denolfe and
jacobsfletch
as code owners
October 6, 2026 16:27
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
paulpopus
requested changes
Oct 7, 2026
| npm run payload migrate:create optional-name-here | ||
| ``` | ||
|
|
||
| When upgrading a SQL project to a Payload release that adds upload file versioning, generate a migration in that project after updating Payload and before deploying with `push: false`. Inspect the generated migration for each upload collection: it should add the `original` metadata and the per-file location fields defined by your upload and storage configuration to both the collection and its versions table, if versions are enabled. Each stored representation retains its own `filename`, `prefix`, and `_objectKey` so retained versions can locate their files. Then run `npm run payload migrate` during deployment. Payload does not ship a single migration for these fields because upload collection tables are defined by each project's config. Existing rows retain null values for newly added fields until a later write persists them; reads alone do not change stored rows. |
Member
There was a problem hiding this comment.
Is this necessary as information here? Migration guide should be enough
Collaborator
Author
There was a problem hiding this comment.
Sure, I removed it and ensured it was covered in the migration guide.
|
|
||
| #### If you maintain a custom storage adapter | ||
|
|
||
| File versioning adds a required `GeneratedAdapter.copyFile` method. It receives `collection`, `req`, complete `from` and `to` storage keys, and an optional `mimeType`. Implement it using the provider's copy operation or a safe authenticated stream: keep the source, reject an occupied destination, and wait until the destination is readable before returning. `moveFile` is optional. This is a 4.0 adapter contract change; custom adapters must implement the new method to support the updated interface. Path-addressed keys cannot be assumed for adapters whose provider assigns opaque object IDs. See [Custom Storage Adapters](../upload/storage-adapters) for the contract and first-party provider requirements. |
Member
There was a problem hiding this comment.
This can be reworded to be shorter
Collaborator
Author
There was a problem hiding this comment.
Sure thing. It hath been shortened.
| @@ -0,0 +1,83 @@ | |||
| import { Readable } from 'node:stream' | |||
| import { expect, it, vi } from 'vitest' | |||
|
|
|||
Member
There was a problem hiding this comment.
These spec files can go I think, we can rely on int tests here
Collaborator
Author
There was a problem hiding this comment.
Removed all five adapter copy specs
paulpopus
approved these changes
Oct 7, 2026
nathanlentz
added a commit
that referenced
this pull request
Oct 7, 2026
_Written by AI_ ## What? This is part 2 of the two-PR file versioning stack. It adds the Payload and storage adapter implementation for the behavior defined in #18547. Versioned upload documents now retain their original source and every stored representation needed by current or historical versions. Restore, pruning, replacement, rename, and deletion preserve referenced objects and remove objects after their final reference is removed. ## Why? Payload document versions previously retained upload metadata without managing the corresponding stored files. Historical versions could therefore reference replaced or deleted objects. ## How? - Stores location data with the current file, `original`, and each configured variant. - Stages storage writes before document writes and delays cleanup until the surrounding operation succeeds. - Archives outgoing local and cloud objects when versions retain them. - Restores stored files without replaying transformations. - Adds safe copy operations to first-party storage adapters. - Uses the retained original as the image editor source while keeping normal previews on the processed file. - Adds Local API, REST, and GraphQL support for file rename operations. ##⚠️ Breaking changes - Custom cloud storage adapters must implement the required `GeneratedAdapter.copyFile` operation. - New uploads retain their source using an `-original` filename. Code and infrastructure that depend on the previous filename, URL, or object key must account for the new location. - Upload collections gain stored `original`, `prefix`, and `_objectKey` fields. Relational database projects must generate and apply the corresponding schema migration. ## API Applications can rename an upload and its stored representations through `payload.renameFile`, the REST rename endpoint, or the generated GraphQL mutation. Existing upload create, update, delete, draft, and restore operations manage file history automatically.
Collaborator
Author
|
Merged as part of #18548 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
This is part 1 of the two-PR file versioning stack.
This PR defines the expected behavior for versioned upload files across local storage, cloud storage, drafts, restore, pruning, rename, and image editing. It also documents the new upload metadata and storage adapter requirements.
This branch intentionally contains no production implementation. Its checks will fail until the core PR is merged into this branch.
Why?
The separate test branch lets reviewers evaluate the required behavior without reading the implementation at the same time. It also gives the core PR a stable, behavior-focused specification.
How?