From 72f0237f3310a69fd566f1d2c25ca805f677199a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Jul 2011 18:39:09 +0200 Subject: Add support for multi-pass database schema generation --- odb/schema-catalog.cxx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'odb/schema-catalog.cxx') 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_functions; struct schema_catalog_impl: map {}; @@ -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 -- cgit v1.1