data: Fixed version check when opening older db
This commit is contained in:
+1
-6
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);"
|
||||
);
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
SqliteStorage(const std::string& dbFilePath);
|
||||
~SqliteStorage();
|
||||
|
||||
bool init();
|
||||
void setup();
|
||||
void clear();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
|
||||
Version getVersion() const;
|
||||
|
||||
bool init();
|
||||
void clear();
|
||||
void clearCaches();
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user