data: Fixed version check when opening older db

This commit is contained in:
Eberhard Graether
2016-01-08 14:51:11 +01:00
parent ffca8841ea
commit b8faa5506d
7 changed files with 42 additions and 15 deletions
+1 -6
View File
@@ -150,12 +150,7 @@ void Project::setProjectSettingsFilePath(const FilePath& path)
if (!m_storage || !dbPath.exists())
{
m_storage = std::make_shared<Storage>(dbPath);
}
if (m_storageWasLoaded && m_storage->getVersion().isOlderStorageVersionThan(Version::getApplicationVersion()))
{
m_storage->clear();
m_storageWasLoaded = false;
m_storageWasLoaded = m_storage->init();
}
}
+22 -3
View File
@@ -11,7 +11,6 @@
SqliteStorage::SqliteStorage(const std::string& dbFilePath)
{
m_database.open(dbFilePath.c_str());
setup();
}
SqliteStorage::~SqliteStorage()
@@ -19,6 +18,26 @@ SqliteStorage::~SqliteStorage()
m_database.close();
}
bool SqliteStorage::init()
{
Version version = getVersion();
if (version.isEmpty())
{
setup();
return false;
}
else if (version.isOlderStorageVersionThan(Version::getApplicationVersion()))
{
clear();
return false;
}
else
{
return true;
}
}
void SqliteStorage::setup()
{
m_database.execDML("PRAGMA foreign_keys=ON;");
@@ -688,8 +707,8 @@ void SqliteStorage::setupTables()
"defined INTEGER NOT NULL, "
"PRIMARY KEY(id), "
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
);
);
m_database.execDML(
"CREATE INDEX IF NOT EXISTS node_serializedName_index ON node(serializedName);"
);
+1
View File
@@ -23,6 +23,7 @@ public:
SqliteStorage(const std::string& dbFilePath);
~SqliteStorage();
bool init();
void setup();
void clear();
+7 -2
View File
@@ -9,6 +9,7 @@
#include "utility/TimePoint.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
#include "utility/Version.h"
#include "data/graph/token_component/TokenComponentAggregation.h"
#include "data/graph/token_component/TokenComponentSignature.h"
@@ -22,7 +23,6 @@
#include "data/parser/ParseVariable.h"
#include "data/type/DataType.h"
#include "settings/ApplicationSettings.h"
#include "utility/Version.h"
Storage::Storage(const FilePath& dbPath)
: m_sqliteStorage(dbPath.str())
@@ -38,6 +38,11 @@ Version Storage::getVersion() const
return m_sqliteStorage.getVersion();
}
bool Storage::init()
{
return m_sqliteStorage.init();
}
void Storage::clear()
{
m_sqliteStorage.clear();
@@ -761,7 +766,7 @@ Id Storage::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) co
Id Storage::getIdForEdge(
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy
) const
) const
{
Id sourceId = getIdForNodeWithNameHierarchy(fromNameHierarchy);
Id targetId = getIdForNodeWithNameHierarchy(toNameHierarchy);
+1
View File
@@ -24,6 +24,7 @@ public:
Version getVersion() const;
bool init();
void clear();
void clearCaches();
+7 -2
View File
@@ -54,7 +54,12 @@ Version::Version()
{
}
bool Version::operator<(const Version& other)
bool Version::isEmpty() const
{
return m_majorNumber == 0 && m_minorNumber == 0 && m_refreshNumber == 0 && m_commitNumber == 0;
}
bool Version::operator<(const Version& other) const
{
if (m_majorNumber != other.m_majorNumber)
{
@@ -78,7 +83,7 @@ bool Version::operator<(const Version& other)
}
}
bool Version::isOlderStorageVersionThan(const Version& other)
bool Version::isOlderStorageVersionThan(const Version& other) const
{
if (m_majorNumber != other.m_majorNumber)
{
+3 -2
View File
@@ -13,8 +13,9 @@ public:
Version();
bool operator<(const Version& other);
bool isOlderStorageVersionThan(const Version& other);
bool isEmpty() const;
bool operator<(const Version& other) const;
bool isOlderStorageVersionThan(const Version& other) const;
std::string toString() const;
std::string toDisplayString() const;