summaryrefslogtreecommitdiffhomepage
path: root/migration/migration.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-09-09 08:51:25 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-09-09 15:00:58 +0200
commit6bc3fe31a3f354afc7be870a4a2d375ab6c746b6 (patch)
tree39b439b16cb872b3d982a6083a546456001d0f8e /migration/migration.hpp
parentcc6fc6577940df89c57db08743b181291c2a4b43 (diff)
add support for migrations
They're run from the UI thread so can even be interactive.
Diffstat (limited to 'migration/migration.hpp')
-rw-r--r--migration/migration.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/migration/migration.hpp b/migration/migration.hpp
new file mode 100644
index 00000000..b9c20f15
--- /dev/null
+++ b/migration/migration.hpp
@@ -0,0 +1,72 @@
+#pragma once
+
+#include <QString>
+#include <vector>
+
+#include "export.hpp"
+
+namespace migrations {
+
+class migration;
+class registrator;
+
+namespace detail {
+ class migrator final
+ {
+ using mm = migration*;
+ template<typename t> using vec_ = std::vector<t>;
+ using vstr = vec_<QString>;
+ using vec = vec_<mm>;
+ static vec& migrations();
+ static QString last_migration_time();
+ static QString time_after_migrations();
+ static void set_last_migration_time(const QString& val);
+ migrator() = delete;
+ static vec sorted_migrations();
+ public:
+ static vstr run();
+ static void register_migration(migration* m);
+ static void mark_config_as_not_needing_migration();
+ };
+
+ template<typename t>
+ struct registrator final
+ {
+ registrator()
+ {
+ static t m;
+ migrator::register_migration(static_cast<migration*>(&m));
+ }
+ };
+}
+
+#ifndef __COUNTER__
+# error "oops, need __COUNTER__ extension for preprocessor"
+#endif
+
+#define OPENTRACK_MIGRATION(type) static ::migrations::detail::registrator<type> opentrack_migration_registrator__ ## __COUNTER__ ## _gensym;
+
+#ifdef Q_CREATOR_RUN
+# pragma clang diagnostic ignored "-Wweak-vtables"
+#endif
+
+class migration
+{
+ migration& operator=(const migration&) = delete;
+ migration(const migration&) = delete;
+ migration& operator=(migration&&) = delete;
+ migration(migration&&) = delete;
+
+public:
+ migration();
+ virtual ~migration();
+ virtual QString unique_date() const = 0;
+ virtual QString name() const = 0;
+ virtual bool should_run() const = 0;
+ virtual void run() = 0;
+};
+
+}
+
+OPENTRACK_MIGRATION_EXPORT std::vector<QString> run_migrations();
+OPENTRACK_MIGRATION_EXPORT void mark_config_as_not_needing_migration();