@@ -22,7 +22,7 @@ namespace brave_rewards {
22
22
23
23
namespace {
24
24
25
- const int kCurrentVersionNumber = 2 ;
25
+ const int kCurrentVersionNumber = 3 ;
26
26
const int kCompatibleVersionNumber = 1 ;
27
27
28
28
} // namespace
@@ -152,10 +152,10 @@ bool PublisherInfoDatabase::CreateActivityInfoTable() {
152
152
" ("
153
153
" publisher_id LONGVARCHAR NOT NULL,"
154
154
" duration INTEGER DEFAULT 0 NOT NULL,"
155
+ " visits INTEGER DEFAULT 0 NOT NULL,"
155
156
" score DOUBLE DEFAULT 0 NOT NULL,"
156
157
" percent INTEGER DEFAULT 0 NOT NULL,"
157
158
" weight DOUBLE DEFAULT 0 NOT NULL,"
158
- " category INTEGER NOT NULL,"
159
159
" month INTEGER NOT NULL,"
160
160
" year INTEGER NOT NULL,"
161
161
" reconcile_stamp INTEGER DEFAULT 0 NOT NULL,"
@@ -263,33 +263,31 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
263
263
264
264
sql::Statement activity_get (
265
265
db_.GetUniqueStatement (" SELECT publisher_id FROM activity_info WHERE "
266
- " publisher_id=? AND category =? "
267
- " AND month=? AND year=? AND reconcile_stamp=?" ));
266
+ " publisher_id=? AND month =? "
267
+ " AND year=? AND reconcile_stamp=?" ));
268
268
269
269
activity_get.BindString (0 , info.id );
270
- activity_get.BindInt (1 , info.category );
271
- activity_get.BindInt (2 , info.month );
272
- activity_get.BindInt (3 , info.year );
273
- activity_get.BindInt64 (4 , info.reconcile_stamp );
270
+ activity_get.BindInt (1 , info.month );
271
+ activity_get.BindInt (2 , info.year );
272
+ activity_get.BindInt64 (3 , info.reconcile_stamp );
274
273
275
274
if (activity_get.Step ()) {
276
275
sql::Statement activity_info_update (
277
276
GetDB ().GetCachedStatement (SQL_FROM_HERE,
278
277
" UPDATE activity_info SET "
279
278
" duration=?, score=?, percent=?, "
280
279
" weight=? WHERE "
281
- " publisher_id=? AND category =? "
282
- " AND month=? AND year=? AND reconcile_stamp=?" ));
280
+ " publisher_id=? AND month =? "
281
+ " AND year=? AND reconcile_stamp=?" ));
283
282
284
283
activity_info_update.BindInt64 (0 , (int )info.duration );
285
284
activity_info_update.BindDouble (1 , info.score );
286
285
activity_info_update.BindInt64 (2 , (int )info.percent );
287
286
activity_info_update.BindDouble (3 , info.weight );
288
287
activity_info_update.BindString (4 , info.id );
289
- activity_info_update.BindInt (5 , info.category );
290
- activity_info_update.BindInt (6 , info.month );
291
- activity_info_update.BindInt (7 , info.year );
292
- activity_info_update.BindInt64 (8 , info.reconcile_stamp );
288
+ activity_info_update.BindInt (5 , info.month );
289
+ activity_info_update.BindInt (6 , info.year );
290
+ activity_info_update.BindInt64 (7 , info.reconcile_stamp );
293
291
294
292
return activity_info_update.Run ();
295
293
}
@@ -298,18 +296,17 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
298
296
GetDB ().GetCachedStatement (SQL_FROM_HERE,
299
297
" INSERT INTO activity_info "
300
298
" (publisher_id, duration, score, percent, "
301
- " weight, category, month, year, reconcile_stamp) "
299
+ " weight, month, year, reconcile_stamp) "
302
300
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" ));
303
301
304
302
activity_info_insert.BindString (0 , info.id );
305
303
activity_info_insert.BindInt64 (1 , (int )info.duration );
306
304
activity_info_insert.BindDouble (2 , info.score );
307
305
activity_info_insert.BindInt64 (3 , (int )info.percent );
308
306
activity_info_insert.BindDouble (4 , info.weight );
309
- activity_info_insert.BindInt (5 , info.category );
310
- activity_info_insert.BindInt (6 , info.month );
311
- activity_info_insert.BindInt (7 , info.year );
312
- activity_info_insert.BindInt64 (8 , info.reconcile_stamp );
307
+ activity_info_insert.BindInt (5 , info.month );
308
+ activity_info_insert.BindInt (6 , info.year );
309
+ activity_info_insert.BindInt64 (7 , info.reconcile_stamp );
313
310
314
311
return activity_info_insert.Run ();
315
312
}
@@ -384,7 +381,7 @@ bool PublisherInfoDatabase::Find(int start,
384
381
return false ;
385
382
386
383
std::string query = " SELECT ai.publisher_id, ai.duration, ai.score, ai.percent, "
387
- " ai.weight, pi.verified, pi.excluded, ai.category, ai. month, ai.year, pi.name, "
384
+ " ai.weight, pi.verified, pi.excluded, ai.month, ai.year, pi.name, "
388
385
" pi.url, pi.provider, pi.favIcon, ai.reconcile_stamp "
389
386
" FROM activity_info AS ai "
390
387
" INNER JOIN publisher_info AS pi ON ai.publisher_id = pi.publisher_id "
@@ -399,8 +396,8 @@ bool PublisherInfoDatabase::Find(int start,
399
396
while (info_sql.Step ()) {
400
397
std::string id (info_sql.ColumnString (0 ));
401
398
ledger::PUBLISHER_MONTH month (
402
- static_cast <ledger::PUBLISHER_MONTH>(info_sql.ColumnInt (8 )));
403
- int year (info_sql.ColumnInt (9 ));
399
+ static_cast <ledger::PUBLISHER_MONTH>(info_sql.ColumnInt (7 )));
400
+ int year (info_sql.ColumnInt (8 ));
404
401
405
402
ledger::PublisherInfo info (id, month, year);
406
403
info.duration = info_sql.ColumnInt64 (1 );
@@ -409,15 +406,13 @@ bool PublisherInfoDatabase::Find(int start,
409
406
info.percent = info_sql.ColumnInt64 (3 );
410
407
info.weight = info_sql.ColumnDouble (4 );
411
408
info.verified = info_sql.ColumnBool (5 );
412
- info.name = info_sql.ColumnString (10 );
413
- info.url = info_sql.ColumnString (11 );
414
- info.provider = info_sql.ColumnString (12 );
415
- info.favicon_url = info_sql.ColumnString (13 );
416
- info.reconcile_stamp = info_sql.ColumnInt64 (14 );
409
+ info.name = info_sql.ColumnString (9 );
410
+ info.url = info_sql.ColumnString (10 );
411
+ info.provider = info_sql.ColumnString (11 );
412
+ info.favicon_url = info_sql.ColumnString (12 );
413
+ info.reconcile_stamp = info_sql.ColumnInt64 (13 );
417
414
418
415
info.excluded = static_cast <ledger::PUBLISHER_EXCLUDE>(info_sql.ColumnInt (6 ));
419
- info.category =
420
- static_cast <ledger::PUBLISHER_CATEGORY>(info_sql.ColumnInt (7 ));
421
416
422
417
list->push_back (info);
423
418
}
@@ -459,9 +454,6 @@ std::string PublisherInfoDatabase::BuildClauses(int start,
459
454
if (!filter.id .empty ())
460
455
clauses += " AND ai.publisher_id = ?" ;
461
456
462
- if (filter.category != ledger::PUBLISHER_CATEGORY::ALL_CATEGORIES)
463
- clauses += " AND ai.category = ?" ;
464
-
465
457
if (filter.month != ledger::PUBLISHER_MONTH::ANY)
466
458
clauses += " AND ai.month = ?" ;
467
459
@@ -505,9 +497,6 @@ void PublisherInfoDatabase::BindFilter(sql::Statement& statement,
505
497
if (!filter.id .empty ())
506
498
statement.BindString (column++, filter.id );
507
499
508
- if (filter.category != ledger::PUBLISHER_CATEGORY::ALL_CATEGORIES)
509
- statement.BindInt (column++, filter.category );
510
-
511
500
if (filter.month != ledger::PUBLISHER_MONTH::ANY)
512
501
statement.BindInt (column++, filter.month );
513
502
@@ -751,6 +740,49 @@ bool PublisherInfoDatabase::MigrateV1toV2() {
751
740
return CreateRecurringDonationIndex ();
752
741
}
753
742
743
+ bool PublisherInfoDatabase::MigrateV2toV3 () {
744
+ DCHECK_CALLED_ON_VALID_SEQUENCE (sequence_checker_);
745
+
746
+ // Activity info
747
+ const char * activity = " activity_info" ;
748
+ if (GetDB ().DoesTableExist (activity)) {
749
+ std::string sql = " ALTER TABLE activity_info RENAME TO activity_info_old;" ;
750
+
751
+ if (!GetDB ().Execute (sql.c_str ())) {
752
+ return false ;
753
+ }
754
+
755
+ if (!CreateActivityInfoTable ()) {
756
+ return false ;
757
+ }
758
+
759
+ if (!CreateActivityInfoIndex ()) {
760
+ return false ;
761
+ }
762
+
763
+ std::string columns = " publisher_id, "
764
+ " duration, "
765
+ " score, "
766
+ " percent, "
767
+ " weight, "
768
+ " month, "
769
+ " year, "
770
+ " reconcile_stamp" ;
771
+
772
+ sql = " PRAGMA foreign_keys=off;" ;
773
+ sql.append (" INSERT INTO activity_info (" + columns + " ) "
774
+ " SELECT " + columns + " "
775
+ " FROM activity_info_old;" );
776
+ sql.append (" UPDATE activity_info SET visits=5;" );
777
+ sql.append (" DROP TABLE activity_info_old;" );
778
+ sql.append (" PRAGMA foreign_keys=on;" );
779
+
780
+ return GetDB ().Execute (sql.c_str ());
781
+ }
782
+
783
+ return false ;
784
+ }
785
+
754
786
sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion () {
755
787
DCHECK_CALLED_ON_VALID_SEQUENCE (sequence_checker_);
756
788
@@ -763,10 +795,32 @@ sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() {
763
795
const int old_version = meta_table_.GetVersionNumber ();
764
796
const int cur_version = GetCurrentVersion ();
765
797
766
- // Migration from version 1 to version 2
767
- if (old_version == 1 && cur_version == 2 ) {
768
- if (!MigrateV1toV2 ()) {
769
- LOG (ERROR) << " DB: Error with MigrateV1toV2" ;
798
+ // Migration from version 1
799
+ if (old_version == 1 ) {
800
+ // to version 2
801
+ if (cur_version < 3 ) {
802
+ if (!MigrateV1toV2 ()) {
803
+ LOG (ERROR) << " DB: Error with MigrateV1toV2" ;
804
+ }
805
+ }
806
+
807
+ // to version 3
808
+ if (cur_version < 4 ) {
809
+ if (!MigrateV2toV3 ()) {
810
+ LOG (ERROR) << " DB: Error with MigrateV2toV3" ;
811
+ }
812
+ }
813
+
814
+ meta_table_.SetVersionNumber (cur_version);
815
+ }
816
+
817
+ // Migration from version 2
818
+ if (old_version == 2 ) {
819
+ // to version 3
820
+ if (cur_version < 4 ) {
821
+ if (!MigrateV2toV3 ()) {
822
+ LOG (ERROR) << " DB: Error with MigrateV2toV3" ;
823
+ }
770
824
}
771
825
772
826
meta_table_.SetVersionNumber (cur_version);
0 commit comments