aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-07-05 18:39:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-07-05 18:39:09 +0200
commit72f0237f3310a69fd566f1d2c25ca805f677199a (patch)
treedae417dd3216f20be7e2c75aacd85ccc7ba0d97f
parentafa56605aca5021c5aab2fbe70cdfb81f863206f (diff)
Add support for multi-pass database schema generation
-rw-r--r--odb/schema-catalog-impl.hxx3
-rw-r--r--odb/schema-catalog.cxx22
2 files changed, 20 insertions, 5 deletions
diff --git a/odb/schema-catalog-impl.hxx b/odb/schema-catalog-impl.hxx
index 782536a..51a4902 100644
--- a/odb/schema-catalog-impl.hxx
+++ b/odb/schema-catalog-impl.hxx
@@ -35,7 +35,8 @@ namespace odb
//
struct LIBODB_EXPORT schema_catalog_entry
{
- schema_catalog_entry (const char* name, void (*entry) (database&));
+ schema_catalog_entry (const char* name,
+ bool (*entry) (database&, unsigned short pass));
};
}
diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx
index 5332cce..2d8415f 100644
--- a/odb/schema-catalog.cxx
+++ b/odb/schema-catalog.cxx
@@ -14,7 +14,7 @@ using namespace std;
namespace odb
{
- typedef void (*create_function) (database&);
+ typedef bool (*create_function) (database&, unsigned short pass);
typedef vector<create_function> create_functions;
struct schema_catalog_impl: map<string, create_functions> {};
@@ -33,9 +33,23 @@ namespace odb
const create_functions& fs (i->second);
- for (create_functions::const_iterator j (fs.begin ()), e (fs.end ());
- j != e; ++j)
- (*j) (db);
+ // Run the passes until we ran them all or all the functions
+ // return false, which means no more passes necessary.
+ //
+ for (unsigned short pass (0); pass < 3; ++pass)
+ {
+ bool done (true);
+
+ for (create_functions::const_iterator j (fs.begin ()), e (fs.end ());
+ j != e; ++j)
+ {
+ if ((*j) (db, pass))
+ done = false;
+ }
+
+ if (done)
+ break;
+ }
}
// schema_catalog_init