| 30 | namespace comm { |
| 31 | |
| 32 | void SQLiteQueryExecutor::migrate() const { |
| 33 | this->connectionManager->validateEncryption(); |
| 34 | |
| 35 | std::stringstream db_path; |
| 36 | db_path << "db path: " << this->connectionManager->getSQLiteFilePath() |
| 37 | << std::endl; |
| 38 | Logger::log(db_path.str()); |
| 39 | |
| 40 | sqlite3 *db = this->connectionManager->getEphemeralConnection(); |
| 41 | |
| 42 | auto db_version = SQLiteUtils::getDatabaseVersion(db); |
| 43 | std::stringstream version_msg; |
| 44 | version_msg << "db version: " << db_version << std::endl; |
| 45 | Logger::log(version_msg.str()); |
| 46 | |
| 47 | if (db_version == 0) { |
| 48 | auto db_created = SQLiteSchema::setupDatabase(db); |
| 49 | if (!db_created) { |
| 50 | sqlite3_close(db); |
| 51 | Logger::log("Database structure creation error."); |
| 52 | throw std::runtime_error("Database structure creation error"); |
| 53 | } |
| 54 | Logger::log("Database structure created."); |
| 55 | |
| 56 | sqlite3_close(db); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | SQLiteSchema::migrate(db); |
| 61 | sqlite3_close(db); |
| 62 | } |
| 63 | |
| 64 | SQLiteQueryExecutor::SQLiteQueryExecutor( |
| 65 | std::shared_ptr<SQLiteConnectionManager> connectionManager, |
no test coverage detected