简体   繁体   中英

How to safely change the user's config file?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM