How to update sqlite database asset?

Hi,

For an existing database, I need to copy my asset to the SQLITE folder using the FileSystem API.

But then when my database asset gets updated, the file is not copied to the SQLITE folder since it already exists.

What condition should I use ? Should I store the first hash file to redux and then compare with the new on every app launch, and then copy the file to the SQLITE folder?

What is the best way to check for the new database asset?

I assume this is a read-only database?

How do you get a new copy of the database? Off the top of my head I would think you could check if the database needs to be updated (e.g. check a version table in the database to see if it matches what the server says is the latest version). If an update is available, download it. Then delete the old one and move the new one into place.

Of course there’s a possibility that something might go wrong between deleting the old database and copying the new one into place, so you’d presumably have to handle the possibility of a missing database.

Thanks for you insights!

Basically it’s done like that:
https://github.com/bulby97/bible-strong/blob/feature/studies/src/common/WaitForDB.js

The name of the file don’t change, the asset is the same, just the content of the file changed.

Having to rely on the version mean read the remote database version, how it can be possible?

I think I came up with something:

      const dbPath = `${sqliteDirPath}/strong.sqlite`
      const dbFile = await FileSystem.getInfoAsync(dbPath)

      const sqliteDB = await AssetUtils.resolveAsync(require('~assets/db/strong.sqlite'))

      if (!dbFile.exists || sqliteDB.hash !== strongDatabaseHash) {
        dispatch(setStrongDatabaseHash(sqliteDB.hash))
        console.log(`Copying ${sqliteDB.localUri} to ${dbPath}`)
        await FileSystem.copyAsync({ from: sqliteDB.localUri, to: dbPath })
      }

I store the database hash, and I compare it to the asset hash. If it doesn’t match, it means it has been updated