aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-21 10:47:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-21 10:47:30 +0200
commit1e63b60696f2e3012221e3bf6430a0d66ce1ba34 (patch)
treebbf88b77c86c7f3135e7e21fefb14ffe6e0fe0cb
parent9ac9bb98f307156c02fa19ea747cf5eb1d2dcadf (diff)
Add support for multi-pass database schema drop
-rw-r--r--odb/schema-catalog-impl.hxx5
-rw-r--r--odb/schema-catalog.cxx25
2 files changed, 24 insertions, 6 deletions
diff --git a/odb/schema-catalog-impl.hxx b/odb/schema-catalog-impl.hxx
index 51a4902..32fd68f 100644
--- a/odb/schema-catalog-impl.hxx
+++ b/odb/schema-catalog-impl.hxx
@@ -35,8 +35,9 @@ namespace odb
//
struct LIBODB_EXPORT schema_catalog_entry
{
- schema_catalog_entry (const char* name,
- bool (*entry) (database&, unsigned short pass));
+ schema_catalog_entry (
+ const char* name,
+ bool (*entry) (database&, unsigned short pass, bool drop));
};
}
diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx
index 2d8415f..ab83dbd 100644
--- a/odb/schema-catalog.cxx
+++ b/odb/schema-catalog.cxx
@@ -14,7 +14,7 @@ using namespace std;
namespace odb
{
- typedef bool (*create_function) (database&, unsigned short pass);
+ typedef bool (*create_function) (database&, unsigned short pass, bool drop);
typedef vector<create_function> create_functions;
struct schema_catalog_impl: map<string, create_functions> {};
@@ -34,16 +34,33 @@ namespace odb
const create_functions& fs (i->second);
// Run the passes until we ran them all or all the functions
- // return false, which means no more passes necessary.
+ // return false, which means no more passes necessary. Do that
+ // first for drop passes, then for create.
//
- for (unsigned short pass (0); pass < 3; ++pass)
+
+ for (unsigned short pass (1); pass < 3; ++pass)
+ {
+ bool done (true);
+
+ for (create_functions::const_iterator j (fs.begin ()), e (fs.end ());
+ j != e; ++j)
+ {
+ if ((*j) (db, pass, true))
+ done = false;
+ }
+
+ if (done)
+ break;
+ }
+
+ for (unsigned short pass (1); pass < 3; ++pass)
{
bool done (true);
for (create_functions::const_iterator j (fs.begin ()), e (fs.end ());
j != e; ++j)
{
- if ((*j) (db, pass))
+ if ((*j) (db, pass, false))
done = false;
}