Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3246441
D5377.id17607.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D5377.id17607.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D5377: [native/sqlite] refactor code to perform migration inside one transaction
Attached
Detach File
Event Timeline
Log In to Comment