diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-09 16:17:27 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-04-10 18:46:47 +0200 |
commit | b0c2c30dd0b83ea67fb2c8375ae2061dad0d1770 (patch) | |
tree | b1fbada48dab47c2477c6016a45cfac957670346 /evolution/drop-table | |
parent | 7d1e16930e37c4109f439f5ebe1e789b9619a57e (diff) |
Add support for embedded schema migration
Diffstat (limited to 'evolution/drop-table')
-rw-r--r-- | evolution/drop-table/driver.cxx | 26 | ||||
-rw-r--r-- | evolution/drop-table/makefile | 9 |
2 files changed, 30 insertions, 5 deletions
diff --git a/evolution/drop-table/driver.cxx b/evolution/drop-table/driver.cxx index 2a48ed5..6ab29f0 100644 --- a/evolution/drop-table/driver.cxx +++ b/evolution/drop-table/driver.cxx @@ -11,6 +11,7 @@ #include <odb/database.hxx> #include <odb/transaction.hxx> +#include <odb/schema-catalog.hxx> #include <common/common.hxx> @@ -27,7 +28,8 @@ main (int argc, char* argv[]) { try { - auto_ptr<database> db (create_database (argc, argv)); + auto_ptr<database> db (create_database (argc, argv, false)); + bool embedded (schema_catalog::exists (*db, "test2")); // 1 - base version // 2 - migration @@ -41,6 +43,15 @@ main (int argc, char* argv[]) { using namespace v2; + if (embedded) + { + transaction t (db->begin ()); + schema_catalog::create_schema (*db, "test2"); + schema_catalog::create_schema (*db, "test1"); + schema_catalog::migrate_schema (*db, 2, "test2"); + t.commit (); + } + object1 o1; o1.o = new object (1); o1.o->str = "abc"; @@ -60,6 +71,13 @@ main (int argc, char* argv[]) { using namespace v2; // @@ v3; soft immediate drop + if (embedded) + { + transaction t (db->begin ()); + schema_catalog::migrate_schema_pre (*db, 3, "test2"); + t.commit (); + } + // Both object and object1 are still there so we can migrate the data. // typedef odb::query<object1> query; @@ -79,6 +97,12 @@ main (int argc, char* argv[]) t.commit (); } + if (embedded) + { + transaction t (db->begin ()); + schema_catalog::migrate_schema_pre (*db, 3, "test2"); + t.commit (); + } break; } case 3: diff --git a/evolution/drop-table/makefile b/evolution/drop-table/makefile index 091a679..a08f0a1 100644 --- a/evolution/drop-table/makefile +++ b/evolution/drop-table/makefile @@ -29,15 +29,16 @@ $(driver): $(cxx_obj) $(common.l) $(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) $(cxx_obj) $(cxx_od): $(common.l.cpp-options) -genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx test1.sql model.xml +genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx model.xml gen1 := $(addprefix $(out_base)/,$(genf1)) -genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx test2.sql \ -test2-002-pre.sql test2-002-post.sql test2-003-pre.sql test2-003-post.sql +genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx gen2 := $(addprefix $(out_base)/,$(genf2)) genf := $(genf1) $(genf2) gen := $(gen1) $(gen2) +gens := test1.sql test2.sql test2-002-pre.sql test2-002-post.sql \ +test2-003-pre.sql test2-003-post.sql $(gen): $(odb) $(gen): odb := $(odb) @@ -113,7 +114,7 @@ $(clean): \ ifeq ($(out_base),$(src_base)) $(driver): | $(out_base)/.gitignore -$(out_base)/.gitignore: files := driver $(genf) +$(out_base)/.gitignore: files := driver $(genf) $(gens) $(clean): $(out_base)/.gitignore.clean $(call include,$(bld_root)/git/gitignore.make) |