diff --git a/shared/common.cpp b/shared/common.cpp index fb7d43c..f7ce2fa 100644 --- a/shared/common.cpp +++ b/shared/common.cpp @@ -22,17 +22,18 @@ inline void initResources() bool Common::initSqliteDatabase(QString path) { - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); - db.setDatabaseName(path); - if(!db.open()) + try { - qDebug() << "failed to open database: " << path; + initResources(); + DatabaseFactory factory(path); + DBMigrator migrator{factory}; + migrator.performMigrations(); + } + catch(std::exception &ex) + { + Logger::error() << "Failed to init dabase: " << ex.what(); return false; } - initResources(); - DBMigrator migrator{db}; - migrator.performMigrations(); - db.close(); return true; } @@ -89,21 +90,6 @@ void Common::ensureConfigured() } settings.setValue(SETTINGS_KEY_DBPATH, dbpath); } - DatabaseFactory factory{dbpath}; - auto db = factory.forCurrentThread(); - DBMigrator migrator{db}; - if(migrator.migrationNeeded()) - { - QFile out; - out.open(stderr, QIODevice::WriteOnly); - Logger migrationLogger{&out}; - migrationLogger << "Database is being upgraded, please be patient..." << Qt::endl; - QObject::connect(&migrator, &DBMigrator::migrationDone, - [&migrationLogger](uint32_t migration) - { migrationLogger << "Progress: Successfully migrated to: " << migration << Qt::endl; }); - migrator.performMigrations(); - migrationLogger << "Database upgraded successfully" << Qt::endl; - } QVariant pdfViewer = settings.value(SETTINGS_KEY_PDFVIEWER); if(!pdfViewer.isValid()) {