#Is it possible to change the db object on the fly?

3 messages · Page 1 of 1 (latest)

magic elm
#

I'm trying to create a button in the admin interface which switches between a local and production database. Is there a way to change the db object in payload config at some point later after initialization?

frosty tokenBOT
magic elm
#

This seems to do the job:

// Delete cache of payload object
;(global as any)._payload.payload = null
;(global as any)._payload.promise = null
// Trigger Hot-Module-Replacement of payload config
// by updating the last accessed and last modified time of the file
// (this does not trigger a file change in git)
const time = new Date()
fs.utimesSync('payload.config.ts', time, time)