Skip to content

Commit

Permalink
Adds migration for min visits
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Feb 8, 2019
1 parent 64b2466 commit 742add5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion components/brave_rewards/browser/publisher_info_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace brave_rewards {

namespace {

const int kCurrentVersionNumber = 4;
const int kCurrentVersionNumber = 5;
const int kCompatibleVersionNumber = 1;

} // namespace
Expand Down Expand Up @@ -1054,6 +1054,33 @@ bool PublisherInfoDatabase::MigrateV3toV4() {
return false;
}

bool PublisherInfoDatabase::MigrateV4toV5() {
sql::Transaction transaction(&GetDB());
if (!transaction.Begin()) {
return false;
}

sql::Statement info_sql(db_.GetUniqueStatement(
"SELECT publisher_id, month, year, reconcile_stamp "
"FROM activity_info "
"WHERE visits = 0"));

while (info_sql.Step()) {
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"UPDATE activity_info SET visits = 1 "
"WHERE publisher_id = ? AND month = ? AND "
"year = ? AND reconcile_stamp = ?"));

statement.BindString(0, info_sql.ColumnString(0));
statement.BindInt(1, info_sql.ColumnInt(1));
statement.BindInt(2, info_sql.ColumnInt(2));
statement.BindInt64(3, info_sql.ColumnInt64(3));
statement.Run();
}

return transaction.Commit();
}

sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

Expand Down Expand Up @@ -1087,6 +1114,13 @@ sql::InitStatus PublisherInfoDatabase::EnsureCurrentVersion() {
}
}

// to version 5
if (old_version < 5 && cur_version < 6) {
if (!MigrateV4toV5()) {
LOG(ERROR) << "DB: Error with MigrateV4toV5";
}
}

meta_table_.SetVersionNumber(cur_version);
return sql::INIT_OK;
}
Expand Down
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/publisher_info_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class PublisherInfoDatabase {

bool MigrateV3toV4();

bool MigrateV4toV5();

sql::InitStatus EnsureCurrentVersion();

sql::Database db_;
Expand Down

0 comments on commit 742add5

Please sign in to comment.