mirror of https://github.com/stella-emu/stella.git
Add a migration for an old settings DB (R77 style).
This commit is contained in:
parent
20e277c3e4
commit
a9e2a99f53
|
@ -25,7 +25,7 @@
|
||||||
#include "repository/CompositeKVRJsonAdapter.hxx"
|
#include "repository/CompositeKVRJsonAdapter.hxx"
|
||||||
#include "repository/KeyValueRepositoryConfigfile.hxx"
|
#include "repository/KeyValueRepositoryConfigfile.hxx"
|
||||||
#include "KeyValueRepositorySqlite.hxx"
|
#include "KeyValueRepositorySqlite.hxx"
|
||||||
#include "SqliteTransaction.hxx"
|
#include "SqliteStatement.hxx"
|
||||||
#include "FSNode.hxx"
|
#include "FSNode.hxx"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -75,8 +75,6 @@ void SettingsDb::initialize()
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SettingsDb::initializeDb() {
|
void SettingsDb::initializeDb() {
|
||||||
SqliteTransaction tx{*myDb};
|
|
||||||
|
|
||||||
FilesystemNode legacyConfigFile{myDatabaseDirectory};
|
FilesystemNode legacyConfigFile{myDatabaseDirectory};
|
||||||
legacyConfigFile /= "stellarc";
|
legacyConfigFile /= "stellarc";
|
||||||
|
|
||||||
|
@ -88,10 +86,26 @@ void SettingsDb::initializeDb() {
|
||||||
|
|
||||||
mySettingsRepository->save(KeyValueRepositoryConfigfile{legacyConfigFile}.load());
|
mySettingsRepository->save(KeyValueRepositoryConfigfile{legacyConfigFile}.load());
|
||||||
}
|
}
|
||||||
|
else if (legacyConfigDatabase.exists() && legacyConfigDatabase.isFile()) {
|
||||||
|
Logger::info("importing old settings from " + legacyConfigDatabase.getPath());
|
||||||
|
|
||||||
|
try {
|
||||||
|
SqliteStatement(
|
||||||
|
*myDb,
|
||||||
|
"ATTACH DATABASE ? AS old_db"
|
||||||
|
)
|
||||||
|
.bind(1, legacyConfigDatabase.getPath())
|
||||||
|
.step();
|
||||||
|
|
||||||
|
myDb->exec("INSERT INTO `settings` SELECT * FROM `old_db`.`settings`");
|
||||||
|
myDb->exec("DETACH DATABASE `old_db`");
|
||||||
|
}
|
||||||
|
catch (const SqliteError& err) {
|
||||||
|
Logger::error(err.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
myDb->setUserVersion(CURRENT_VERSION);
|
myDb->setUserVersion(CURRENT_VERSION);
|
||||||
|
|
||||||
tx.commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -97,7 +97,6 @@ void SqliteDatabase::exec(const string& sql) const
|
||||||
Int32 SqliteDatabase::getUserVersion() const
|
Int32 SqliteDatabase::getUserVersion() const
|
||||||
{
|
{
|
||||||
SqliteStatement stmt(*this, "PRAGMA user_version");
|
SqliteStatement stmt(*this, "PRAGMA user_version");
|
||||||
stmt.reset();
|
|
||||||
|
|
||||||
if (!stmt.step())
|
if (!stmt.step())
|
||||||
throw SqliteError("failed to get user_version");
|
throw SqliteError("failed to get user_version");
|
||||||
|
@ -108,8 +107,6 @@ Int32 SqliteDatabase::getUserVersion() const
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SqliteDatabase::setUserVersion(Int32 version) const
|
void SqliteDatabase::setUserVersion(Int32 version) const
|
||||||
{
|
{
|
||||||
SqliteStatement stmt(*this, "PRAGMA user_version = %i", static_cast<int>(version));
|
SqliteStatement(*this, "PRAGMA user_version = %i", static_cast<int>(version))
|
||||||
stmt.reset();
|
.step();
|
||||||
|
|
||||||
stmt.step();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue