HomePhabricator
Diffusion Comm c07f1ab316bb

Implement SQLiteQueryExecutor method to restore database from main compaction

Description

Implement SQLiteQueryExecutor method to restore database from main compaction

Summary: This revision implements a method in SQLiteQueryExecutor to restore database from backup file using SQLite backup API. Additionally it modifies is_database_queryable function so that it can be used for database at any path with any encryption key. It is necessary since we need to check if backup file is actually encrypted with the encryption key provided from backup service and to handle and edge case that we successfully re-encrypted backup database with our encryption key but restoration was interrupted before we replaced database content with backup. Finally this differential implements a function to change encryption key of an encrypted database according to SQLCipher docs: https://www.zetetic.net/sqlcipher/sqlcipher-api/#Changing_Key.

Test Plan:

  1. Build app.
  2. Write some drafts in some threads.
  3. Rebuild the app, but modify updateDraft function in SQLiteQueryExecutor to create main compaction instead of updating draft. Add some logging to print encryptionKey to the console.
  4. Update draft.
  5. Ensure that backup file is created by downloading container from Xcode or by examining device file explorer in Android studio. Ensure file is encrypted.
  6. Log-out.
  7. Re-build the app, but modify updateDraft function in SQLiteQueryExecutor to restore database from main compaction. Hardcode the same backup id that you used to create compaction and encryptionKey that was logged to the console.
  8. Log-in.
  9. Update draft.
  10. Ensure that drafts saved before log-out are on the device.

Reviewers: kamil, michal

Reviewed By: kamil

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D10504

Details