Advice for AppSupport to AppGroup migration before publishing

Hi all

In pursuit of adopting widgets in my application, I have transitioned from AppSupport to AppGroup as storage location for Core Data. I have done a migration process/flow that goes as follows and which have been tested multiple times although I have yet to publish the update:

  1. Check if migration has taken place or not

1a. if yes continue to app

1b. If no continue flow

  1. Begin migration process

2a. Backup original store in AppSupport

2b. Migrate store to AppGroup

2c. Migrate userdefaults to AppGroup

2d. Update userdefaults with true for both hasMigratedToAppGroup and hasMigratedUserDefaultsToAppGroup

Is there any tips or stuff to look for that hasn’t been taken in to account? How have you done it previously, and what would be recommended? Also, is there some specific tests to run/over many times get a baseline of how many is succeeding or failing?

Thanks in advance.

Bump, no answer yet after 85 views.

Again no replies at 110 views. Kindly advice.

Again again no replies at 163 views. Can someone kindly provide some advice? Thanks.

Did you change your Core Data model in your new version app? If not, I'd assume that the "migration" you mentioned means "copy," which can be done using replacePersistentStore(at:destinationOptions:withPersistentStoreFrom:sourceOptions:type:).

Otherwise, you might consider doing the migration (lightweight or staged migration depending on your change) first, and then copy the migrated store to your App Group container.

Secondly, your flow doesn't seem to cover the widget side. Consider your users do the following:

  1. Downloading and installing your app.
  2. Configuring and adding your widget before running your main app.

Now your widget can run before your main app being launched, or they can run simultaneously. If your widget goes ahead to create an empty store and put some data there, the data will be lost when your main app copies the existing store. Also, if the widget and main app access the UserDefault simultaneously, a race will be triggered.

Without having the bigger picture, I may consider the following flow:

On the main app side:

  1. Check if the destination store URL exists. If yes, the copy is done, and so you continue the normal process.
  2. Otherwise, copy the store using replacePersistentStore....
  3. Set hasMigratedToAppGroup to true in the shared UseDefault.
  4. Continue your normal process.

On the widget side:

  1. Check if hasMigratedToAppGroup in the shared UserDefault is true. If yes, continue your normal process.
  2. Otherwise, present something in the UI to ask the user to launch the main app. With this, the widget doesn't access the store before it exists.

In this flow, hasMigratedToAppGroup helps the widget avoid accessing the store while the main app is copying. If your widget doesn't really write data to the store, you can load the store in readonly mode (See isReadOnly), and don't need the user default.

Advice for AppSupport to AppGroup migration before publishing
 
 
Q