Page MenuHomePhabricator

D5377.id17607.diff
No OneTemporary

D5377.id17607.diff

diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
@@ -554,29 +554,43 @@
Logger::log(version_msg.str());
for (const auto &[idx, migration] : migrations) {
+ auto db_version = get_database_version(db);
if (idx <= db_version) {
continue;
}
- const auto &[applyMigration, shouldBeInTransaction] = migration;
std::stringstream migration_msg;
+ const auto &[applyMigration, shouldBeInTransaction] = migration;
+ if (!shouldBeInTransaction) {
+ auto rc = applyMigration(db);
+ if (!rc) {
+ migration_msg << "migration " << idx << " failed." << std::endl;
+ Logger::log(migration_msg.str());
+ break;
+ }
+ }
- if (shouldBeInTransaction) {
- sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr);
+ sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr);
+ auto db_version_inside_transaction = get_database_version(db);
+ if (idx <= db_version_inside_transaction) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ continue;
}
auto rc = applyMigration(db);
- if (!rc) {
- migration_msg << "migration " << idx << " failed." << std::endl;
- Logger::log(migration_msg.str());
- break;
+ if (shouldBeInTransaction) {
+ auto rc = applyMigration(db);
+ if (!rc) {
+ migration_msg << "migration " << idx << " failed." << std::endl;
+ Logger::log(migration_msg.str());
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ break;
+ }
}
set_database_version(db, idx);
- if (shouldBeInTransaction) {
- sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr);
- }
+ sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr);
migration_msg << "migration " << idx << " succeeded." << std::endl;
Logger::log(migration_msg.str());
}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 11:48 PM (20 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2495807
Default Alt Text
D5377.id17607.diff (2 KB)

Event Timeline