mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:06:30 +00:00
DB: Improve migration checks.
This commit is contained in:
parent
ea9904b0f4
commit
a32d78d8b1
23
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
23
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
@ -177,6 +177,12 @@ bool SqliteDb::migrate(const QString &sqlDir, int version,
|
||||
if (userVersion == version)
|
||||
return true;
|
||||
|
||||
if (userVersion > version) {
|
||||
qWarning() << "SQLite: Cannot open new DB" << userVersion
|
||||
<< "from old code" << version;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Run migration SQL scripts
|
||||
QDir dir(sqlDir);
|
||||
bool res = true;
|
||||
@ -186,19 +192,24 @@ bool SqliteDb::migrate(const QString &sqlDir, int version,
|
||||
const QString filePath = dir.filePath(QString::number(i) + ".sql");
|
||||
|
||||
QFile file(filePath);
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text))
|
||||
continue;
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qWarning() << "SQLite: Cannot open migration file" << filePath;
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
|
||||
const QByteArray data = file.readAll();
|
||||
if (data.isEmpty())
|
||||
continue;
|
||||
if (data.isEmpty()) {
|
||||
qWarning() << "SQLite: Migration file is empty" << filePath;
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
|
||||
beginSavepoint();
|
||||
if (!execute(data.constData())
|
||||
|| !(migrateFunc == nullptr
|
||||
|| migrateFunc(this, i, migrateContext))) {
|
||||
qWarning() << "SQLite: Migrate error:" << filePath << errorMessage();
|
||||
|
||||
qWarning() << "SQLite: Migration error:" << filePath << errorMessage();
|
||||
res = false;
|
||||
rollbackSavepoint();
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user