简体   繁体   中英

Change Firebase Realtime Database POJO properties using @PropertyName, How to migrate existing data

I have an app already in production, and now I want to change database property names in several tables to reduce bandwidth.

For eg, realtime database existing property is:

   purchasePrice: 60

and by using @PropertyName, I want to change it so it now looks like this:

   pp: 60

The changed POJO now has @PropertyName like:

   @PropertyName("pp")
   public float purchasePrice;

The question is: What is the best migration strategy so that all existing 'purchasePrice' is updated to new name in the realtime database, ie 'pp' in this example case?

One naive approach I can think of is, on app update at client end, pull all data using old POJOs and assign each property to new POJOs (newPOJO.pp = oldPOJO.purchasePrice) and then save it in DB. But there should be a better way, as I have many POJOs.

Thanks,

If you want to change the name of a field in the database everywhere it occurs, there is really no easy way to do this. You're going to have to:

  1. Query all of the nodes where it could appear
  2. Check to see if the field needs to change
  3. Write the new data back to that location

Whether you do that with code that uses @PropertyName or something more generic, it doesn't really matter.

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