Skip to content

Conversation

@paulpopus
Copy link
Contributor

@paulpopus paulpopus commented Dec 16, 2025

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.

Copy link
Member

@denolfe denolfe left a comment

Choose a reason for hiding this comment

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

This is looking good. However, none of this code will get hit if enabled is being set to false. If we want this behind a flag, we should also handle pushing this field inside https://github.com/payloadcms/payload/blob/main/packages/plugin-cloud-storage/src/plugin.ts#L24-L27

@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2025

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖
This PR introduced no changes to the esbuild bundle! 🙌

@paulpopus paulpopus changed the title fix(storage-*): allow prefix to always exist as a field via prefixAlwaysOn flag fix(storage-*): allow prefix to always exist as a field via alwaysInsertFields flag Dec 16, 2025
@paulpopus paulpopus requested a review from denolfe December 16, 2025 20:42
@denolfe denolfe merged commit 23a8689 into main Jan 5, 2026
95 checks passed
@denolfe denolfe deleted the fix/always-add-the-prefix-field-in-database-adapters branch January 5, 2026 17:55
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

🚀 This is included in version v3.70.0

zubricks pushed a commit that referenced this pull request Jan 6, 2026
…ertFields 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.**
teastudiopl pushed a commit to teastudiopl/payload that referenced this pull request Jan 8, 2026
…ertFields flag (payloadcms#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.**
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.

3 participants