I have a module that I created. Recently I made a new version of it. The new version of the module has a new variable in it's config file. When the new version is installed from scratch - everything works fine. But if there is a previous version present (that doesn't have a new variable in it's config) and it is then updated with a new one, it appears that the config file in /files/config_[hash]/active is left from the older version. As a result the new version doesn't find the needed variable that it tries to read from older config and that causes errors. I wonder how can I ensure that when user updates my module, the existing module's config file adds new variables provided by a new version?
I guess I could add some code to hook_install in module.install file that would check and add new variables to existing config file. But I wonder if there is some automated method that would compare config file from previous version and the one provided by a new version of module and merge them together?
There's no automated way to do this (AFAIK) so what you'd do is implement hook_update_N() and add the new value there (using config_set()).