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
这个提交包含在:
Albert S. 2022-07-28 13:31:11 +02:00
父节点 49b57e1740
当前提交 c03d7da821
共有 1 个文件被更改,包括 9 次插入23 次删除

查看文件

@ -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())
{