data: Store separate storage version number in SqliteStorage for managing migrations

* deprecated the third version number as storage update number
* version can now have either 3 or 4 numbers
* whether a .coatidb file is outdated is now solely determined by the SqliteStorage::STORAGE_VERSION
This commit is contained in:
Eberhard Graether
2016-07-20 14:14:21 +02:00
parent eb8808b624
commit cb869c2465
8 changed files with 103 additions and 78 deletions
+56 -22
View File
@@ -11,6 +11,8 @@
#include "utility/utilityString.h"
#include "utility/Version.h"
const size_t SqliteStorage::STORAGE_VERSION = 1;
SqliteStorage::SqliteStorage(const FilePath& dbFilePath)
: m_dbFilePath(dbFilePath)
{
@@ -31,20 +33,6 @@ SqliteStorage::~SqliteStorage()
}
}
void SqliteStorage::init()
{
Version version = getVersion();
if (version.isEmpty())
{
setup();
}
else if (version.isDifferentStorageVersionThan(Version::getApplicationVersion()))
{
clear();
}
}
void SqliteStorage::setup()
{
m_database.execDML("PRAGMA foreign_keys=ON;");
@@ -79,21 +67,33 @@ FilePath SqliteStorage::getDbFilePath() const
return m_dbFilePath;
}
Version SqliteStorage::getVersion() const
bool SqliteStorage::isEmpty() const
{
std::string versionStr = getMetaValue("version");
if (versionStr.size())
size_t storageVersion = getStorageVersion();
if (storageVersion > 0)
{
return Version::fromString(versionStr);
return false;
}
return Version();
Version applicationVersion = getApplicationVersion();
return applicationVersion.isEmpty();
}
void SqliteStorage::setVersion(const Version& version)
bool SqliteStorage::isIncompatible() const
{
insertOrUpdateMetaValue("version", version.toString());
size_t storageVersion = getStorageVersion();
if (storageVersion == 0 || storageVersion != STORAGE_VERSION)
{
return true;
}
return false;
}
void SqliteStorage::setVersion()
{
setStorageVersion();
setApplicationVersion();
}
Id SqliteStorage::addEdge(int type, Id sourceNodeId, Id targetNodeId)
@@ -797,6 +797,40 @@ void SqliteStorage::insertOrUpdateMetaValue(const std::string& key, const std::s
).c_str());
}
size_t SqliteStorage::getStorageVersion() const
{
std::string storageVersionStr = getMetaValue("storage_version");
if (storageVersionStr.size())
{
return std::stoi(storageVersionStr);
}
return 0;
}
void SqliteStorage::setStorageVersion()
{
insertOrUpdateMetaValue("storage_version", std::to_string(STORAGE_VERSION));
}
Version SqliteStorage::getApplicationVersion() const
{
std::string versionStr = getMetaValue("version");
if (versionStr.size())
{
return Version::fromString(versionStr);
}
return Version();
}
void SqliteStorage::setApplicationVersion()
{
insertOrUpdateMetaValue("version", Version::getApplicationVersion().toString());
}
template <>
std::vector<StorageFile> SqliteStorage::getAll<StorageFile>(const std::string& query) const
{