diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-26 13:33:17 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-26 13:33:17 +0200 |
commit | 29f80e6e4d698217933b7bd2df90c08162416d3f (patch) | |
tree | 324c496b016b694a3ee963e7ff29d21dcc36426c | |
parent | a9c40f85cf9487ab684c35d564a603e28ae63066 (diff) | |
download | sink-29f80e6e4d698217933b7bd2df90c08162416d3f.tar.gz sink-29f80e6e4d698217933b7bd2df90c08162416d3f.zip |
Don't just set the db version, only when we create the db first.
-rw-r--r-- | common/pipeline.cpp | 4 | ||||
-rw-r--r-- | common/storage/entitystore.cpp | 9 | ||||
-rw-r--r-- | common/storage/entitystore.h | 2 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 3 |
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: | |||
63 | Pipeline::Pipeline(const ResourceContext &context, const Sink::Log::Context &ctx) : QObject(nullptr), d(new Private(context, ctx)) | 63 | Pipeline::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 | ||
71 | Pipeline::~Pipeline() | 69 | Pipeline::~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 | ||
161 | void 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 | |||
161 | void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) | 170 | void 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 | ||
919 | bool DataStore::exists() const | 919 | bool 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 | ||
924 | DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function<void(const DataStore::Error &error)> &errorHandlerArg) | 925 | DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function<void(const DataStore::Error &error)> &errorHandlerArg) |