diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-25 07:35:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-25 07:35:45 +0200 |
commit | 8554cd89897f9cbd1705592cf0318b3ef4e42665 (patch) | |
tree | a81469bcddd6bddd2eb89c12faa9c59169484b43 /odb/relational/schema-source.cxx | |
parent | 5ced83875191cf9e0f395af79f45babd6fae3d29 (diff) |
Add support for schema version table
Diffstat (limited to 'odb/relational/schema-source.cxx')
-rw-r--r-- | odb/relational/schema-source.cxx | 42 |
1 files changed, 38 insertions, 4 deletions
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<cxx_emitter> 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<version_table> 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<version_table> 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<version_table> 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<version_table> 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 } } |