Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Room database #10977

Merged
merged 10 commits into from
Nov 15, 2022
Merged

Setup Room database #10977

merged 10 commits into from
Nov 15, 2022

Conversation

AlvaroBrey
Copy link
Member

@AlvaroBrey AlvaroBrey commented Nov 2, 2022

The point of this PR is to set up Room as a DB client, even if we are still using the FileContentProvider as an accessor for now.

After this is merged:

  • Room will handle creation and upgrades of database
  • The app will keep using the FileContentProvider as a database access point
  • The FileContentProvider will stay mostly the same, but will get the database helper from Room instead of creating it.

This is the first step in the recommended way to migrate an app to Room incrementally, when a full migration is not possible immediately.

After this is finalized and merged, it will be possible to write DAOs (and Repositories) for the introduced entities and progressively stop using the ContentProviders as a way to access the DB internally. It should also be possible to use Room's auto-migrations for future DB upgrades.

Resources:
https://developer.android.com/training/data-storage/room/sqlite-room-migration#incremental
https://medium.com/androiddevelopers/incrementally-migrate-from-sqlite-to-room-66c2f655b377

  • Check projectionMap and setStrict
    • Not supported directly in SupportSqliteQueryBuilder
    • Extra validations added in place
  • Migrations
    • Migrate LONG, STRING to INTEGER, TEXT
    • Test with 3.22
    • Test with several old app versions
      • 3.21
      • 3.20
      • 3.19
      • 3.18
      • 3.17
      • 3.10 -> crashes because of files_drop column that doesn't exist anymore
        - added new migrations
      • 3.3.0
      • 2.0.0
      • fall back to destructive migration for older versions?
        • remove migration code for versions under that one?
      • check what happens when migrating a filelist table with too big rows ([Meta] Crashes caused by too much data in SQLite rows #10213) -> migration doesn't trigger crash, so that's fine
  • Finalize Room config (export schemas, automigration)
    • Automigration config will be added first time we do a migration
  • [ ] TypeConverters for boolean <-> int etc? out of scope. let's get room working first
  • Tests written, or not not needed

@AlvaroBrey
Copy link
Member Author

@tobiasKaminsky @AndyScherzinger this is still in an early stage, but I'd appreciate any input on the approach and your opinion about this in general

@AndyScherzinger
Copy link
Member

Approach looks good to me and super happy to see this change being kicked off 👍

@codecov
Copy link

codecov bot commented Nov 3, 2022

Codecov Report

Merging #10977 (f049603) into master (e963905) will decrease coverage by 0.33%.
The diff coverage is 2.10%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #10977      +/-   ##
============================================
- Coverage     31.31%   30.98%   -0.34%     
+ Complexity     3282     3269      -13     
============================================
  Files           544      558      +14     
  Lines         41016    41505     +489     
  Branches       5681     5709      +28     
============================================
+ Hits          12846    12859      +13     
- Misses        26269    26724     +455     
- Partials       1901     1922      +21     
Impacted Files Coverage Δ
...loud/client/database/entity/ArbitraryDataEntity.kt 0.00% <0.00%> (ø)
...xtcloud/client/database/entity/CapabilityEntity.kt 0.00% <0.00%> (ø)
...cloud/client/database/entity/ExternalLinkEntity.kt 0.00% <0.00%> (ø)
...com/nextcloud/client/database/entity/FileEntity.kt 0.00% <0.00%> (ø)
...xtcloud/client/database/entity/FilesystemEntity.kt 0.00% <0.00%> (ø)
...om/nextcloud/client/database/entity/ShareEntity.kt 0.00% <0.00%> (ø)
...cloud/client/database/entity/SyncedFolderEntity.kt 0.00% <0.00%> (ø)
...m/nextcloud/client/database/entity/UploadEntity.kt 0.00% <0.00%> (ø)
.../nextcloud/client/database/entity/VirtualEntity.kt 0.00% <0.00%> (ø)
...ent/database/migrations/LegacyMigrationHelper.java 0.00% <0.00%> (ø)
... and 17 more

@AlvaroBrey
Copy link
Member Author

AlvaroBrey commented Nov 4, 2022

@tobiasKaminsky @AndyScherzinger this is now ready for review. I still have to test migrations from 3.18-3.20, but since it's working from 3.10, I'd say it's a safe bet it will work for newer versions.

I would also encourage smoketesting if possible.

That being said, 3.10 is a semi-random point I chose for cutoff, as it's from January 2019, so almost 3 years old. Do you have any other idea of a "safe" point to test back to? Maybe 3.0?

@AlvaroBrey
Copy link
Member Author

That being said, 3.10 is a semi-random point I chose for cutoff, as it's from January 2019, so almost 3 years old. Do you have any other idea of a "safe" point to test back to? Maybe 3.0?

Tested back to 3.3.0, which is the oldest 3.x version I can find an APK for.

@AlvaroBrey AlvaroBrey changed the title WIP: Setup Room Setup Room database Nov 4, 2022
@AndyScherzinger
Copy link
Member

I am only partially on duty this and next week, so it's unlikely that find the time to test drive this or next week 😔

@AlvaroBrey
Copy link
Member Author

That being said, 3.10 is a semi-random point I chose for cutoff, as it's from January 2019, so almost 3 years old. Do you have any other idea of a "safe" point to test back to? Maybe 3.0?

Tested back to 3.3.0, which is the oldest 3.x version I can find an APK for.

Finally set the cutoff to 2.0 and dropped earlier migrations. 2.0 is the oldest that doesn't break (upgrade from 1.x to current 3.22 is broken too, not just in this PR).

@tobiasKaminsky
Copy link
Member

Finally set the cutoff to 2.0 and dropped earlier migrations. 2.0 is the oldest that doesn't break (upgrade from 1.x to current 3.22 is broken too, not just in this PR).

2.0 is more than enough 👏

@tobiasKaminsky
Copy link
Member

Awesome!

@tobiasKaminsky
Copy link
Member

/rebase

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
See added comment for explanation

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Needed to enable auto-upgrades later

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
…projectionMap

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
github-actions and others added 4 commits November 15, 2022 10:02
Signed-off-by: github-actions <github-actions@github.com>
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
They both have unused columns that were not removed in previous migrations, and this makes Room unhappy

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Migration from such old app versions is broken anyway, not only in the database, but also in sharedprefs

Additionally, configure destructive migration for unsupported versions in Room

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
@github-actions
Copy link

Codacy

Lint

TypemasterPR
Warnings8382
Errors00

SpotBugs

CategoryBaseNew
Bad practice2828
Correctness4545
Dodgy code341341
Internationalization99
Multithreaded correctness99
Performance5858
Security2818
Total518508

@github-actions
Copy link

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/10977.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@github-actions
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants