From 8554cd89897f9cbd1705592cf0318b3ef4e42665 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 25 Apr 2013 07:35:45 +0200 Subject: Add support for schema version table --- odb/relational/schema-source.cxx | 42 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'odb/relational/schema-source.cxx') diff --git a/odb/relational/schema-source.cxx b/odb/relational/schema-source.cxx index d54ae02..54d5076 100644 --- a/odb/relational/schema-source.cxx +++ b/odb/relational/schema-source.cxx @@ -21,20 +21,24 @@ namespace relational sema_rel::model& model (*ctx.model); string const& schema_name (ops.schema_name ()[db]); - if (log != 0 && log->contains_changeset_empty ()) + if (log != 0 && + (log->contains_changeset_empty () || ops.suppress_migration ())) log = 0; + bool schema_version ( + model.version () != 0 && !ctx.options.suppress_schema_version ()); + instance emitter; emitter_ostream emitter_os (*emitter); schema_format format (schema_format::embedded); - if (!model.names_empty () || log != 0) + if (!model.names_empty () || log != 0 || schema_version) os << "namespace odb" << "{"; // Schema. // - if (!model.names_empty ()) + if (!model.names_empty () || schema_version) { os << "static bool" << endl << "create_schema (database& db, unsigned short pass, bool drop)" @@ -69,6 +73,14 @@ namespace relational close = close || !emitter->empty (); } + if (schema_version) + { + instance vt (*emitter, emitter_os, format); + vt->create_table (); + vt->drop (); + close = true; + } + if (close) // Close the last case and the switch block. os << "return false;" << "}" // case @@ -106,6 +118,14 @@ namespace relational close = close || !emitter->empty (); } + if (schema_version) + { + instance vt (*emitter, emitter_os, format); + vt->create_table (); + vt->create (model.version ()); + close = true; + } + if (close) // Close the last case and the switch block. os << "return false;" << "}" // case @@ -172,6 +192,13 @@ namespace relational close = close || !emitter->empty (); } + if (!ctx.options.suppress_schema_version ()) + { + instance vt (*emitter, emitter_os, format); + vt->migrate_pre (cs.version ()); + close = true; + } + if (close) // Close the last case and the switch block. os << "return false;" << "}" // case @@ -208,6 +235,13 @@ namespace relational close = close || !emitter->empty (); } + if (!ctx.options.suppress_schema_version ()) + { + instance vt (*emitter, emitter_os, format); + vt->migrate_post (); + close = true; + } + if (close) // Close the last case and the switch block. os << "return false;" << "}" // case @@ -229,7 +263,7 @@ namespace relational } } - if (!model.names_empty () || log != 0) + if (!model.names_empty () || log != 0 || schema_version) os << "}"; // namespace odb } } -- cgit v1.1