Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33025841
D5379.1768394225.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D5379.1768394225.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
@@ -663,6 +663,39 @@
return MigrationResult::SUCCESS;
}
+bool set_up_database(sqlite3 *db) {
+ auto write_ahead_enabled = enable_write_ahead_logging_mode(db);
+ if (!write_ahead_enabled) {
+ return false;
+ }
+
+ sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr);
+ auto db_version = get_database_version(db);
+ auto latest_version = migrations.back().first;
+ if (db_version == latest_version) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ return true;
+ }
+ if (db_version != 0) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ return false;
+ }
+
+ auto tables_created = create_schema(db);
+ if (!tables_created) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ return false;
+ }
+
+ auto database_version_set = set_database_version(db, latest_version);
+ if (!database_version_set) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ return false;
+ }
+ sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr);
+ return true;
+}
+
void SQLiteQueryExecutor::migrate() const {
validate_encryption();
@@ -680,6 +713,14 @@
version_msg << "db version: " << db_version << std::endl;
Logger::log(version_msg.str());
+ if (db_version == 0) {
+ set_up_database(db);
+ Logger::log("Database structure created.");
+
+ sqlite3_close(db);
+ return;
+ }
+
for (const auto &[idx, migration] : migrations) {
const auto &[applyMigration, shouldBeInTransaction] = migration;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 14, 12:37 PM (3 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5932056
Default Alt Text
D5379.1768394225.diff (1 KB)
Attached To
Mode
D5379: [native/sqlite] introduce function to set up database
Attached
Detach File
Event Timeline
Log In to Comment