From c03d7da8215a47c9d37168fc7b00130268f046f6 Mon Sep 17 00:00:00 2001 From: Albert S Date: Thu, 28 Jul 2022 13:31:11 +0200 Subject: [PATCH] shared: common: Remove migration logic from ensureConfigured() Running migrations is okay for initialization. However, doing it here might take ages, so the GUI simply would not show up. Therefore, migration must be done by the CLI or GUI and they should show that migrations are running --- shared/common.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) 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()) {