summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-11 17:47:54 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-11 17:47:54 +0200
commit254f9dad6377311b8115221c252b20726acad0c5 (patch)
tree3361c671d301586cc8d07f459194808e0dd39fc3
parent1291ccf13a0b8a1eddb6aaed24b45ceb31a2e01e (diff)
downloadsink-254f9dad6377311b8115221c252b20726acad0c5.tar.gz
sink-254f9dad6377311b8115221c252b20726acad0c5.zip
Upgrade job that we can eventually use to upgrade the storage
-rw-r--r--common/store.cpp13
-rw-r--r--common/store.h12
-rw-r--r--sinksh/CMakeLists.txt1
-rw-r--r--sinksh/syntax_modules/sink_upgrade.cpp47
4 files changed, 73 insertions, 0 deletions
diff --git a/common/store.cpp b/common/store.cpp
index d266098..0eefe69 100644
--- a/common/store.cpp
+++ b/common/store.cpp
@@ -277,6 +277,19 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier)
277 }); 277 });
278} 278}
279 279
280KAsync::Job<void> Store::upgrade()
281{
282 SinkLog() << "Upgrading...";
283 return fetchAll<ApplicationDomain::SinkResource>({})
284 .template each([](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job<void> {
285 SinkLog() << "Removing caches for " << resource->identifier();
286 return removeDataFromDisk(resource->identifier());
287 })
288 .then([] {
289 SinkLog() << "Upgrade complete.";
290 });
291}
292
280static KAsync::Job<void> synchronize(const QByteArray &resource, const Sink::SyncScope &scope) 293static KAsync::Job<void> synchronize(const QByteArray &resource, const Sink::SyncScope &scope)
281{ 294{
282 SinkLog() << "Synchronizing " << resource << scope; 295 SinkLog() << "Synchronizing " << resource << scope;
diff --git a/common/store.h b/common/store.h
index fae76e5..34e14df 100644
--- a/common/store.h
+++ b/common/store.h
@@ -122,6 +122,18 @@ KAsync::Job<void> SINK_EXPORT synchronize(const Sink::SyncScope &query);
122 */ 122 */
123KAsync::Job<void> SINK_EXPORT removeDataFromDisk(const QByteArray &resourceIdentifier); 123KAsync::Job<void> SINK_EXPORT removeDataFromDisk(const QByteArray &resourceIdentifier);
124 124
125/**
126 * Run upgrade jobs.
127 *
128 * Run this to upgrade your local database to a new version.
129 * Note that this may:
130 * * take a while
131 * * remove some/all of your local caches
132 *
133 * Note: The initial implementation simply calls removeDataFromDisk for all resources.
134 */
135KAsync::Job<void> SINK_EXPORT upgrade();
136
125template <class DomainType> 137template <class DomainType>
126KAsync::Job<DomainType> SINK_EXPORT fetchOne(const Sink::Query &query); 138KAsync::Job<DomainType> SINK_EXPORT fetchOne(const Sink::Query &query);
127 139
diff --git a/sinksh/CMakeLists.txt b/sinksh/CMakeLists.txt
index 82839ab..bc487c1 100644
--- a/sinksh/CMakeLists.txt
+++ b/sinksh/CMakeLists.txt
@@ -18,6 +18,7 @@ set(sink_cli_SRCS
18 syntax_modules/sink_trace.cpp 18 syntax_modules/sink_trace.cpp
19 syntax_modules/sink_inspect.cpp 19 syntax_modules/sink_inspect.cpp
20 syntax_modules/sink_drop.cpp 20 syntax_modules/sink_drop.cpp
21 syntax_modules/sink_upgrade.cpp
21 sinksh_utils.cpp 22 sinksh_utils.cpp
22 repl/repl.cpp 23 repl/repl.cpp
23 repl/replStates.cpp 24 repl/replStates.cpp
diff --git a/sinksh/syntax_modules/sink_upgrade.cpp b/sinksh/syntax_modules/sink_upgrade.cpp
new file mode 100644
index 0000000..c399048
--- /dev/null
+++ b/sinksh/syntax_modules/sink_upgrade.cpp
@@ -0,0 +1,47 @@
1/*
2 * Copyright (C) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <QDebug>
21#include <QObject> // tr()
22#include <QTimer>
23
24#include "common/store.h"
25
26#include "state.h"
27#include "syntaxtree.h"
28
29namespace SinkUpgrade
30{
31
32bool upgrade(const QStringList &args, State &state)
33{
34 state.print(QObject::tr("Upgrading..."));
35 Sink::Store::upgrade().exec().waitForFinished();
36 state.printLine(QObject::tr("done"));
37 return true;
38}
39
40Syntax::List syntax()
41{
42 return Syntax::List() << Syntax{"upgrade", QObject::tr("Upgrades your storage to the latest version (be careful!)"), &SinkUpgrade::upgrade, Syntax::NotInteractive};
43}
44
45REGISTER_SYNTAX(SinkUpgrade)
46
47}