Migrate from old domain device to new domain with `config_flow.py`


I’m new to home assiant integration develop, also read some basic from our : Home Assistant Core | Home Assistant Developer Docs

and I want to develop a new integration , use HACS to install it now.
and try to migrate from an old domain user device/configs to my new domain name, as old domain not maintainer anymore, no any new feature and no any support now.
and i don’t want to use the old domain name, as there is more feature changes, and can support more devices, I just want to save and migrate exist old user data and history.

so i want to add migrate solution to process old device configs(old domain name) with new domain name using config_flow.py.

this old integration saved all the device configs with json file in /configs/.storage/<old_domain_name>/device_id.json
this is simple for me to check and migrate it to new domain in async_step_user() in config_flow.py
I have finished it now, but how to migrate the old history and the remain datas? I’m not sure now, not found any useful document about it.
for example ,some sensor history data, maybe in homeassiant database with sqllite3 or any suppored DB format? I’m not sure.
any idea for this migrate process? need help, thanks!


Main question for me would be: is it worth going through all the trouble of developing and testing this? This is a one-off migration, why not let the user set-it up again?

One reason for such a migration is that you would otherwise lose the history.

if you have more than 10-20 devices, setup again is a bad option.
if it possible, why not doing it via code ?

in fact, I have finished most of the device configs migrate, as it’s a lots of json config file, , it’s not a very comlex job, it can be finished it less than 100 lines.
i just want to check with history data and the remains I can continue doing .

yes, this is what i want to do, and need to confirm.
I think it maybe possible.
if it can’t be finished by config_flow.py.

maybe a py script to check and doing history data migrate with sqlite db is possible?
I’m not sure with the database and table info, need more help.

It is also some junk data and can be deleted directly from the database, so it is safe to operate these data directly.

If that is typical yes, understand … still, I am more of the lazy type and would just manually change it in the .storage where possible…100lin of code seems still a lot for me :slight_smile:

Were you successful with this task?
Mind sharing a link to your code? as I am looking into something similar and it might be very helpful to see what you have done :slight_smile: