Working Locally

Testing production data

Being able to pull down current production data and test against that can be helpful at times to better track down bugs without having to either mess around in the production environment (no-no) or meticulously trying to re-create a page from production on your local machine. For this we can instead pull down the latest production backup and import that.

php artisan backup:restore

What the restore will do for you

  • Ask you if you want to back up your current databases.

  • Find and download the latest production database file from the remote location.

  • Extract the file if compressed.

  • Replace your current tenant databases with the production ones.

  • Replace any production URLs with you local domain as the base URL.

  • Reset any app settings from production. More about this in the Reset settings section.

  • Attempt to sync up your Shopify product IDs to match the store defined in the Shopify app settings.

    • Example, the backup has production product IDs in the database, but we want to use the test Shopify store in our local environment, so we can test checkout and other various functionality, and, you know, not mess with production data... So we update the Shopify URL to point to our test store URL, but now the Shopify product IDs (shopify_id) no longer match up. Syncing go through all the products in the database and see if it can find the same product (by looking for the same name) in the Shopify store (test store in our case) and if it finds a match it will simply update the shopify_id to the matched one from the remote Shopify store.

You should now have a near complete copy of production on your local machine.

Resetting settings

Settings from production can be tricky to get right. Sometimes we want the same settings for an app as in production, i.e. Discounts thresholds and settings, there's no harm in keeping those from production, other times we absolutely do not want that, i.e. Zaius or Heap public and private keys, we do absolutely not want to bring those back with us to local as it would completely screw with the data that we sent to those services. So to be on the safe side, by default we disable and reset all app settings when we restore from backup. Which makes it a bit of a hassle to then go in and have to manually update the settings that you do want from production. The process can be automated by creating a settings .env file for each site with the values you want to either keep or overwrite.

Read more about how to reset/sync settings from a .env file.

Any encrypted settings will not be kept even though you have specified the app to keep settings. The reason for this is that the decryption will fail if we leave the encrypted values in the settings as the APP_KEY which is used to decrypt the values is different from the one in production used to encrypt the value.

Was this helpful?