-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/sync with core package update #96
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5bc63e3
build(deps): update core package reference
fulleni 0f3cb81
feat(db): add migration to refactor user preferences and remote config
fulleni 8c3fea9
refactor(db): update migration registry with new schema changes
fulleni 870dec5
refactor(auth): adapt user creation to new preference models
fulleni e08b1f4
refactor(db): adapt user seeding to new preference models
fulleni 0378a35
refactor(limits): adapt user preference limits to new config structure
fulleni 7f42386
refactor(notifications): update breaking news subscription query
fulleni 1929991
refactor(rbac): remove local ad permissions and role assignments
fulleni bbdd4a6
docs(README): update notification streams feature description
fulleni 271c8ce
fix(default-user-preference-limit): change log level for saved headli…
fulleni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
229 changes: 0 additions & 229 deletions
229
lib/src/database/migrations/20251111000000_unify_interests_and_remote_config.dart
This file was deleted.
Oops, something went wrong.
160 changes: 160 additions & 0 deletions
160
lib/src/database/migrations/20251112000000_refactor_user_preferences_and_remote_config.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import 'package:core/core.dart'; | ||
| import 'package:flutter_news_app_api_server_full_source_code/src/database/migration.dart'; | ||
| import 'package:logging/logging.dart'; | ||
| import 'package:mongo_dart/mongo_dart.dart'; | ||
|
|
||
| /// {@template refactor_user_preferences_and_remote_config} | ||
| /// A migration to refactor the database schema to align with the updated | ||
| /// `UserContentPreferences` and `RemoteConfig` models from the core package. | ||
| /// | ||
| /// This migration performs two critical transformations: | ||
| /// | ||
| /// 1. **User Preferences Transformation:** It iterates through all | ||
| /// `user_content_preferences` documents. For each user, it adds the new | ||
| /// `savedHeadlineFilters` and `savedSourceFilters` fields as empty lists | ||
| /// and removes the now-obsolete `interests` field. | ||
| /// | ||
| /// 2. **Remote Config Transformation:** It updates the single `remote_configs` | ||
| /// document by removing the deprecated `interestConfig` and replacing the | ||
| /// individual limit fields in `userPreferenceConfig` with the new, | ||
| /// flexible role-based map structure. | ||
| /// {@endtemplate} | ||
| class RefactorUserPreferencesAndRemoteConfig extends Migration { | ||
| /// {@macro refactor_user_preferences_and_remote_config} | ||
| RefactorUserPreferencesAndRemoteConfig() | ||
| : super( | ||
| prDate: '20251112000000', | ||
| prId: '78', | ||
| prSummary: | ||
| 'Refactors UserContentPreferences and RemoteConfig to support new SavedFilter models.', | ||
| ); | ||
|
|
||
| @override | ||
| Future<void> up(Db db, Logger log) async { | ||
| log.info('Starting migration: RefactorUserPreferencesAndRemoteConfig.up'); | ||
|
|
||
| // --- 1. Migrate user_content_preferences --- | ||
| log.info('Migrating user_content_preferences collection...'); | ||
| final preferencesCollection = db.collection('user_content_preferences'); | ||
| final result = await preferencesCollection.updateMany( | ||
| where.exists('interests'), | ||
| modify | ||
| .set('savedHeadlineFilters', <dynamic>[]) | ||
| .set('savedSourceFilters', <dynamic>[]) | ||
| .unset('interests'), | ||
| ); | ||
| log.info( | ||
| 'Updated user_content_preferences: ${result.nModified} documents modified.', | ||
| ); | ||
|
|
||
| // --- 2. Migrate remote_configs --- | ||
| log.info('Migrating remote_configs collection...'); | ||
| final remoteConfigCollection = db.collection('remote_configs'); | ||
| final remoteConfig = await remoteConfigCollection.findOne(); | ||
|
|
||
| if (remoteConfig != null) { | ||
| // Define the new UserPreferenceConfig structure based on the new model. | ||
| // This uses the structure from the "NEW REMOTE CONFIG" example. | ||
| const newConfig = UserPreferenceConfig( | ||
| followedItemsLimit: { | ||
| AppUserRole.guestUser: 5, | ||
| AppUserRole.standardUser: 15, | ||
| AppUserRole.premiumUser: 30, | ||
| }, | ||
| savedHeadlinesLimit: { | ||
| AppUserRole.guestUser: 10, | ||
| AppUserRole.standardUser: 30, | ||
| AppUserRole.premiumUser: 100, | ||
| }, | ||
| savedHeadlineFiltersLimit: { | ||
| AppUserRole.guestUser: SavedFilterLimits( | ||
| total: 3, | ||
| pinned: 3, | ||
| notificationSubscriptions: { | ||
| PushNotificationSubscriptionDeliveryType.breakingOnly: 1, | ||
| PushNotificationSubscriptionDeliveryType.dailyDigest: 0, | ||
| PushNotificationSubscriptionDeliveryType.weeklyRoundup: 0, | ||
| }, | ||
| ), | ||
| AppUserRole.standardUser: SavedFilterLimits( | ||
| total: 10, | ||
| pinned: 5, | ||
| notificationSubscriptions: { | ||
| PushNotificationSubscriptionDeliveryType.breakingOnly: 3, | ||
| PushNotificationSubscriptionDeliveryType.dailyDigest: 2, | ||
| PushNotificationSubscriptionDeliveryType.weeklyRoundup: 2, | ||
| }, | ||
| ), | ||
| AppUserRole.premiumUser: SavedFilterLimits( | ||
| total: 25, | ||
| pinned: 10, | ||
| notificationSubscriptions: { | ||
| PushNotificationSubscriptionDeliveryType.breakingOnly: 10, | ||
| PushNotificationSubscriptionDeliveryType.dailyDigest: 10, | ||
| PushNotificationSubscriptionDeliveryType.weeklyRoundup: 10, | ||
| }, | ||
| ), | ||
| }, | ||
| savedSourceFiltersLimit: { | ||
| AppUserRole.guestUser: SavedFilterLimits(total: 3, pinned: 3), | ||
| AppUserRole.standardUser: SavedFilterLimits(total: 10, pinned: 5), | ||
| AppUserRole.premiumUser: SavedFilterLimits(total: 25, pinned: 10), | ||
| }, | ||
| ); | ||
|
|
||
| await remoteConfigCollection.updateOne( | ||
| where.id(remoteConfig['_id'] as ObjectId), | ||
| modify | ||
| // Set the entire userPreferenceConfig to the new structure | ||
| .set('userPreferenceConfig', newConfig.toJson()) | ||
| // Remove the obsolete interestConfig | ||
| .unset('interestConfig'), | ||
| ); | ||
| log.info('Successfully migrated remote_configs document.'); | ||
| } else { | ||
| log.warning('Remote config document not found. Skipping migration.'); | ||
| } | ||
|
|
||
| log.info('Migration RefactorUserPreferencesAndRemoteConfig.up completed.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> down(Db db, Logger log) async { | ||
| log.warning( | ||
| 'Executing "down" for RefactorUserPreferencesAndRemoteConfig. ' | ||
| 'This is a destructive operation and may result in data loss.', | ||
| ); | ||
|
|
||
| // --- 1. Revert user_content_preferences --- | ||
| final preferencesCollection = db.collection('user_content_preferences'); | ||
| await preferencesCollection.updateMany( | ||
| where.exists('savedHeadlineFilters'), // Target documents to revert | ||
| modify | ||
| .unset('savedHeadlineFilters') | ||
| .unset('savedSourceFilters') | ||
| .set('interests', <dynamic>[]), | ||
| ); | ||
| log.info( | ||
| 'Reverted user_content_preferences: removed new filter fields and ' | ||
| 're-added empty "interests" field.', | ||
| ); | ||
|
|
||
| // --- 2. Revert remote_configs --- | ||
| // This is a best-effort revert and will not restore the exact previous | ||
| // state but will remove the new fields. | ||
| final remoteConfigCollection = db.collection('remote_configs'); | ||
| await remoteConfigCollection.updateMany( | ||
| where.exists('userPreferenceConfig.followedItemsLimit'), | ||
| modify | ||
| .unset('userPreferenceConfig') | ||
| .set('interestConfig', <String, dynamic>{}), | ||
| ); | ||
fulleni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.info( | ||
| 'Reverted remote_configs: removed new userPreferenceConfig structure.', | ||
| ); | ||
|
|
||
| log.info( | ||
| 'Migration RefactorUserPreferencesAndRemoteConfig.down completed.', | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.