Skip to content

Commit 90a0204

Browse files
authored
Merge pull request #76 from flutter-news-app-full-source-code/chore/sync-migration
Chore/sync migration
2 parents f6e64dc + a65e33e commit 90a0204

File tree

5 files changed

+79
-18
lines changed

5 files changed

+79
-18
lines changed

CHANGELOG.md

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import 'package:flutter_news_app_api_server_full_source_code/src/database/migration.dart';
2+
import 'package:logging/logging.dart';
3+
import 'package:mongo_dart/mongo_dart.dart';
4+
5+
/// Migration to add the `logoUrl` field to existing `sources` documents.
6+
class AddLogoUrlToSources extends Migration {
7+
/// {@macro add_logo_url_to_sources}
8+
AddLogoUrlToSources()
9+
: super(
10+
prDate: '20251024000000',
11+
prId: '60',
12+
prSummary:
13+
'Adds the required `logoUrl` field to all existing '
14+
'documents in the `sources` collection to align with the '
15+
'core v1.3.0 model update.',
16+
);
17+
18+
@override
19+
Future<void> up(Db db, Logger log) async {
20+
final collection = db.collection('sources');
21+
final sourcesToUpdate = await collection
22+
.find(where.notExists('logoUrl'))
23+
.toList();
24+
25+
if (sourcesToUpdate.isEmpty) {
26+
log.info('No sources found needing a logoUrl. Migration is up to date.');
27+
return;
28+
}
29+
30+
log.info(
31+
'Found ${sourcesToUpdate.length} sources to update with a logoUrl.',
32+
);
33+
var count = 0;
34+
for (final source in sourcesToUpdate) {
35+
final sourceUrl = source['url'] as String?;
36+
if (sourceUrl != null && sourceUrl.isNotEmpty) {
37+
try {
38+
final host = Uri.parse(sourceUrl).host;
39+
final logoUrl = 'https://logo.clearbit.com/$host?size=200';
40+
await collection.updateOne(
41+
where.id(source['_id'] as ObjectId),
42+
modify.set('logoUrl', logoUrl),
43+
);
44+
count++;
45+
} catch (e) {
46+
log.warning(
47+
'Could not parse URL for source ${source['_id']}: $sourceUrl',
48+
);
49+
}
50+
}
51+
}
52+
log.info('Updated $count sources with a new logoUrl.');
53+
}
54+
55+
@override
56+
Future<void> down(Db db, Logger log) async {
57+
final collection = db.collection('sources');
58+
await collection.updateMany(
59+
where.exists('logoUrl'),
60+
modify.unset('logoUrl'),
61+
);
62+
log.info(
63+
'Removed "logoUrl" field from all documents in the sources collection.',
64+
);
65+
}
66+
}

lib/src/database/migrations/all_migrations.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter_news_app_api_server_full_source_code/src/database/migrat
22
import 'package:flutter_news_app_api_server_full_source_code/src/database/migrations/20250924084800__refactor_ad_config_to_role_based.dart';
33
import 'package:flutter_news_app_api_server_full_source_code/src/database/migrations/20251013000056_add_saved_filters_to_user_preferences.dart';
44
import 'package:flutter_news_app_api_server_full_source_code/src/database/migrations/20251013000057_add_saved_filters_to_remote_config.dart';
5+
import 'package:flutter_news_app_api_server_full_source_code/src/database/migrations/20251024000000_add_logo_url_to_sources.dart';
56
import 'package:flutter_news_app_api_server_full_source_code/src/services/database_migration_service.dart'
67
show DatabaseMigrationService;
78

@@ -14,4 +15,5 @@ final List<Migration> allMigrations = [
1415
RefactorAdConfigToRoleBased(),
1516
AddSavedFiltersToUserPreferences(),
1617
AddSavedFiltersToRemoteConfig(),
18+
AddLogoUrlToSources(),
1719
];

pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ packages:
117117
dependency: "direct main"
118118
description:
119119
path: "."
120-
ref: "v1.2.0"
121-
resolved-ref: d052799c1ebb7bcdd1a725a2a7919948c14fa001
120+
ref: "v1.3.0"
121+
resolved-ref: ee2ad7de28baec04d64c0afd3e3a61d7e4ad6cb0
122122
url: "https://github.com/flutter-news-app-full-source-code/core.git"
123123
source: git
124-
version: "1.2.0"
124+
version: "1.3.0"
125125
coverage:
126126
dependency: transitive
127127
description:

pubspec.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flutter_news_app_api_server_full_source_code
22
description: The complete backend API server for the Flutter News App Toolkit, built with Dart Frog. Powers authentication, data management, user settings, and more.
33
repository: https://github.com/flutter-news-app-full-source-code/flutter-news-app-api-server-full-source-code
44
publish_to: none
5-
version: 1.0.1
5+
version: 1.1.0
66

77
environment:
88
sdk: ^3.9.0
@@ -12,7 +12,7 @@ dependencies:
1212
core:
1313
git:
1414
url: https://github.com/flutter-news-app-full-source-code/core.git
15-
ref: v1.2.0
15+
ref: v1.3.0
1616
dart_frog: ^1.1.0
1717
dart_jsonwebtoken: ^3.2.0
1818
data_client:
@@ -54,3 +54,9 @@ dev_dependencies:
5454
mocktail: ^1.0.3
5555
test: ^1.25.5
5656
very_good_analysis: ^9.0.0
57+
58+
dependency_overrides:
59+
core:
60+
git:
61+
url: https://github.com/flutter-news-app-full-source-code/core.git
62+
ref: v1.3.0

0 commit comments

Comments
 (0)