diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-09 16:17:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-09 16:17:26 +0200 |
commit | 287a41287ed26bcf481f087680cad56ed5ef9865 (patch) | |
tree | a139f2da973f2e6576d2673e9e096a4e4ab12e6f /odb/schema-catalog.hxx | |
parent | 4962329eecb716bc2b99810ec1ac4214606fc1e8 (diff) |
Add support for embedded schema migration
Diffstat (limited to 'odb/schema-catalog.hxx')
-rw-r--r-- | odb/schema-catalog.hxx | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/odb/schema-catalog.hxx b/odb/schema-catalog.hxx index b9252d3..da6b767 100644 --- a/odb/schema-catalog.hxx +++ b/odb/schema-catalog.hxx @@ -9,7 +9,7 @@ #include <string> -#include <odb/forward.hxx> // odb::core +#include <odb/forward.hxx> // schema_version, odb::core #include <odb/details/export.hxx> @@ -18,17 +18,85 @@ namespace odb class LIBODB_EXPORT schema_catalog { public: + // Schema creation. + // static void create_schema (database&, const std::string& name = ""); - static bool - exists (database_id, const std::string& name); + // Schema migration. + // + static void + migrate_schema_pre (database& db, + schema_version v, + const std::string& name = "") + { + migrate_schema_impl (db, v, name, migrate_pre); + } + + static void + migrate_schema_post (database& db, + schema_version v, + const std::string& name = "") + { + migrate_schema_impl (db, v, name, migrate_post); + } + + static void + migrate_schema (database& db, + schema_version v, + const std::string& name = "") + { + migrate_schema_impl (db, v, name, migrate_both); + } + + // Return 0 if current is greater or equal to the latest version. + // + schema_version + next_version (const database& db, + schema_version current /*= 0*/, + const std::string& name = "") + { + return next_version (db.id (), current, name); + } + + schema_version + next_version (database_id, + schema_version current /*= 0*/, + const std::string& name = ""); + + schema_version + latest_version (const database& db, const std::string& name = "") + { + return latest_version (db.id (), name); + } + + schema_version + latest_version (database_id, const std::string& name = ""); + // Test for presence of a schema with a specific name. + // static bool exists (const database& db, const std::string& name) { return exists (db.id (), name); } + + static bool + exists (database_id, const std::string& name); + + private: + enum migrate_mode + { + migrate_pre, + migrate_post, + migrate_both + }; + + static void + migrate_schema_impl (database&, + schema_version, + const std::string& name, + migrate_mode); }; namespace common |