How to safely change the user's config file?

Viewed 90

How to deal with a situation when I need to change config file structure?
For example, let's say I want to change it from this

{
  "device_address": "127.0.0.1:5001"
}

to this

{
  "device": {
    "ip": "127.0.0.1",
    "port": 5001
  }
}

If I'll do so, the new program release will fail to read it, which will cause the configuration will be lost, which is bad :(
But I can't stack with the same config structure forever - project is changing, requirements are changing...
Does anyone know any best practices for this issue?

1 Answers

I don't know if this qualifies as a "best practice", but one way is to do this migration in several steps:

  1. First update the application's code so it can read either the old or new layout of the configuration file .
  2. Ensure this new version of the application is deployed everywhere.
  3. Finally, deploy the new configuration file.
Related