@@ -22,7 +22,7 @@ namespace brave_rewards {
22
22
23
23
namespace {
24
24
25
- const int kCurrentVersionNumber = 3 ;
25
+ const int kCurrentVersionNumber = 4 ;
26
26
const int kCompatibleVersionNumber = 1 ;
27
27
28
28
} // namespace
@@ -154,10 +154,10 @@ bool PublisherInfoDatabase::CreateActivityInfoTable() {
154
154
" ("
155
155
" publisher_id LONGVARCHAR NOT NULL,"
156
156
" duration INTEGER DEFAULT 0 NOT NULL,"
157
+ " visits INTEGER DEFAULT 0 NOT NULL,"
157
158
" score DOUBLE DEFAULT 0 NOT NULL,"
158
159
" percent INTEGER DEFAULT 0 NOT NULL,"
159
160
" weight DOUBLE DEFAULT 0 NOT NULL,"
160
- " category INTEGER NOT NULL,"
161
161
" month INTEGER NOT NULL,"
162
162
" year INTEGER NOT NULL,"
163
163
" reconcile_stamp INTEGER DEFAULT 0 NOT NULL,"
@@ -265,33 +265,31 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
265
265
266
266
sql::Statement activity_get (
267
267
db_.GetUniqueStatement (" SELECT publisher_id FROM activity_info WHERE "
268
- " publisher_id=? AND category =? "
269
- " AND month=? AND year=? AND reconcile_stamp=?" ));
268
+ " publisher_id=? AND month =? "
269
+ " AND year=? AND reconcile_stamp=?" ));
270
270
271
271
activity_get.BindString (0 , info.id );
272
- activity_get.BindInt (1 , info.category );
273
- activity_get.BindInt (2 , info.month );
274
- activity_get.BindInt (3 , info.year );
275
- activity_get.BindInt64 (4 , info.reconcile_stamp );
272
+ activity_get.BindInt (1 , info.month );
273
+ activity_get.BindInt (2 , info.year );
274
+ activity_get.BindInt64 (3 , info.reconcile_stamp );
276
275
277
276
if (activity_get.Step ()) {
278
277
sql::Statement activity_info_update (
279
278
GetDB ().GetCachedStatement (SQL_FROM_HERE,
280
279
" UPDATE activity_info SET "
281
280
" duration=?, score=?, percent=?, "
282
281
" weight=? WHERE "
283
- " publisher_id=? AND category =? "
284
- " AND month=? AND year=? AND reconcile_stamp=?" ));
282
+ " publisher_id=? AND month =? "
283
+ " AND year=? AND reconcile_stamp=?" ));
285
284
286
285
activity_info_update.BindInt64 (0 , (int )info.duration );
287
286
activity_info_update.BindDouble (1 , info.score );
288
287
activity_info_update.BindInt64 (2 , (int )info.percent );
289
288
activity_info_update.BindDouble (3 , info.weight );
290
289
activity_info_update.BindString (4 , info.id );
291
- activity_info_update.BindInt (5 , info.category );
292
- activity_info_update.BindInt (6 , info.month );
293
- activity_info_update.BindInt (7 , info.year );
294
- activity_info_update.BindInt64 (8 , info.reconcile_stamp );
290
+ activity_info_update.BindInt (5 , info.month );
291
+ activity_info_update.BindInt (6 , info.year );
292
+ activity_info_update.BindInt64 (7 , info.reconcile_stamp );
295
293
296
294
return activity_info_update.Run ();
297
295
}
@@ -300,18 +298,17 @@ bool PublisherInfoDatabase::InsertOrUpdatePublisherInfo(
300
298
GetDB ().GetCachedStatement (SQL_FROM_HERE,
301
299
" INSERT INTO activity_info "
302
300
" (publisher_id, duration, score, percent, "
303
- " weight, category, month, year, reconcile_stamp) "
301
+ " weight, month, year, reconcile_stamp) "
304
302
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" ));
305
303
306
304
activity_info_insert.BindString (0 , info.id );
307
305
activity_info_insert.BindInt64 (1 , (int )info.duration );
308
306
activity_info_insert.BindDouble (2 , info.score );
309
307
activity_info_insert.BindInt64 (3 , (int )info.percent );
310
308
activity_info_insert.BindDouble (4 , info.weight );
311
- activity_info_insert.BindInt (5 , info.category );
312
- activity_info_insert.BindInt (6 , info.month );
313
- activity_info_insert.BindInt (7 , info.year );
314
- activity_info_insert.BindInt64 (8 , info.reconcile_stamp );
309
+ activity_info_insert.BindInt (5 , info.month );
310
+ activity_info_insert.BindInt (6 , info.year );
311
+ activity_info_insert.BindInt64 (7 , info.reconcile_stamp );
315
312
316
313
return activity_info_insert.Run ();
317
314
}
@@ -386,7 +383,7 @@ bool PublisherInfoDatabase::Find(int start,
386
383
return false ;
387
384
388
385
std::string query = " SELECT ai.publisher_id, ai.duration, ai.score, ai.percent, "
389
- " ai.weight, pi.verified, pi.excluded, ai.category, ai. month, ai.year, pi.name, "
386
+ " ai.weight, pi.verified, pi.excluded, ai.month, ai.year, pi.name, "
390
387
" pi.url, pi.provider, pi.favIcon, ai.reconcile_stamp "
391
388
" FROM activity_info AS ai "
392
389
" INNER JOIN publisher_info AS pi ON ai.publisher_id = pi.publisher_id "
@@ -401,8 +398,8 @@ bool PublisherInfoDatabase::Find(int start,
401
398
while (info_sql.Step ()) {
402
399
std::string id (info_sql.ColumnString (0 ));
403
400
ledger::PUBLISHER_MONTH month (
404
- static_cast <ledger::PUBLISHER_MONTH>(info_sql.ColumnInt (8 )));
405
- int year (info_sql.ColumnInt (9 ));
401
+ static_cast <ledger::PUBLISHER_MONTH>(info_sql.ColumnInt (7 )));
402
+ int year (info_sql.ColumnInt (8 ));
406
403
407
404
ledger::PublisherInfo info (id, month, year);
408
405
info.duration = info_sql.ColumnInt64 (1 );
@@ -411,15 +408,13 @@ bool PublisherInfoDatabase::Find(int start,
411
408
info.percent = info_sql.ColumnInt64 (3 );
412
409
info.weight = info_sql.ColumnDouble (4 );
413
410
info.verified = info_sql.ColumnBool (5 );
414
- info.name = info_sql.ColumnString (10 );
415
- info.url = info_sql.ColumnString (11 );
416
- info.provider = info_sql.ColumnString (12 );
417
- info.favicon_url = info_sql.ColumnString (13 );
418
- info.reconcile_stamp = info_sql.ColumnInt64 (14 );
411
+ info.name = info_sql.ColumnString (9 );
412
+ info.url = info_sql.ColumnString (10 );
413
+ info.provider = info_sql.ColumnString (11 );
414
+ info.favicon_url = info_sql.ColumnString (12 );
415
+ info.reconcile_stamp = info_sql.ColumnInt64 (13 );
419
416
420
417
info.excluded = static_cast <ledger::PUBLISHER_EXCLUDE>(info_sql.ColumnInt (6 ));
421
- info.category =
422
- static_cast <ledger::PUBLISHER_CATEGORY>(info_sql.ColumnInt (7 ));
423
418
424
419
list->push_back (info);
425
420
}
@@ -461,9 +456,6 @@ std::string PublisherInfoDatabase::BuildClauses(int start,
461
456
if (!filter.id .empty ())
462
457
clauses += " AND ai.publisher_id = ?" ;
463
458
464
- if (filter.category != ledger::PUBLISHER_CATEGORY::ALL_CATEGORIES)
465
- clauses += " AND ai.category = ?" ;
466
-
467
459
if (filter.month != ledger::PUBLISHER_MONTH::ANY)
468
460
clauses += " AND ai.month = ?" ;
469
461
@@ -515,9 +507,6 @@ void PublisherInfoDatabase::BindFilter(sql::Statement& statement,
515
507
if (!filter.id .empty ())
516
508
statement.BindString (column++, filter.id );
517
509
518
- if (filter.category != ledger::PUBLISHER_CATEGORY::ALL_CATEGORIES)
519
- statement.BindInt (column++, filter.category );
520
-
521
510
if (filter.month != ledger::PUBLISHER_MONTH::ANY)
522
511
statement.BindInt (column++, filter.month );
523
512
@@ -865,6 +854,49 @@ bool PublisherInfoDatabase::MigrateV2toV3() {
865
854
return CreatePendingContributionsIndex ();
866
855
}
867
856
857
+ bool PublisherInfoDatabase::MigrateV3toV4 () {
858
+ DCHECK_CALLED_ON_VALID_SEQUENCE (sequence_checker_);
859
+
860
+ // Activity info
861
+ const char * activity = " activity_info" ;
862
+ if (GetDB ().DoesTableExist (activity)) {
863
+ std::string sql = " ALTER TABLE activity_info RENAME TO activity_info_old;" ;
864
+
865
+ if (!GetDB ().Execute (sql.c_str ())) {
866
+ return false ;
867
+ }
868
+
869
+ if (!CreateActivityInfoTable ()) {
870
+ return false ;
871
+ }
872
+
873
+ if (!CreateActivityInfoIndex ()) {
874
+ return false ;
875
+ }
876
+
877
+ std::string columns = " publisher_id, "
878
+ " duration, "
879
+ " score, "
880
+ " percent, "
881
+ " weight, "
882
+ " month, "
883
+ " year, "
884
+ " reconcile_stamp" ;
885
+
886
+ sql = " PRAGMA foreign_keys=off;" ;
887
+ sql.append (" INSERT INTO activity_info (" + columns + " ) "
888
+ " SELECT " + columns + " "
889
+ " FROM activity_info_old;" );
890
+ sql.append (" UPDATE activity_info SET visits=5;" );
891
+ sql.append (" DROP TABLE activity_info_old;" );
892
+ sql.append (" PRAGMA foreign_keys=on;" );
893
+
894
+ return GetDB ().Execute (sql.c_str ());
895
+ }
896
+
897
+ return false ;
898
+ }
899
+
868
900
sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion () {
869
901
DCHECK_CALLED_ON_VALID_SEQUENCE (sequence_checker_);
870
902
@@ -891,6 +923,13 @@ sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() {
891
923
}
892
924
}
893
925
926
+ // to version 4
927
+ if (old_version < 4 && cur_version < 5 ) {
928
+ if (!MigrateV2toV3 ()) {
929
+ LOG (ERROR) << " DB: Error with MigrateV3toV4" ;
930
+ }
931
+ }
932
+
894
933
meta_table_.SetVersionNumber (cur_version);
895
934
return sql::INIT_OK;
896
935
}
0 commit comments