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:
@@ -238,14 +238,19 @@ FilePath PersistentStorage::getDbFilePath() const
|
||||
return m_sqliteStorage.getDbFilePath();
|
||||
}
|
||||
|
||||
Version PersistentStorage::getVersion() const
|
||||
bool PersistentStorage::isEmpty() const
|
||||
{
|
||||
return m_sqliteStorage.getVersion();
|
||||
return m_sqliteStorage.isEmpty();
|
||||
}
|
||||
|
||||
void PersistentStorage::init()
|
||||
bool PersistentStorage::isIncompatible() const
|
||||
{
|
||||
m_sqliteStorage.init();
|
||||
return m_sqliteStorage.isIncompatible();
|
||||
}
|
||||
|
||||
void PersistentStorage::setup()
|
||||
{
|
||||
m_sqliteStorage.setup();
|
||||
}
|
||||
|
||||
void PersistentStorage::clear()
|
||||
@@ -365,7 +370,7 @@ void PersistentStorage::startParsing()
|
||||
{
|
||||
MessageClearErrorCount().dispatch();
|
||||
|
||||
m_sqliteStorage.setVersion(Version::getApplicationVersion());
|
||||
m_sqliteStorage.setVersion();
|
||||
}
|
||||
|
||||
void PersistentStorage::finishParsing()
|
||||
|
||||
@@ -49,9 +49,11 @@ public:
|
||||
virtual void finishInjection();
|
||||
|
||||
FilePath getDbFilePath() const;
|
||||
Version getVersion() const;
|
||||
|
||||
void init();
|
||||
bool isEmpty() const;
|
||||
bool isIncompatible() const;
|
||||
|
||||
void setup();
|
||||
void clear();
|
||||
void clearCaches();
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -24,7 +24,6 @@ public:
|
||||
SqliteStorage(const FilePath& dbFilePath);
|
||||
~SqliteStorage();
|
||||
|
||||
void init();
|
||||
void setup();
|
||||
void clear();
|
||||
|
||||
@@ -34,8 +33,10 @@ public:
|
||||
|
||||
FilePath getDbFilePath() const;
|
||||
|
||||
Version getVersion() const;
|
||||
void setVersion(const Version& version);
|
||||
bool isEmpty() const;
|
||||
bool isIncompatible() const;
|
||||
|
||||
void setVersion();
|
||||
|
||||
Id addEdge(int type, Id sourceNodeId, Id targetNodeId);
|
||||
Id addNode(int type, const std::string& serializedName, int definitionType);
|
||||
@@ -118,6 +119,8 @@ public:
|
||||
int getSourceLocationCount() const;
|
||||
|
||||
private:
|
||||
static const size_t STORAGE_VERSION;
|
||||
|
||||
void clearTables();
|
||||
void setupTables();
|
||||
|
||||
@@ -126,6 +129,12 @@ private:
|
||||
std::string getMetaValue(const std::string& key) const;
|
||||
void insertOrUpdateMetaValue(const std::string& key, const std::string& value);
|
||||
|
||||
size_t getStorageVersion() const;
|
||||
void setStorageVersion();
|
||||
|
||||
Version getApplicationVersion() const;
|
||||
void setApplicationVersion();
|
||||
|
||||
template <typename ResultType>
|
||||
std::vector<ResultType> getAll(const std::string& query) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user