diff options
-rw-r--r-- | odb/schema-catalog.cxx | 28 | ||||
-rw-r--r-- | odb/schema-catalog.hxx | 9 |
2 files changed, 28 insertions, 9 deletions
diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx index 52b612f..9599afe 100644 --- a/odb/schema-catalog.cxx +++ b/odb/schema-catalog.cxx @@ -42,7 +42,7 @@ namespace odb } void schema_catalog:: - create_schema (database& db, const string& name) + create_schema (database& db, const string& name, bool drop) { const schema_catalog_impl& c (*schema_catalog_init::catalog); schema_catalog_impl::const_iterator i (c.find (key (db.id (), name))); @@ -52,11 +52,12 @@ namespace odb const create_functions& fs (i->second.create); + if (drop) + drop_schema (db, name); + // Run the passes until we ran them all or all the functions - // return false, which means no more passes necessary. Do that - // first for drop passes, then for create. + // return false, which means no more passes necessary. // - for (unsigned short pass (1); pass < 3; ++pass) { bool done (true); @@ -64,14 +65,29 @@ namespace odb for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); j != e; ++j) { - if ((*j) (db, pass, true)) + if ((*j) (db, pass, false)) done = false; } if (done) break; } + } + + void schema_catalog:: + drop_schema (database& db, const string& name) + { + const schema_catalog_impl& c (*schema_catalog_init::catalog); + schema_catalog_impl::const_iterator i (c.find (key (db.id (), name))); + if (i == c.end ()) + throw unknown_schema (name); + + const create_functions& fs (i->second.create); + + // Run the passes until we ran them all or all the functions + // return false, which means no more passes necessary. + // for (unsigned short pass (1); pass < 3; ++pass) { bool done (true); @@ -79,7 +95,7 @@ namespace odb for (create_functions::const_iterator j (fs.begin ()), e (fs.end ()); j != e; ++j) { - if ((*j) (db, pass, false)) + if ((*j) (db, pass, true)) done = false; } diff --git a/odb/schema-catalog.hxx b/odb/schema-catalog.hxx index da6b767..a186de4 100644 --- a/odb/schema-catalog.hxx +++ b/odb/schema-catalog.hxx @@ -21,7 +21,10 @@ namespace odb // Schema creation. // static void - create_schema (database&, const std::string& name = ""); + create_schema (database&, const std::string& name = "", bool drop = true); + + static void + drop_schema (database&, const std::string& name = ""); // Schema migration. // @@ -76,13 +79,13 @@ namespace odb // Test for presence of a schema with a specific name. // static bool - exists (const database& db, const std::string& name) + exists (const database& db, const std::string& name = "") { return exists (db.id (), name); } static bool - exists (database_id, const std::string& name); + exists (database_id, const std::string& name = ""); private: enum migrate_mode |