Skip to content

test: cover upload file versioning - #18547

Closed
nathanlentz wants to merge 25 commits into
mainfrom
feat/file-versioning-tests
Closed

nathanlentz wants to merge 25 commits into
mainfrom
feat/file-versioning-tests

Conversation

@nathanlentz

@nathanlentz nathanlentz commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

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?

  • Adds integration coverage for retained originals, derived variants, historical files, cleanup, drafts, and restore.
  • Covers local storage and first-party cloud storage adapter behavior.
  • Covers Local API, REST, and GraphQL file rename behavior.
  • Adds focused provider copy and client upload regression coverage.
  • Documents file versioning behavior and adapter migration requirements.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖

Meta File Out File Size (raw) Note
packages/next/meta_index.json esbuild/index.js 242.21 KB ⚠️ +27.44 KB (+12.8%)
packages/payload/meta_index.json esbuild/index.js 1.91 MB ⚠️ +117.74 KB (+6.6%)
packages/payload/meta_shared.json esbuild/exports/shared.js 564.12 KB ⚠️ +14.81 KB (+2.7%)
packages/richtext-lexical/meta_client.json esbuild/exports/client_optimized/index.js 296.20 KB ⚠️ +9.70 KB (+3.4%)
packages/ui/meta_client.json esbuild/exports/client_optimized/index.js 1.31 MB ‼️ +1.28 MB (+3497.0%)
packages/ui/meta_shared.json esbuild/exports/shared_optimized/index.js 18.98 KB ⚠️ +34 B (+0.2%)
Largest paths These visualization shows top 20 largest paths in the bundle.

Meta file: packages/next/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████████████████▋ }}}$ 98.9%, 237.09 KB
dist/adapters/router.js ${{\color{Goldenrod}{ }}}$ 0.3%, 718 B
dist/adapters/server.js ${{\color{Goldenrod}{ }}}$ 0.2%, 533 B
dist/adapters/layout.js ${{\color{Goldenrod}{ }}}$ 0.2%, 529 B
dist/adapters/views.js ${{\color{Goldenrod}{ }}}$ 0.1%, 324 B
dist/utilities/initAdminContext.js ${{\color{Goldenrod}{ }}}$ 0.1%, 315 B
dist/utilities/selectiveCache.js ${{\color{Goldenrod}{ }}}$ 0.1%, 263 B
dist/esbuildEntry.js ${{\color{Goldenrod}{ }}}$ 0.0%, 0 B

Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ █████████████████▋ }}}$ 70.7%, 1.34 MB
dist/collections/operations ${{\color{Goldenrod}{ ▊ }}}$ 3.1%, 58.19 KB
dist/fields/hooks ${{\color{Goldenrod}{ ▌ }}}$ 2.4%, 46.18 KB
dist/globals/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 18.19 KB
dist/auth/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 16.99 KB
dist/utilities/configToJSONSchema.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 16.02 KB
dist/queues/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 14.31 KB
dist/fields/config ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 13.71 KB
dist/utilities/telemetry ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 11.90 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 11.79 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 10.29 KB
dist/cli/commands ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 9.92 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 8.76 KB
dist/uploads/fetchAPI-multipart ${{\color{Goldenrod}{ }}}$ 0.4%, 8.38 KB
dist/database/migrations ${{\color{Goldenrod}{ }}}$ 0.4%, 8.16 KB
dist/config/sanitize.js ${{\color{Goldenrod}{ }}}$ 0.4%, 8.16 KB
dist/hierarchy/utils ${{\color{Goldenrod}{ }}}$ 0.4%, 7.66 KB
dist/index.js ${{\color{Goldenrod}{ }}}$ 0.4%, 7.60 KB
dist/auth/strategies ${{\color{Goldenrod}{ }}}$ 0.4%, 7.46 KB
dist/utilities/entityInputSchema ${{\color{Goldenrod}{ }}}$ 0.4%, 7.39 KB
(other) ${{\color{Goldenrod}{ ███████▎ }}}$ 29.3%, 555.01 KB

Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ██████████████████████▏ }}}$ 88.7%, 495.80 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 10.26 KB
dist/fields/config ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 5.83 KB
dist/utilities/traverseFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 4.34 KB
dist/utilities/deepCopyObject.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 3.52 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 3.42 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 3.13 KB
dist/fields/baseFields ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 2.79 KB
dist/config/client.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 2.58 KB
dist/auth/cookies.js ${{\color{Goldenrod}{ }}}$ 0.3%, 1.55 KB
dist/utilities/flattenTopLevelFields.js ${{\color{Goldenrod}{ }}}$ 0.3%, 1.42 KB
dist/utilities/getVersionsConfig.js ${{\color{Goldenrod}{ }}}$ 0.2%, 1.04 KB
dist/globals/config ${{\color{Goldenrod}{ }}}$ 0.2%, 957 B
dist/uploads/generatePayloadFileURL.js ${{\color{Goldenrod}{ }}}$ 0.2%, 864 B
dist/utilities/unflatten.js ${{\color{Goldenrod}{ }}}$ 0.2%, 850 B
dist/utilities/flattenAllFields.js ${{\color{Goldenrod}{ }}}$ 0.1%, 798 B
dist/errors/ValidationError.js ${{\color{Goldenrod}{ }}}$ 0.1%, 773 B
dist/utilities/sanitizeUserDataForEmail.js ${{\color{Goldenrod}{ }}}$ 0.1%, 713 B
dist/auth/extractJWT.js ${{\color{Goldenrod}{ }}}$ 0.1%, 696 B
dist/utilities/getFieldPermissions.js ${{\color{Goldenrod}{ }}}$ 0.1%, 681 B
(other) ${{\color{Goldenrod}{ ██▊ }}}$ 11.3%, 63.37 KB

Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
dist/features/blocks ${{\color{Goldenrod}{ ███▋ }}}$ 14.6%, 42.78 KB
dist/lexical/plugins ${{\color{Goldenrod}{ ██▉ }}}$ 11.8%, 34.51 KB
dist/lexical/ui ${{\color{Goldenrod}{ ██▊ }}}$ 11.4%, 33.54 KB
dist/features/table ${{\color{Goldenrod}{ ██▎ }}}$ 9.4%, 27.46 KB
dist/features/link ${{\color{Goldenrod}{ █▋ }}}$ 6.5%, 18.92 KB
dist/features/toolbars ${{\color{Goldenrod}{ █▌ }}}$ 6.3%, 18.41 KB
dist/features/upload ${{\color{Goldenrod}{ █▏ }}}$ 4.9%, 14.28 KB
dist/features/textState ${{\color{Goldenrod}{ ▉ }}}$ 3.8%, 11.08 KB
dist/lexical/utils ${{\color{Goldenrod}{ ▊ }}}$ 3.4%, 10.02 KB
dist/features/relationship ${{\color{Goldenrod}{ ▊ }}}$ 3.2%, 9.43 KB
dist/features/converters ${{\color{Goldenrod}{ ▋ }}}$ 2.9%, 8.41 KB
dist/utilities/fieldsDrawer ${{\color{Goldenrod}{ ▋ }}}$ 2.8%, 8.12 KB
dist/features/debug ${{\color{Goldenrod}{ ▋ }}}$ 2.5%, 7.40 KB
dist/lexical/config ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 5.14 KB
dist/features/indent ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 4.19 KB
dist/features/lists ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 3.67 KB
dist/lexical/LexicalEditor.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.33 KB
dist/features/format ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.28 KB
dist/features/horizontalRule ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 3.18 KB
dist/field/Field.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 3.06 KB
(other) ${{\color{Goldenrod}{ █████████████████████▎ }}}$ 85.4%, 250.21 KB

Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ███████▎ }}}$ 29.4%, 382.61 KB
dist/elements/Hierarchy ${{\color{Goldenrod}{ ▉ }}}$ 3.8%, 49.37 KB
dist/elements/BulkUpload ${{\color{Goldenrod}{ ▌ }}}$ 2.3%, 30.54 KB
dist/elements/Table ${{\color{Goldenrod}{ ▌ }}}$ 2.2%, 28.85 KB
dist/views/Version ${{\color{Goldenrod}{ ▌ }}}$ 2.1%, 27.83 KB
dist/views/Edit ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 22.15 KB
dist/views/HierarchyList ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 21.51 KB
dist/views/Dashboard ${{\color{Goldenrod}{ ▍ }}}$ 1.5%, 19.60 KB
dist/elements/WhereBuilder ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 17.66 KB
dist/providers/Auth ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 17.38 KB
dist/fields/Relationship ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 16.23 KB
dist/forms/Form ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 16.02 KB
dist/fields/Upload ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 14.94 KB
dist/fields/Blocks ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 14.91 KB
dist/elements/Popup ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 13.33 KB
dist/views/List ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 13.22 KB
dist/elements/ReactSelect ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 12.99 KB
dist/elements/QueryPresets ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.82 KB
dist/elements/FileManager ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.39 KB
dist/widgets/RecentlyViewed ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 10.02 KB
(other) ${{\color{Goldenrod}{ █████████████████▋ }}}$ 70.6%, 919.51 KB

Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js

Path Size
dist/graphics/Logo ${{\color{Goldenrod}{ ███████▋ }}}$ 30.7%, 5.61 KB
../../node_modules ${{\color{Goldenrod}{ ███▌ }}}$ 14.5%, 2.65 KB
dist/graphics/Icon ${{\color{Goldenrod}{ ██ }}}$ 8.3%, 1.51 KB
dist/utilities/formatDocTitle ${{\color{Goldenrod}{ █▊ }}}$ 7.2%, 1.32 KB
dist/providers/TableColumns ${{\color{Goldenrod}{ █▏ }}}$ 4.7%, 866 B
dist/utilities/getGlobalData.js ${{\color{Goldenrod}{ █ }}}$ 4.2%, 762 B
dist/utilities/api.js ${{\color{Goldenrod}{ █ }}}$ 4.1%, 756 B
dist/utilities/groupNavItems.js ${{\color{Goldenrod}{ █ }}}$ 4.1%, 745 B
dist/elements/Translation ${{\color{Goldenrod}{ ▋ }}}$ 2.7%, 493 B
dist/utilities/handleTakeOver.js ${{\color{Goldenrod}{ ▌ }}}$ 2.4%, 440 B
dist/utilities/traverseForLocalizedFields.js ${{\color{Goldenrod}{ ▌ }}}$ 2.3%, 419 B
dist/elements/withMergedProps ${{\color{Goldenrod}{ ▍ }}}$ 1.9%, 339 B
dist/utilities/getNavGroups.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 338 B
dist/utilities/getVisibleEntities.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 329 B
dist/elements/WithServerSideProps ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 232 B
dist/layouts/Root ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 230 B
dist/utilities/handleGoBack.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 180 B
dist/fields/mergeFieldStyles.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 158 B
dist/forms/Form ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 152 B
dist/utilities/handleBackToDashboard.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 152 B
(other) ${{\color{Goldenrod}{ █████████████████▎ }}}$ 69.3%, 12.68 KB
Details

Next to the size is how much the size has increased or decreased compared with the base branch of this PR.

  • ‼️: Size increased by 20% or more. Special attention should be given to this.
  • ⚠️: Size increased in acceptable range (lower than 20%).
  • ✅: No change or even downsized.
  • 🗑️: The out file is deleted: not found in base branch.
  • 🆕: The out file is newly found: will be added to base branch.

@nathanlentz
nathanlentz added this pull request to stack #18549 October 6, 2026 16:33
Comment thread docs/database/migrations.mdx Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary as information here? Migration guide should be enough

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I removed it and ensured it was covered in the migration guide.

Comment thread docs/migration-guide/v4.mdx Outdated

#### 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be reworded to be shorter

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. It hath been shortened.

Comment thread docs/upload/overview.mdx Resolved
Comment thread docs/upload/storage-adapters.mdx Resolved
@@ -0,0 +1,83 @@
import { Readable } from 'node:stream'
import { expect, it, vi } from 'vitest'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These spec files can go I think, we can rely on int tests here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all five adapter copy specs

@nathanlentz
nathanlentz removed this pull request from stack #18549 October 7, 2026 18:25
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.
@nathanlentz

Copy link
Copy Markdown
Collaborator Author

Merged as part of #18548

@nathanlentz nathanlentz closed this Oct 7, 2026
@nathanlentz
nathanlentz deleted the feat/file-versioning-tests branch October 7, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants