You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(storage-*): allow prefix to always exist as a field via alwaysInsertFields flag (#14949)
This PR adds a new top-level flag `alwaysInsertFields` in the storage
adapter plugin options to ensure the prefix field is always present in
the schema.
Some configurations have prefix dynamically set by environment, but this
can cause schema/db drift and issues where db migrations are needed, as
well as generated types being different between environments.
Now you can add `alwaysInsertFields: true` at the plugin level so that
the prefix field is always present regardless of what you set in
`prefix`, even when the plugin is disabled:
```
s3Storage({
alwaysInsertFields: true, // prefix field will always exist in schema
collections: {
'media': true,
'media-with-prefix': {
prefix: process.env.MEDIA_PREFIX, // can be undefined without causing schema drift
},
},
enabled: process.env.USE_S3 === 'true', // works even when disabled
// ...
})
```
This is particularly useful for:
- Multi-tenant setups where prefix is set dynamically
- Environments where cloud storage is conditionally enabled (e.g., local
dev vs production)
- Ensuring consistent database schema across all environments
**This will be enabled by default and removed as a flag in Payload v4.**
|`collections`\*|`Record<string, CollectionOptions>`| Object with keys set to the slug of collections you want to enable the plugin for, and values set to collection-specific options. |
374
-
|`enabled`|`boolean`| To conditionally enable/disable plugin. Default: `true`. |
|`alwaysInsertFields`|`boolean`| When enabled, fields (like the prefix field) will always be inserted into the collection schema regardless of whether the plugin is enabled. This will be enabled by default in Payload v4. Default: `false`. |
374
+
|`collections`\*|`Record<string, CollectionOptions>`| Object with keys set to the slug of collections you want to enable the plugin for, and values set to collection-specific options. |
375
+
|`enabled`|`boolean`| To conditionally enable/disable plugin. Default: `true`. |
375
376
376
377
## Collection-specific options
377
378
@@ -380,8 +381,8 @@ This plugin is configurable to work across many different Payload collections. A
380
381
|`adapter`\*|[Adapter](https://github.com/payloadcms/payload/blob/main/packages/plugin-cloud-storage/src/types.ts#L49)| Pass in the adapter that you'd like to use for this collection. You can also set this field to `null` for local development if you'd like to bypass cloud storage in certain scenarios and use local storage. |
381
382
|`disableLocalStorage`|`boolean`| Choose to disable local storage on this collection. Defaults to `true`. |
382
383
|`disablePayloadAccessControl`|`true`| Set to `true` to disable Payload's Access Control. [More](#payload-access-control)|
383
-
|`prefix`|`string`| Set to `media/images` to upload files inside `media/images` folder in the bucket. |
384
384
|`generateFileURL`|[GenerateFileURL](https://github.com/payloadcms/payload/blob/main/packages/plugin-cloud-storage/src/types.ts#L67)| Override the generated file URL with one that you create. |
385
+
|`prefix`|`string`| Set to `media/images` to upload files inside `media/images` folder in the bucket. |
0 commit comments