// file : odb/schema-catalog.hxx // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_SCHEMA_CATALOG_HXX #define ODB_SCHEMA_CATALOG_HXX #include #include // ODB_CXX11 #include #include // std::size_t #ifdef ODB_CXX11 # include // std::function #endif #include // schema_version, odb::core #include namespace odb { class LIBODB_EXPORT schema_catalog { public: // Schema creation. // static void create_schema (database&, const std::string& name = "", bool drop = true); static void drop_schema (database&, const std::string& name = ""); // Schema migration. // public: 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); } // Data migration. // public: // If version is 0, then use the current version and also check whether // we are in migration. Returns the number of calls made. // static std::size_t migrate_data (database&, schema_version = 0, const std::string& name = ""); #ifdef ODB_CXX11 typedef std::function 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&, 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. // static schema_version next_version (const database& db, schema_version current = 0, const std::string& name = "") { return next_version (db.id (), current == 0 ? db.schema_version () : current, name); } static schema_version next_version (database_id, schema_version current, const std::string& name = ""); static schema_version latest_version (const database& db, const std::string& name = "") { return latest_version (db.id (), name); } 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 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); }; // 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; } } #include #endif // ODB_SCHEMA_CATALOG_HXX