This commit introduces a mechanism to remove specific repositories from the user's database during an `onUpgrade` event.
Key changes:
- Added a `toRemove` list in `Repository.kt` to specify addresses of repositories to be removed.
- Implemented `SQLiteDatabase.removeRepositories()` in `DatabaseHelper.kt`. This function:
- Queries the database for existing repositories.
- Compares them against the `toRemove` list.
- Marks matching repositories as deleted in the database by setting the `ROW_DELETED` flag to 1.
- The `onUpgrade` method in `DatabaseHelper.kt` now calls `db.removeRepositories()` before adding newly added repositories.
This commit refactors the database management logic by:
- Introducing a `Table` interface to define common table operations.
- Creating a `DatabaseHelper` class that extends `SQLiteOpenHelper` to encapsulate database creation, upgrades, and table/index management.
- Moving the `Schema` object into `Database` to maintain its accessibility.
- Making the `query` extension function on `SQLiteDatabase` public.
This improves code organization and maintainability by separating concerns related to database structure and helper functionalities.
This commit refactors the `AppDao` to provide more flexible and robust querying options for application data.
Key changes:
- **Renamed `_rawQueryAppEntities` to `_rawStreamAppEntities`**: This clarifies the function's purpose of returning a Flow of entities.
- **Added `_rawQueryAppEntities`**: A new suspend function that directly returns a List of entities, for non-streaming use cases.
- **Introduced `query` function**: A new public suspend function that mirrors the functionality of `stream` but returns a `List<AppEntity>` instead of a `Flow`.
- **Enhanced `searchQuery` private function**:
- Now accepts lists for `categoriesToInclude`, `categoriesToExclude`, `antiFeaturesToInclude`, and `antiFeaturesToExclude` to allow filtering by multiple criteria.
- Uses `DISTINCT` in the SQL query to avoid duplicate app entries.
- Corrected join condition for `category_app_relation` from `app.id = category_app_relation.appId` to `app.id = category_app_relation.id`.
- Corrected table name for anti-features from `anti_feature_app_relation` to `anti_features_app_relation`.
- Improved SQL query construction for category and anti-feature filtering using `IN` and `NOT IN` clauses.
- Ensured `ORDER BY` clause is always present, even if `searchQuery` is null.
- Prefixed table names in `ORDER BY` clause (e.g., `app.lastUpdated`) for clarity and to avoid ambiguity.
- **Updated `stream` function**: Now utilizes the refactored `searchQuery` function and passes through all new filtering parameters.
- **Updated database schema**:
- Changed `onDelete` action for the foreign key in the `authentication` table to `CASCADE`.
- **Updated Room tests**:
- Simplified setup by removing legacy database initialization.
- Added tests for new sorting and category filtering functionalities in `AppDao`.
This commit simplifies the `RepoDao` by removing the manual deletion of authentication records when a repository is deleted.
Instead, it leverages Room's `onDelete = CASCADE` functionality in the `AuthenticationEntity`'s foreign key definition. This ensures that when a `RepoEntity` is deleted, its associated `AuthenticationEntity` records are automatically removed from the database.
The `deleteRepo` and `deleteAuth` methods in `RepoDao` have been removed as they are no longer necessary. Additionally, `stream()` and `repo()` methods have been added to `RepoDao` for observing repository data.
This commit simplifies the `RepoDao` by removing the manual deletion of authentication records when a repository is deleted.
Instead, it leverages Room's `onDelete = CASCADE` functionality in the `AuthenticationEntity`'s foreign key definition. This ensures that when a `RepoEntity` is deleted, its associated `AuthenticationEntity` records are automatically removed from the database.
The `deleteRepo` and `deleteAuth` methods in `RepoDao` have been removed as they are no longer necessary. Additionally, `stream()` and `repo()` methods have been added to `RepoDao` for observing repository data.