Pizzly uses uuidv4
to generate pseudo-random setupId, such as a3ef22ba-8916-424f-b613-9e8608026094
. In some cases, you might be interested in renaming the setupId to something more meaningful. Here's how to do it.
Assuming you can't run SQL queries on your production database, to rename a setupId
on your Pizzly instance (e.g. on Heroku), you'll have to create a new endpoint on Pizzly's API and request that endpoint each time you want to rename a setupId.
Here's how to do it:
-
Open your Pizzly repository (or clone the official repo)
-
Open the file under
src/routes/api.ts
-
After the test endpoint (around line 30), copy/paste the following code:
/** * Custom endpoint to rename a setupId */ api.put('/custom/rename-setup-id', async (req, res, next) => { const currentSetupId = req.body.current_setup_id const newSetupId = req.body.new_setup_id if (!currentSetupId || !newSetupId) { next(new Error("Can't rename setupId. Invalid params")) return } let affectedRows = 0 const startTime = Date.now() // Rename the configuration affectedRows += await store('configurations') .update({ setup_id: newSetupId }) .where({ setup_id: currentSetupId }) // Rename all authentications affectedRows += await store('authentications') .update({ setup_id: newSetupId }) .where({ setup_id: currentSetupId }) // Log result const endTime = Date.now() res.send(`Done in ${endTime - startTime}ms - ${affectedRows} rows affected.`) }) // Example: // // curl -X PUT "http://pizzly.example.org/api/custom/rename-setup-id" \ // -u "replace-with-your-secret-key:" \ // -H "Content-Type: application/json" \ // --data '{"current_setup_id": "foo", "new_setup_id": "bar"}'
-
Save then redeploy your code.
git add . && git commit -m "custom endpoint to rename a setupId"
To redeploy your Pizzly instance hosted on Heroku, use
git push heroku master
-
When you want to rename a setupId, make a cURL request to that custom endpoint:
curl -X PUT "http://pizzly.example.org/api/custom/rename-setup-id" \ -u "replace-with-your-secret-key:" \ -H "Content-Type: application/json" \ --data '{"current_setup_id": "", "new_setup_id": ""}'
💡 Remember to use your own secretKey before triggering that command.
On success, you will have something like this: Done in 16ms - 6 rows affected
.
To rename a setupId
on your own machine, or if you have access to your server using SSH, follow these steps:
-
Add a new file
pizzly-rename-setup-id.js
at the root of your Pizzly folder.touch pizzly-rename-setup-id.js
-
Copy/paste the following content in that new file:
const { store } = require('./dist/src/lib/database') const currentSetupId = process.env.CURRENT_SETUP_ID const newSetupId = process.env.NEW_SETUP_ID if (!currentSetupId || !newSetupId) { console.log( 'Initialize this script as follow:', '\n', '$ CURRENT_SETUP_ID="" NEW_SETUP_ID="" node pizzly-rename-setup-id.js' ) return process.exit(1) } ;(async () => { let affectedRows = 0 const startTime = Date.now() // Rename the configuration affectedRows += await store('configurations') .update({ setup_id: newSetupId }) .where({ setup_id: currentSetupId }) // Rename all authentications affectedRows += await store('authentications') .update({ setup_id: newSetupId }) .where({ setup_id: currentSetupId }) // Log result const endTime = Date.now() console.log(`Done in ${endTime - startTime}ms`, '-', `${affectedRows} rows affected.`) process.exit(1) })()
-
Run the script:
CURRENT_SETUP_ID="" NEW_SETUP_ID="" node pizzly-rename-setup-id.js
Got a question? Have a feedback, please open an issue on Pizzly repo.