Skip to content

Commit

Permalink
[Character] Fix character copier due to schema change (#3805)
Browse files Browse the repository at this point in the history
* [Character] Fix character copier due to schema change

* Tweak
  • Loading branch information
Akkadius authored Dec 28, 2023
1 parent 51cd43b commit 52763b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion common/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,11 @@ bool Database::CopyCharacter(
row = results.begin();
std::string new_character_id = row[0];

std::vector<std::string> tables_to_zero_id = {
"keyring",
"data_buckets",
};

TransactionBegin();
for (const auto &iter : DatabaseSchema::GetCharacterTables()) {
std::string table_name = iter.first;
Expand Down Expand Up @@ -2279,6 +2284,10 @@ bool Database::CopyCharacter(
std::string column = columns[column_index];
std::string value = row[column_index] ? row[column_index] : "null";

if (column == "id" && Strings::Contains(tables_to_zero_id, table_name)) {
value = "0";
}

if (column == character_id_column_name) {
value = new_character_id;
}
Expand Down Expand Up @@ -2326,7 +2335,6 @@ bool Database::CopyCharacter(
if (!insert.ErrorMessage().empty()) {
TransactionRollback();
return false;
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/database_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace DatabaseSchema {
{"character_tasks", "charid"},
{"character_tribute", "character_id"},
{"completed_tasks", "charid"},
{"data_buckets", "id"},
{"data_buckets", "character_id"},
{"faction_values", "char_id"},
{"friends", "charid"},
{"guild_members", "char_id"},
Expand Down

0 comments on commit 52763b6

Please sign in to comment.