@@ -22,8 +22,8 @@ namespace brave_ads {
22
22
23
23
namespace {
24
24
25
- const int kCurrentVersionNumber = 3 ;
26
- const int kCompatibleVersionNumber = 3 ;
25
+ const int kCurrentVersionNumber = 4 ;
26
+ const int kCompatibleVersionNumber = 4 ;
27
27
28
28
} // namespace
29
29
@@ -171,6 +171,7 @@ bool BundleStateDatabase::CreateAdInfoTable() {
171
171
" region VARCHAR,"
172
172
" campaign_id LONGVARCHAR,"
173
173
" daily_cap INTEGER DEFAULT 0 NOT NULL,"
174
+ " advertiser_id LONGVARCHAR,"
174
175
" per_day INTEGER DEFAULT 0 NOT NULL,"
175
176
" total_max INTEGER DEFAULT 0 NOT NULL,"
176
177
" PRIMARY KEY(region, uuid))" );
@@ -330,8 +331,9 @@ bool BundleStateDatabase::InsertOrUpdateAdInfo(const ads::AdInfo& info) {
330
331
" INSERT OR REPLACE INTO ad_info "
331
332
" (creative_set_id, advertiser, notification_text, "
332
333
" notification_url, start_timestamp, end_timestamp, uuid, "
333
- " campaign_id, daily_cap, per_day, total_max, region) "
334
- " VALUES (?, ?, ?, ?, datetime(?), datetime(?), ?, ?, ?, ?, ?, ?)" ));
334
+ " campaign_id, daily_cap, advertiser_id, per_day, total_max, "
335
+ " region) VALUES (?, ?, ?, ?, datetime(?), datetime(?), ?, ?, ?, "
336
+ " ?, ?, ?, ?)" ));
335
337
336
338
ad_info_statement.BindString (0 , info.creative_set_id );
337
339
ad_info_statement.BindString (1 , info.advertiser );
@@ -342,9 +344,10 @@ bool BundleStateDatabase::InsertOrUpdateAdInfo(const ads::AdInfo& info) {
342
344
ad_info_statement.BindString (6 , info.uuid );
343
345
ad_info_statement.BindString (7 , info.campaign_id );
344
346
ad_info_statement.BindInt (8 , info.daily_cap );
345
- ad_info_statement.BindInt (9 , info.per_day );
346
- ad_info_statement.BindInt (10 , info.total_max );
347
- ad_info_statement.BindString (11 , *it);
347
+ ad_info_statement.BindString (9 , info.advertiser_id );
348
+ ad_info_statement.BindInt (10 , info.per_day );
349
+ ad_info_statement.BindInt (11 , info.total_max );
350
+ ad_info_statement.BindString (12 , *it);
348
351
if (!ad_info_statement.Run ()) {
349
352
return false ;
350
353
}
@@ -418,7 +421,7 @@ bool BundleStateDatabase::GetAdsForCategory(
418
421
" ai.notification_text, ai.notification_url, "
419
422
" ai.start_timestamp, ai.end_timestamp, "
420
423
" ai.uuid, ai.region, ai.campaign_id, ai.daily_cap, "
421
- " ai.per_day, ai.total_max FROM ad_info AS ai "
424
+ " ai.advertiser_id, ai. per_day, ai.total_max FROM ad_info AS ai "
422
425
" INNER JOIN ad_info_category AS aic "
423
426
" ON aic.ad_info_uuid = ai.uuid "
424
427
" WHERE aic.category_name = ? and "
@@ -440,8 +443,9 @@ bool BundleStateDatabase::GetAdsForCategory(
440
443
info.uuid = info_sql.ColumnString (6 );
441
444
info.campaign_id = info_sql.ColumnString (8 );
442
445
info.daily_cap = info_sql.ColumnInt (9 );
443
- info.per_day = info_sql.ColumnInt (10 );
444
- info.total_max = info_sql.ColumnInt (11 );
446
+ info.advertiser_id = info_sql.ColumnString (10 );
447
+ info.per_day = info_sql.ColumnInt (11 );
448
+ info.total_max = info_sql.ColumnInt (12 );
445
449
ads->emplace_back (info);
446
450
}
447
451
@@ -558,6 +562,15 @@ bool BundleStateDatabase::Migrate() {
558
562
break ;
559
563
}
560
564
565
+ case 3 : {
566
+ if (!MigrateV3toV4 ()) {
567
+ LOG (ERROR) << " DB: Error migrating database from v3 to v4" ;
568
+ return false ;
569
+ }
570
+
571
+ break ;
572
+ }
573
+
561
574
default : {
562
575
NOTREACHED ();
563
576
return false ;
@@ -620,4 +633,13 @@ bool BundleStateDatabase::MigrateV2toV3() {
620
633
return GetDB ().Execute (sql.c_str ());
621
634
}
622
635
636
+ bool BundleStateDatabase::MigrateV3toV4 () {
637
+ std::string sql = " ALTER TABLE ad_info ADD advertiser_id LONGVARCHAR;" ;
638
+ if (!GetDB ().Execute (sql.c_str ())) {
639
+ return false ;
640
+ }
641
+
642
+ return false ;
643
+ }
644
+
623
645
} // namespace brave_ads
0 commit comments