aboutsummaryrefslogtreecommitdiff
path: root/odb/schema-catalog.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-25 10:46:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-25 10:46:33 +0200
commit429cd8f13191cc08f6461d646fdde2d573496f06 (patch)
tree9b20afa2599bfea9c35e0e976a6a30a20f66eece /odb/schema-catalog.hxx
parentd78ba3e97cbe0d6c641120d94d47e25b198febfb (diff)
Add support for data migration
Diffstat (limited to 'odb/schema-catalog.hxx')
-rw-r--r--odb/schema-catalog.hxx85
1 files changed, 84 insertions, 1 deletions
diff --git a/odb/schema-catalog.hxx b/odb/schema-catalog.hxx
index 07e625b..5af7c48 100644
--- a/odb/schema-catalog.hxx
+++ b/odb/schema-catalog.hxx
@@ -7,8 +7,14 @@
#include <odb/pre.hxx>
+#include <odb/details/config.hxx> // ODB_CXX11
+
#include <string>
+#ifdef ODB_CXX11
+# include <functional> // std::function
+#endif
+
#include <odb/forward.hxx> // schema_version, odb::core
#include <odb/details/export.hxx>
@@ -28,6 +34,7 @@ namespace odb
// Schema migration.
//
+ public:
static void
migrate_schema_pre (database& db,
schema_version v,
@@ -52,12 +59,62 @@ namespace odb
migrate_schema_impl (db, v, name, migrate_both);
}
+ // Data migration.
+ //
+ public:
+ // If version is 0, then use the current version and also check whether
+ // we are in migration.
+ //
+ static void
+ migrate_data (database&,
+ schema_version = 0,
+ const std::string& name = "");
+
+#ifdef ODB_CXX11
+ typedef std::function<void (database&)> data_migration_function_type;
+#else
+ typedef void (*data_migration_function_type) (database&);
+#endif
+
+ // Data migration functions are called in the order of registration.
+ //
+ static void
+ data_migration_function (schema_version v,
+ data_migration_function_type f,
+ const std::string& name = "")
+ {
+ data_migration_function (id_common, v, f, name);
+ }
+
+ // Database-specific data migration.
+ //
+ static void
+ data_migration_function (database& db,
+ schema_version v,
+ data_migration_function_type f,
+ const std::string& name = "")
+ {
+ data_migration_function (db.id (), v, f, name);
+ }
+
+ static void
+ data_migration_function (database_id,
+ schema_version,
+ data_migration_function_type,
+ const std::string& name = "");
+
+ // Combined schema and data migration.
+ //
+ public:
// Migrate both schema and data to the specified version. If version
// is not specified, then migrate to the latest version.
//
static void
- migrate (database& db, schema_version v = 0, const std::string& name = "");
+ migrate (database&, schema_version = 0, const std::string& name = "");
+ // Schema version information.
+ //
+ public:
// Return 0 if current is greater or equal to the latest version.
// If current is not specified, get the current version from the
// database.
@@ -86,6 +143,9 @@ namespace odb
static schema_version
latest_version (database_id, const std::string& name = "");
+ // Schema existence.
+ //
+ public:
// Test for presence of a schema with a specific name.
//
static bool
@@ -112,9 +172,32 @@ namespace odb
migrate_mode);
};
+ // Static data migration function registration.
+ //
+ struct LIBODB_EXPORT data_migration_entry
+ {
+ typedef schema_catalog::data_migration_function_type function_type;
+
+ data_migration_entry (schema_version v,
+ function_type f,
+ const std::string& name = "")
+ {
+ schema_catalog::data_migration_function (v, f, name);
+ }
+
+ data_migration_entry (database_id id,
+ schema_version v,
+ function_type f,
+ const std::string& name = "")
+ {
+ schema_catalog::data_migration_function (id, v, f, name);
+ }
+ };
+
namespace common
{
using odb::schema_catalog;
+ using odb::data_migration_entry;
}
}