How to Deploy a Large Database

Using Xcode 11.6; Swift; deploying to iOS.

The app has a ~250M SQLite database as a core resource.

The database is built up by importing a dozen .txt files. This process takes considerable time.

I have used the simulator to build up the database. I then obtained the .sqlite file from the macOS filesystem and include it in the iOS app Resources.

Since this database will undergo changes as the app is used, during first use the .sqlite file id copied to the .applicationSupportDirectory.
The original file in the mainBundle remains useful in the event that the user wishes to 'reset to factory'.

All of this is working fine and as expected.

My concern is the 2x usage of the users storage:
250M in mainBundle + 250M in .applicationSupport....

I have tried using Swift [data].compressed(using: .lz4) and .decompressed() ... The .compressed() works as expected and results in a ~65M file.. BUT the .decompressed() never finishes and never errors - it simply runs until the process is killed... Are there known issues with .sqlite files?

Is there a better strategy?

I really would like to understand the best practice for deploying a large .sqlite file without using 2x the storage...

Any feedback is appreciated.
Feedback from other sources has illuminated the following strategy:
  • -Split the database into two databases: ReadOnly and UserModifiable

Use the ReadOnly directly from within the mainBundle.
UserModifiable is copied to .applicationSupport and then used from there.

Duplication is then reduced to the initial database for userModifiable...(in my case this is relatively small!)

This strategy also addresses concern with backup (contents of .applicationSupport)




You can use On-Demand Resources to solve this. You are able to tag a resource as required during the download of the app (as an Initial Install Tag), and then once the app has run the first time for you to deploy the database, you can tell ODR that you're done with the resource so its removed from the device. When you need to re-deploy the data, ask ODR to download the resource again.
How to Deploy a Large Database
 
 
Q