Adds an admin button to toggle the database connection between production and development, or to copy the production database into a development one. Configured through the plugin array, it must come last, after a cloud storage plugin. Copied upload documents keep pointing at production cloud files, which are protected from edits. Requires Payload 3.0.2 or later, MongoDB and cloud storage for production uploads; migrations are not supported.
Payload plugin to switch environments
Installation
npm i @elliott-w/payload-plugin-switch-env5
Stars
1
Forks
0
Open Issues
4 months ago
Last Updated
84
Weekly Downloads
v2.0.3
npm Version
235.8 KB
Unpacked Size
0
Dependencies
50 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 5 |
| Dec 4, 2026 | 5 |
| Dec 3, 2026 | 5 |
| Dec 2, 2026 | 5 |
| Dec 1, 2026 | 5 |
| Nov 30, 2026 | 5 |
| Nov 29, 2026 | 5 |
| Nov 28, 2026 | 5 |
| Nov 27, 2026 | 5 |
| Nov 26, 2026 | 5 |
| Nov 25, 2026 | 5 |
| Nov 24, 2026 | 5 |
| Nov 23, 2026 | 5 |
| Nov 22, 2026 | 5 |
| Nov 21, 2026 | 5 |
| Nov 20, 2026 | 5 |
| Nov 19, 2026 | 5 |
| Nov 18, 2026 | 5 |
| Nov 17, 2026 | 5 |
| Nov 16, 2026 | 5 |
| Nov 15, 2026 | 5 |
| Nov 14, 2026 | 5 |
| Nov 13, 2026 | 5 |
| Nov 12, 2026 | 5 |
| Nov 11, 2026 | 5 |
| Nov 10, 2026 | 5 |
| Nov 9, 2026 | 5 |
| Nov 8, 2026 | 5 |
| Nov 7, 2026 | 5 |
| Nov 6, 2026 | 5 |
| Nov 5, 2026 | 5 |
| Nov 4, 2026 | 5 |
| Nov 3, 2026 | 5 |
| Nov 2, 2026 | 5 |
| Nov 1, 2026 | 5 |
| Oct 31, 2026 | 5 |
| Oct 30, 2026 | 5 |
| Oct 29, 2026 | 5 |
| Oct 28, 2026 | 5 |
| Oct 27, 2026 | 5 |
| Oct 26, 2026 | 5 |
| Oct 25, 2026 | 5 |
| Oct 24, 2026 | 5 |
| Oct 23, 2026 | 5 |
| Oct 22, 2026 | 5 |
| Oct 21, 2026 | 5 |
| Oct 20, 2026 | 5 |
| Oct 19, 2026 | 5 |
| Oct 18, 2026 | 5 |
| Oct 17, 2026 | 5 |
| Oct 16, 2026 | 5 |
| Oct 15, 2026 | 5 |
| Oct 14, 2026 | 5 |
| Oct 13, 2026 | 5 |
| Oct 12, 2026 | 5 |
| Oct 11, 2026 | 5 |
| Oct 10, 2026 | 5 |
| Oct 9, 2026 | 5 |
| Oct 8, 2026 | 5 |
| Oct 7, 2026 | 5 |
| Oct 6, 2026 | 5 |
| Oct 5, 2026 | 5 |
| Oct 4, 2026 | 5 |
| Oct 3, 2026 | 5 |
| Oct 2, 2026 | 5 |
| Oct 1, 2026 | 5 |
| Sep 30, 2026 | 5 |
| Sep 29, 2026 | 5 |
| Sep 28, 2026 | 5 |
| Sep 27, 2026 | 5 |
| Sep 26, 2026 | 5 |
| Sep 25, 2026 | 5 |
| Sep 24, 2026 | 5 |
| Sep 23, 2026 | 5 |
| Sep 22, 2026 | 5 |
| Sep 21, 2026 | 5 |
| Sep 20, 2026 | 5 |
| Sep 19, 2026 | 5 |
| Sep 18, 2026 | 5 |
| Sep 17, 2026 | 5 |
| Sep 16, 2026 | 5 |
| Sep 15, 2026 | 5 |
| Sep 14, 2026 | 5 |
| Sep 13, 2026 | 5 |
| Sep 12, 2026 | 5 |
| Sep 11, 2026 | 5 |
| Sep 10, 2026 | 5 |
| Sep 9, 2026 | 5 |
| Sep 8, 2026 | 5 |
| Sep 7, 2026 | 5 |
| Sep 6, 2026 | 5 |
30+5 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 30 |
| Dec 4, 2026 | 32 |
| Dec 3, 2026 | 32 |
| Dec 2, 2026 | 32 |
| Dec 1, 2026 | 36 |
| Nov 30, 2026 | 37 |
| Nov 29, 2026 | 37 |
| Nov 28, 2026 | 36 |
| Nov 27, 2026 | 38 |
| Nov 26, 2026 | 37 |
| Nov 25, 2026 | 91 |
| Nov 24, 2026 | 87 |
| Nov 23, 2026 | 115 |
| Nov 22, 2026 | 117 |
| Nov 21, 2026 | 117 |
| Nov 20, 2026 | 113 |
| Nov 19, 2026 | 113 |
| Nov 18, 2026 | 85 |
| Nov 17, 2026 | 57 |
| Nov 16, 2026 | 28 |
| Nov 15, 2026 | 26 |
| Nov 14, 2026 | 26 |
| Nov 13, 2026 | 29 |
| Nov 12, 2026 | 32 |
| Nov 11, 2026 | 6 |
| Nov 10, 2026 | 33 |
| Nov 9, 2026 | 34 |
| Nov 8, 2026 | 34 |
| Nov 7, 2026 | 45 |
| Nov 6, 2026 | 42 |
| Nov 5, 2026 | 40 |
| Nov 4, 2026 | 40 |
| Nov 3, 2026 | 15 |
| Nov 2, 2026 | 14 |
| Nov 1, 2026 | 17 |
| Oct 31, 2026 | 6 |
| Oct 30, 2026 | 6 |
| Oct 29, 2026 | 5 |
| Oct 28, 2026 | 5 |
| Oct 27, 2026 | 3 |
| Oct 26, 2026 | 3 |
| Oct 25, 2026 | 1 |
| Oct 24, 2026 | 2 |
| Oct 23, 2026 | 2 |
| Oct 22, 2026 | 6 |
| Oct 21, 2026 | 6 |
| Oct 20, 2026 | 6 |
| Oct 19, 2026 | 6 |
| Oct 18, 2026 | 5 |
| Oct 17, 2026 | 4 |
| Oct 16, 2026 | 5 |
| Oct 15, 2026 | 1 |
| Oct 14, 2026 | 1 |
| Oct 13, 2026 | 1 |
| Oct 12, 2026 | 1 |
| Oct 11, 2026 | 2 |
| Oct 10, 2026 | 4 |
| Oct 9, 2026 | 3 |
| Oct 8, 2026 | 6 |
| Oct 7, 2026 | 11 |
| Oct 6, 2026 | 11 |
| Oct 5, 2026 | 13 |
| Oct 4, 2026 | 14 |
| Oct 3, 2026 | 16 |
| Oct 2, 2026 | 16 |
| Oct 1, 2026 | 17 |
| Sep 30, 2026 | 17 |
| Sep 29, 2026 | 17 |
| Sep 28, 2026 | 15 |
| Sep 27, 2026 | 40 |
| Sep 26, 2026 | 43 |
| Sep 25, 2026 | 43 |
| Sep 24, 2026 | 39 |
| Sep 23, 2026 | 34 |
| Sep 22, 2026 | 35 |
| Sep 21, 2026 | 72 |
| Sep 20, 2026 | 45 |
| Sep 19, 2026 | 38 |
| Sep 18, 2026 | 38 |
| Sep 17, 2026 | 38 |
| Sep 16, 2026 | 39 |
| Sep 15, 2026 | 39 |
| Sep 14, 2026 | 2 |
| Sep 13, 2026 | 3 |
| Sep 12, 2026 | 10 |
| Sep 11, 2026 | 11 |
| Sep 10, 2026 | 12 |
| Sep 9, 2026 | 14 |
| Sep 8, 2026 | 25 |
| Sep 7, 2026 | 26 |
| Sep 6, 2026 | 25 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/885749499-root)<a href="https://payloaddirectory.dev/plugins/885749499-root"><img src="https://payloaddirectory.dev/badge/885749499-root.svg" alt="Payload Directory"></a>README
⚠️ This plugin has moved location to: https://github.com/what-works-global/payload-packages/tree/main/packages/switch-env
pnpm i @elliott-w/payload-plugin-switch-env
⚠️ Warning: The switchEnv plugin must come last in the plugins array. Your cloud storage plugin must be second last.
// payload.config.ts
import { type Args, mongooseAdapter } from '@payloadcms/db-mongodb'
import { buildConfig } from 'payload'
import { switchEnvPlugin, adminThumbnail } from '@elliott-w/payload-plugin-switch-env'
import { s3Storage } from '@payloadcms/storage-s3'
const dbArgs: Args = {
url: process.env.DATABASE_URI!,
}
export default buildConfig({
db: mongooseAdapter(dbArgs),
plugins: [
// Your cloud storage plugin must come second last in the plugins array
s3Storage({
bucket: process.env.S3_BUCKET!,
collections: {
media: true,
},
config: {
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY_ID!,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY!,
},
region: process.env.S3_REGION,
},
}),
// The switchEnvPlugin must come last in the plugins array
switchEnvPlugin({
payloadVersion: '3.70.0',
enable: process.env.NODE_ENV === 'development',
db: {
function: mongooseAdapter,
productionArgs: dbArgs,
developmentArgs: {
...dbArgs,
url: process.env.DEVELOPMENT_DATABASE_URI || '',
},
},
copy: {
versions: {
default: { mode: 'latest-x', x: 3 },
},
},
}),
],
collections: [
{
slug: 'media',
fields: [
{
name: 'alt',
type: 'text',
},
],
upload: {
// Helper function if you want admin thumbnails to link directly to cloud storage
adminThumbnail: adminThumbnail({
basePath: `https://${process.env.S3_BUCKET}.s3.${process.env.S3_REGION}.amazonaws.com`,
imageSize: 'thumbnail',
}),
imageSizes: [
{
name: 'thumbnail',
width: 300,
height: 300,
},
],
},
},
],
})
db (required): Database adapter function + production/development args.payloadVersion (required): Installed Payload version string (for hook compatibility), e.g. '3.70.0'.buttonMode (default: 'switch'):
'switch': toggle between production and development.'copy': show a dedicated button to copy production DB to development DB. Useful for staging environments.enable (default: true): Enable/disable plugin behavior.quickSwitch (default: false): Skip the switch modal and switch immediately in 'switch' mode.logDatabaseSize (default: false): Logs serialized backup size when copying DB.developmentSafetyMode (default: true): Throws if developmentArgs.url is not localhost/127.0.0.1 during development.developmentFileStorage:
{ mode: 'file-system' } (default){ mode: 'cloud-storage', prefix, collections }copy: Allows you to copy only a subset of documents to your development database. See type hints for more information.Does not support database migrations.
Only works with:
Notes:
developmentFileStorage.
You're working with a production database that is getting frequently updated and you want to push a feature that requires code + database changes.
Quickly clone the database to your local machine, make the data changes and then overwrite the production database with your local database.
Pros
Cons
Make the code (i.e. field structure) changes on your local machine then use this plugin to switch the database connection to your production database to make data/content updates.
Pros:
Cons:
You want to replicate the production environment to your development environment as quickly and simply as possible.
Do a manual database dump and restore on your local machine. Make a copy of all the upload collection files on your local machine or in the cloud somehow.
Pros
Cons
Use this plugin to quickly copy your production database to local, with all the upload collection documents still referencing the files in your production cloud storage
Pros
Cons
switch env
Switch the admin panel between development and production databases and copy production into development
68239/wk16v3
payload upstash
Upstash Redis key-value adapter for Payload's built-in KV store
82333/wk7v3 v4
payload typeid
TypeID identifiers for Payload collections, as native IDs or an extra type_id field, with PostgreSQL integrity guards
802.6k/wk0v3
payload kv
Store counters, feeds and expiring data in Redis or KV stores while querying them as normal Payload fields
771.4k/wk0v3 v4
payload surrealdb
SurrealDB database adapter for Payload CMS v3 and v4 using its PostgreSQL-compatible SQL interface
77268/wk3v3 v4
payload plugin backup postgres
Scheduled and on-demand PostgreSQL backups with selective restore, stored in Vercel Blob or S3-compatible storage
72118/wk3v3