Akonadi

dbmigrator.h
1/*
2 SPDX-FileCopyrightText: 2024 g10 Code GmbH
3 SPDX-FileContributor: Daniel Vrátil <dvratil@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include <QObject>
11
12#include <functional>
13#include <memory>
14#include <system_error>
15#include <variant>
16
17class QThread;
18
19namespace Akonadi::Server
20{
21
22class DbConfig;
23class TableDescription;
24class DataStore;
25
26class UIDelegate
27{
28public:
29 enum class Result {
30 Yes,
31 No,
32 Skip,
33 };
34
35 virtual ~UIDelegate() = default;
36 virtual Result questionYesNo(const QString &question) = 0;
37 virtual Result questionYesNoSkip(const QString &question) = 0;
38};
39
40class DbMigrator : public QObject
41{
43public:
44 explicit DbMigrator(const QString &targetEngine, UIDelegate *delegate, QObject *parent = nullptr);
45 ~DbMigrator() override;
46
47 void startMigration();
48
50 void info(const QString &message);
51 void error(const QString &message);
52 void progress(const QString &message, int tablesDone, int tablesTotal);
53 void tableProgress(const QString &table, int rowsDone, int rowsTotal);
54
55 void migrationCompleted(bool success);
56
57private:
58 [[nodiscard]] bool runMigrationThread();
59 bool copyTable(DataStore *sourceStore, DataStore *destStore, const TableDescription &table);
60
61 [[nodiscard]] bool migrateTables(DataStore *sourceStore, DataStore *destStore, DbConfig *destConfig);
62 [[nodiscard]] bool moveDatabaseToMainLocation(DbConfig *destConfig, const QString &destServerCfgFile);
63 std::optional<QString> moveDatabaseToBackupLocation(DbConfig *config);
64 std::optional<QString> backupAkonadiServerRc();
65 bool runStorageJanitor(DbConfig *sourceConfig);
66
67 void emitInfo(const QString &message);
68 void emitError(const QString &message);
69 void emitProgress(const QString &message, int tablesDone, int tablesTotal);
70 void emitTableProgress(const QString &table, int done, int total);
71 void emitCompletion(bool success);
72 [[nodiscard]] UIDelegate::Result questionYesNo(const QString &question);
73 [[nodiscard]] UIDelegate::Result questionYesNoSkip(const QString &question);
74
75 QString m_targetEngine;
76 std::unique_ptr<QThread> m_thread;
77 UIDelegate *m_uiDelegate = nullptr;
78};
79
80} // namespace Akonadi::Server
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.