-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/deprecated local ads db migration #91
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e2fd0ff
build(deps): update core and dart_frog dependencies
fulleni d6d6767
refactor(dependencies): remove local ad repository
fulleni 604f425
refactor(routes): remove local ad repository provider
fulleni 61e9fa6
refactor(data): remove local_ad references and add registry initializ…
fulleni 194513b
refactor(registry): remove local_ad model configuration
fulleni 814d81e
refactor(seeding): remove local ads seeding and indexing
fulleni 3a5c15d
refactor(database): remove legacy local ad platform from remote configs
fulleni b9d844f
chore: remove unnecessary comments from PR template
fulleni 998a374
docs(api): update comments for route handler middleware
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
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
65 changes: 65 additions & 0 deletions
65
lib/src/database/migrations/20251103073226_remove_local_ad_platform.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,65 @@ | ||
| 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'; | ||
|
|
||
| /// Migration to remove the legacy `local` ad platform from the `remote_configs` | ||
| /// collection. | ||
| /// | ||
| /// This migration performs two critical cleanup tasks: | ||
| /// 1. It removes the `local` key from the `adConfig.platformAdIdentifiers` map | ||
| /// in all `remote_configs` documents. | ||
| /// 2. It updates any `remote_configs` document where the `primaryAdPlatform` | ||
| /// is set to `local`, changing it to `admob`. | ||
| /// | ||
| /// This ensures data consistency after the removal of the `AdPlatformType.local` | ||
| /// enum value and prevents deserialization errors in the application. | ||
| class RemoveLocalAdPlatform extends Migration { | ||
| /// {@macro remove_local_ad_platform} | ||
| RemoveLocalAdPlatform() | ||
| : super( | ||
| prDate: '20251103073226', | ||
| prId: '57', | ||
| prSummary: | ||
| 'Removes the legacy local ad platform from the remote config, migrating existing data to use admob as the default.', | ||
| ); | ||
|
|
||
| @override | ||
| Future<void> up(Db db, Logger log) async { | ||
| final collection = db.collection('remote_configs'); | ||
|
|
||
| // Step 1: Unset the 'local' key from the platformAdIdentifiers map. | ||
| // This removes the field entirely from any document where it exists. | ||
| log.info( | ||
| 'Attempting to remove "adConfig.platformAdIdentifiers.local" field...', | ||
| ); | ||
| final unsetResult = await collection.updateMany( | ||
| where.exists('adConfig.platformAdIdentifiers.local'), | ||
| modify.unset('adConfig.platformAdIdentifiers.local'), | ||
| ); | ||
| log.info( | ||
| 'Removed "adConfig.platformAdIdentifiers.local" from ${unsetResult.nModified} documents.', | ||
| ); | ||
|
|
||
| // Step 2: Update the primaryAdPlatform from 'local' to 'admob'. | ||
| // This ensures that no document is left with an invalid primary platform. | ||
| log.info( | ||
| 'Attempting to migrate primaryAdPlatform from "local" to "admob"...', | ||
| ); | ||
| final updateResult = await collection.updateMany( | ||
| where.eq('adConfig.primaryAdPlatform', 'local'), | ||
| modify.set('adConfig.primaryAdPlatform', 'admob'), | ||
| ); | ||
| log.info( | ||
| 'Migrated primaryAdPlatform to "admob" for ${updateResult.nModified} documents.', | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> down(Db db, Logger log) async { | ||
| // Reverting this change is not safe as it would require re-introducing | ||
| // an enum value that no longer exists in the code. | ||
| log.warning( | ||
| 'Reverting "RemoveLocalAdPlatform" is not supported. The "local" ad platform configuration would need to be manually restored if required.', | ||
| ); | ||
| } | ||
| } |
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
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
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
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
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
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
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
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
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.