summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/pipeline.cpp4
-rw-r--r--common/storage/entitystore.cpp9
-rw-r--r--common/storage/entitystore.h2
-rw-r--r--common/storage_lmdb.cpp3
4 files changed, 14 insertions, 4 deletions
diff --git a/common/pipeline.cpp b/common/pipeline.cpp
index 434f732..ee9d3af 100644
--- a/common/pipeline.cpp
+++ b/common/pipeline.cpp
@@ -63,9 +63,7 @@ public:
63Pipeline::Pipeline(const ResourceContext &context, const Sink::Log::Context &ctx) : QObject(nullptr), d(new Private(context, ctx)) 63Pipeline::Pipeline(const ResourceContext &context, const Sink::Log::Context &ctx) : QObject(nullptr), d(new Private(context, ctx))
64{ 64{
65 //Create main store immediately on first start 65 //Create main store immediately on first start
66 auto store = Sink::Storage::DataStore(Sink::storageLocation(), context.instanceId(), Sink::Storage::DataStore::ReadWrite); 66 d->entityStore.createIfMissing();
67 auto t = store.createTransaction(Storage::DataStore::ReadWrite);
68 Storage::DataStore::setDatabaseVersion(t, Sink::latestDatabaseVersion());
69} 67}
70 68
71Pipeline::~Pipeline() 69Pipeline::~Pipeline()
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index 7da7efa..6021344 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -158,6 +158,15 @@ EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx
158 158
159} 159}
160 160
161void EntityStore::createIfMissing()
162{
163 if (!d->exists()) {
164 startTransaction(Sink::Storage::DataStore::ReadWrite);
165 Storage::DataStore::setDatabaseVersion(d->transaction, Sink::latestDatabaseVersion());
166 commitTransaction();
167 }
168}
169
161void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) 170void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode)
162{ 171{
163 SinkTraceCtx(d->logCtx) << "Starting transaction: " << accessMode; 172 SinkTraceCtx(d->logCtx) << "Starting transaction: " << accessMode;
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h
index 3eb0b7b..985e7f9 100644
--- a/common/storage/entitystore.h
+++ b/common/storage/entitystore.h
@@ -39,6 +39,8 @@ public:
39 EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &); 39 EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &);
40 ~EntityStore() = default; 40 ~EntityStore() = default;
41 41
42 void createIfMissing();
43
42 //Only the pipeline may call the following functions outside of tests 44 //Only the pipeline may call the following functions outside of tests
43 bool add(const QByteArray &type, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource); 45 bool add(const QByteArray &type, ApplicationDomain::ApplicationDomainType newEntity, bool replayToSource);
44 bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource); 46 bool modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource);
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 4e7f322..9d0bd6b 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -918,7 +918,8 @@ DataStore::~DataStore()
918 918
919bool DataStore::exists() const 919bool DataStore::exists() const
920{ 920{
921 return (d->env != 0); 921 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb");
922 return (d->env != 0) && info.exists();
922} 923}
923 924
924DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function<void(const DataStore::Error &error)> &errorHandlerArg) 925DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function<void(const DataStore::Error &error)> &errorHandlerArg)