mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:56:22 +00:00
UI: SqliteDb: Simplify migrate()
This commit is contained in:
parent
96cd249c6f
commit
424e68ae14
23
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
23
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
@ -309,6 +309,21 @@ bool SqliteDb::migrate(MigrateOptions &opt)
|
||||
if (userVersion == opt.version)
|
||||
return true;
|
||||
|
||||
// Check migration options
|
||||
if (!canMigrate(opt, userVersion))
|
||||
return false;
|
||||
|
||||
// Migrate the DB
|
||||
bool isNewDb = (userVersion == 0);
|
||||
if (isNewDb) {
|
||||
opt.recreate = false;
|
||||
}
|
||||
|
||||
return migrateDb(opt, userVersion, isNewDb);
|
||||
}
|
||||
|
||||
bool SqliteDb::canMigrate(const MigrateOptions &opt, int userVersion) const
|
||||
{
|
||||
if (userVersion > opt.version) {
|
||||
qCWarning(LC) << "Cannot open new DB" << userVersion << "from old application"
|
||||
<< opt.version;
|
||||
@ -320,11 +335,11 @@ bool SqliteDb::migrate(MigrateOptions &opt)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isNewDb = (userVersion == 0);
|
||||
if (isNewDb) {
|
||||
opt.recreate = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SqliteDb::migrateDb(const MigrateOptions &opt, int userVersion, bool isNewDb)
|
||||
{
|
||||
// Re-create the DB
|
||||
if (opt.recreate) {
|
||||
if (!clearWithBackup(opt.sqlPragmas))
|
||||
|
2
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
2
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
@ -110,6 +110,8 @@ public:
|
||||
SqliteStmt *stmt(const char *sql);
|
||||
|
||||
private:
|
||||
bool canMigrate(const MigrateOptions &opt, int userVersion) const;
|
||||
bool migrateDb(const MigrateOptions &opt, int userVersion, bool isNewDb);
|
||||
bool migrateSqlScripts(const MigrateOptions &opt, int userVersion, bool isNewDb);
|
||||
|
||||
bool clearWithBackup(const char *sqlPragmas);
|
||||
|
Loading…
Reference in New Issue
Block a user