aboutsummaryrefslogtreecommitdiff
path: root/evolution
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-25 07:35:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-25 09:58:53 +0200
commit40ae3082645ed3790eb1d5d6f04fb2ca36c19187 (patch)
tree5157fe5db532ec91b0c06ce5f81d4e92444b7fe9 /evolution
parent502926d96b0b5d79dc639b8388fbf19b11cda277 (diff)
Add support for schema version table
Diffstat (limited to 'evolution')
-rw-r--r--evolution/add-column/driver.cxx17
-rw-r--r--evolution/add-column/makefile43
-rw-r--r--evolution/add-column/test1.hxx4
-rw-r--r--evolution/add-column/test2.hxx2
-rw-r--r--evolution/add-column/test3.hxx12
-rw-r--r--evolution/add-foreign-key/driver.cxx17
-rw-r--r--evolution/add-foreign-key/makefile45
-rw-r--r--evolution/add-foreign-key/test1.hxx4
-rw-r--r--evolution/add-foreign-key/test2.hxx2
-rw-r--r--evolution/add-foreign-key/test3.hxx12
-rw-r--r--evolution/add-index/driver.cxx17
-rw-r--r--evolution/add-index/makefile43
-rw-r--r--evolution/add-index/test1.hxx4
-rw-r--r--evolution/add-index/test2.hxx2
-rw-r--r--evolution/add-index/test3.hxx12
-rw-r--r--evolution/add-table/driver.cxx17
-rw-r--r--evolution/add-table/makefile43
-rw-r--r--evolution/add-table/test1.hxx4
-rw-r--r--evolution/add-table/test2.hxx2
-rw-r--r--evolution/add-table/test3.hxx12
-rw-r--r--evolution/alter-column/driver.cxx17
-rw-r--r--evolution/alter-column/makefile43
-rw-r--r--evolution/alter-column/test1.hxx4
-rw-r--r--evolution/alter-column/test2.hxx2
-rw-r--r--evolution/alter-column/test3.hxx12
-rw-r--r--evolution/combined/driver.cxx17
-rw-r--r--evolution/combined/makefile43
-rw-r--r--evolution/combined/test1.hxx4
-rw-r--r--evolution/combined/test2.hxx2
-rw-r--r--evolution/combined/test3.hxx12
-rw-r--r--evolution/drop-column/driver.cxx17
-rw-r--r--evolution/drop-column/makefile43
-rw-r--r--evolution/drop-column/test1.hxx4
-rw-r--r--evolution/drop-column/test2.hxx2
-rw-r--r--evolution/drop-column/test3.hxx12
-rw-r--r--evolution/drop-foreign-key/driver.cxx17
-rw-r--r--evolution/drop-foreign-key/makefile45
-rw-r--r--evolution/drop-foreign-key/test1.hxx4
-rw-r--r--evolution/drop-foreign-key/test2.hxx2
-rw-r--r--evolution/drop-foreign-key/test3.hxx12
-rw-r--r--evolution/drop-index/driver.cxx17
-rw-r--r--evolution/drop-index/makefile43
-rw-r--r--evolution/drop-index/test1.hxx4
-rw-r--r--evolution/drop-index/test2.hxx2
-rw-r--r--evolution/drop-index/test3.hxx12
-rw-r--r--evolution/drop-table/driver.cxx17
-rw-r--r--evolution/drop-table/makefile43
-rw-r--r--evolution/drop-table/test1.hxx4
-rw-r--r--evolution/drop-table/test2.hxx2
-rw-r--r--evolution/drop-table/test3.hxx12
-rw-r--r--evolution/embedded/driver.cxx160
-rw-r--r--evolution/embedded/makefile139
-rw-r--r--evolution/embedded/model.hxx46
-rw-r--r--evolution/embedded/test1.hxx10
-rw-r--r--evolution/embedded/test2.hxx12
-rw-r--r--evolution/embedded/test3.hxx12
-rw-r--r--evolution/makefile2
-rw-r--r--evolution/template/Makefile.am23
-rw-r--r--evolution/template/driver.cxx17
-rw-r--r--evolution/template/makefile43
-rw-r--r--evolution/template/template-vc10.vcxproj13
-rw-r--r--evolution/template/template-vc10.vcxproj.filters4
-rw-r--r--evolution/template/template-vc11.vcxproj13
-rw-r--r--evolution/template/template-vc11.vcxproj.filters4
-rw-r--r--evolution/template/template-vc9.vcproj13
-rw-r--r--evolution/template/test1.hxx4
-rw-r--r--evolution/template/test2.hxx2
-rw-r--r--evolution/template/test3.hxx12
-rwxr-xr-xevolution/tester10
-rw-r--r--evolution/tester.bat14
-rw-r--r--evolution/version/driver.cxx158
-rw-r--r--evolution/version/makefile150
-rw-r--r--evolution/version/model.hxx46
-rw-r--r--evolution/version/test1.hxx10
-rw-r--r--evolution/version/test2.hxx12
-rw-r--r--evolution/version/test3.hxx12
76 files changed, 1373 insertions, 352 deletions
diff --git a/evolution/add-column/driver.cxx b/evolution/add-column/driver.cxx
index 3503010..a619895 100644
--- a/evolution/add-column/driver.cxx
+++ b/evolution/add-column/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -68,7 +69,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -91,7 +92,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/add-column/makefile b/evolution/add-column/makefile
index 5e64a45..0447ad4 100644
--- a/evolution/add-column/makefile
+++ b/evolution/add-column/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_add_c_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_add_c_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/add-column/test1.hxx b/evolution/add-column/test1.hxx
index fb62777..23470b9 100644
--- a/evolution/add-column/test1.hxx
+++ b/evolution/add-column/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/add-column/test2.hxx b/evolution/add-column/test2.hxx
index 7aa2697..0f286b7 100644
--- a/evolution/add-column/test2.hxx
+++ b/evolution/add-column/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/add-column/test3.hxx b/evolution/add-column/test3.hxx
new file mode 100644
index 0000000..88051d3
--- /dev/null
+++ b/evolution/add-column/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/add-column/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/add-foreign-key/driver.cxx b/evolution/add-foreign-key/driver.cxx
index 26c1f57..a05804a 100644
--- a/evolution/add-foreign-key/driver.cxx
+++ b/evolution/add-foreign-key/driver.cxx
@@ -16,10 +16,10 @@
#include <common/config.hxx> // DATABASE_XXX
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -30,7 +30,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -47,9 +47,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -76,7 +77,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -112,7 +113,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/add-foreign-key/makefile b/evolution/add-foreign-key/makefile
index 165cf37..c4eaef2 100644
--- a/evolution/add-foreign-key/makefile
+++ b/evolution/add-foreign-key/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,37 +29,42 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --fkeys-deferrable-mode \
-not_deferrable --table-prefix evo_add_fk_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --fkeys-deferrable-mode not_deferrable \
+--table-prefix evo_add_fk_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -88,15 +93,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -108,14 +115,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/add-foreign-key/test1.hxx b/evolution/add-foreign-key/test1.hxx
index c4281dc..0c82e25 100644
--- a/evolution/add-foreign-key/test1.hxx
+++ b/evolution/add-foreign-key/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/add-foreign-key/test2.hxx b/evolution/add-foreign-key/test2.hxx
index e2d8262..a1ba8df 100644
--- a/evolution/add-foreign-key/test2.hxx
+++ b/evolution/add-foreign-key/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/add-foreign-key/test3.hxx b/evolution/add-foreign-key/test3.hxx
new file mode 100644
index 0000000..c24a09c
--- /dev/null
+++ b/evolution/add-foreign-key/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/add-foreign-key/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/add-index/driver.cxx b/evolution/add-index/driver.cxx
index ba9f837..bb369e5 100644
--- a/evolution/add-index/driver.cxx
+++ b/evolution/add-index/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -79,7 +80,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -118,7 +119,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/add-index/makefile b/evolution/add-index/makefile
index 1fe6f0a..26ba8f0 100644
--- a/evolution/add-index/makefile
+++ b/evolution/add-index/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_add_i_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_add_i_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/add-index/test1.hxx b/evolution/add-index/test1.hxx
index bf8fa79..213ce2f 100644
--- a/evolution/add-index/test1.hxx
+++ b/evolution/add-index/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/add-index/test2.hxx b/evolution/add-index/test2.hxx
index 25e4401..db1e85c 100644
--- a/evolution/add-index/test2.hxx
+++ b/evolution/add-index/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/add-index/test3.hxx b/evolution/add-index/test3.hxx
new file mode 100644
index 0000000..34f074a
--- /dev/null
+++ b/evolution/add-index/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/add-index/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/add-table/driver.cxx b/evolution/add-table/driver.cxx
index d64e991..163fe30 100644
--- a/evolution/add-table/driver.cxx
+++ b/evolution/add-table/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -69,7 +70,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -88,7 +89,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/add-table/makefile b/evolution/add-table/makefile
index a645e7d..8bcacb1 100644
--- a/evolution/add-table/makefile
+++ b/evolution/add-table/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_add_t_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_add_t_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/add-table/test1.hxx b/evolution/add-table/test1.hxx
index 2e9b12d..c91193e 100644
--- a/evolution/add-table/test1.hxx
+++ b/evolution/add-table/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/add-table/test2.hxx b/evolution/add-table/test2.hxx
index 0de1de5..96983e5 100644
--- a/evolution/add-table/test2.hxx
+++ b/evolution/add-table/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/add-table/test3.hxx b/evolution/add-table/test3.hxx
new file mode 100644
index 0000000..e709f25
--- /dev/null
+++ b/evolution/add-table/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/add-table/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/alter-column/driver.cxx b/evolution/alter-column/driver.cxx
index 976f539..a51d09a 100644
--- a/evolution/alter-column/driver.cxx
+++ b/evolution/alter-column/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -33,7 +33,7 @@ main (int argc, char* argv[])
// SQLite doesn't support altering of columns.
//
#ifndef DATABASE_SQLITE
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -50,9 +50,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -73,7 +74,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -100,7 +101,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/alter-column/makefile b/evolution/alter-column/makefile
index de0d3e0..f1cef39 100644
--- a/evolution/alter-column/makefile
+++ b/evolution/alter-column/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_alter_c_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_alter_c_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/alter-column/test1.hxx b/evolution/alter-column/test1.hxx
index cf08732..43297b9 100644
--- a/evolution/alter-column/test1.hxx
+++ b/evolution/alter-column/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/alter-column/test2.hxx b/evolution/alter-column/test2.hxx
index e99a465..3c01eeb 100644
--- a/evolution/alter-column/test2.hxx
+++ b/evolution/alter-column/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/alter-column/test3.hxx b/evolution/alter-column/test3.hxx
new file mode 100644
index 0000000..f17b630
--- /dev/null
+++ b/evolution/alter-column/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/alter-column/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/combined/driver.cxx b/evolution/combined/driver.cxx
index 9cb2853..8eb3eb2 100644
--- a/evolution/combined/driver.cxx
+++ b/evolution/combined/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -84,7 +85,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -116,7 +117,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/combined/makefile b/evolution/combined/makefile
index a489287..81bfd3a 100644
--- a/evolution/combined/makefile
+++ b/evolution/combined/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_comb_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_comb_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/combined/test1.hxx b/evolution/combined/test1.hxx
index ead9591..af73407 100644
--- a/evolution/combined/test1.hxx
+++ b/evolution/combined/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/combined/test2.hxx b/evolution/combined/test2.hxx
index 2c75fac..753b673 100644
--- a/evolution/combined/test2.hxx
+++ b/evolution/combined/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/combined/test3.hxx b/evolution/combined/test3.hxx
new file mode 100644
index 0000000..26626a3
--- /dev/null
+++ b/evolution/combined/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/combined/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/drop-column/driver.cxx b/evolution/drop-column/driver.cxx
index 2fddf3a..099fe0f 100644
--- a/evolution/drop-column/driver.cxx
+++ b/evolution/drop-column/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -33,7 +33,7 @@ main (int argc, char* argv[])
// SQLite doesn't support dropping of columns.
//
#ifndef DATABASE_SQLITE
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -50,9 +50,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -74,7 +75,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -93,7 +94,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/drop-column/makefile b/evolution/drop-column/makefile
index 6bc42fd..5c02c01 100644
--- a/evolution/drop-column/makefile
+++ b/evolution/drop-column/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_drop_c_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_drop_c_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/drop-column/test1.hxx b/evolution/drop-column/test1.hxx
index af02f02..91df52e 100644
--- a/evolution/drop-column/test1.hxx
+++ b/evolution/drop-column/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/drop-column/test2.hxx b/evolution/drop-column/test2.hxx
index 8b91e72..7adb321 100644
--- a/evolution/drop-column/test2.hxx
+++ b/evolution/drop-column/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/drop-column/test3.hxx b/evolution/drop-column/test3.hxx
new file mode 100644
index 0000000..55be2a2
--- /dev/null
+++ b/evolution/drop-column/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/drop-column/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/drop-foreign-key/driver.cxx b/evolution/drop-foreign-key/driver.cxx
index 8fe332b..bd42f5d 100644
--- a/evolution/drop-foreign-key/driver.cxx
+++ b/evolution/drop-foreign-key/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -33,7 +33,7 @@ main (int argc, char* argv[])
// SQLite doesn't support dropping of foreign keys.
//
#ifndef DATABASE_SQLITE
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -50,9 +50,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -90,7 +91,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -112,7 +113,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/drop-foreign-key/makefile b/evolution/drop-foreign-key/makefile
index d83546b..db62bfa 100644
--- a/evolution/drop-foreign-key/makefile
+++ b/evolution/drop-foreign-key/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,37 +29,42 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --fkeys-deferrable-mode \
-not_deferrable --table-prefix evo_drop_fk_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --fkeys-deferrable-mode not_deferrable \
+--table-prefix evo_drop_fk_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -88,15 +93,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -108,14 +115,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/drop-foreign-key/test1.hxx b/evolution/drop-foreign-key/test1.hxx
index 572f0a7..0748126 100644
--- a/evolution/drop-foreign-key/test1.hxx
+++ b/evolution/drop-foreign-key/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/drop-foreign-key/test2.hxx b/evolution/drop-foreign-key/test2.hxx
index b445292..c620179 100644
--- a/evolution/drop-foreign-key/test2.hxx
+++ b/evolution/drop-foreign-key/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/drop-foreign-key/test3.hxx b/evolution/drop-foreign-key/test3.hxx
new file mode 100644
index 0000000..f9f1947
--- /dev/null
+++ b/evolution/drop-foreign-key/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/drop-foreign-key/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/drop-index/driver.cxx b/evolution/drop-index/driver.cxx
index f0740ef..7a04322 100644
--- a/evolution/drop-index/driver.cxx
+++ b/evolution/drop-index/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -87,7 +88,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -105,7 +106,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/drop-index/makefile b/evolution/drop-index/makefile
index fc45fdb..1bda96f 100644
--- a/evolution/drop-index/makefile
+++ b/evolution/drop-index/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_drop_i_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_drop_i_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/drop-index/test1.hxx b/evolution/drop-index/test1.hxx
index bfac5ba..6fb8583 100644
--- a/evolution/drop-index/test1.hxx
+++ b/evolution/drop-index/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/drop-index/test2.hxx b/evolution/drop-index/test2.hxx
index 28198b5..d4722d2 100644
--- a/evolution/drop-index/test2.hxx
+++ b/evolution/drop-index/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/drop-index/test3.hxx b/evolution/drop-index/test3.hxx
new file mode 100644
index 0000000..e672f15
--- /dev/null
+++ b/evolution/drop-index/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/drop-index/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/drop-table/driver.cxx b/evolution/drop-table/driver.cxx
index 6ab29f0..1eca664 100644
--- a/evolution/drop-table/driver.cxx
+++ b/evolution/drop-table/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -74,7 +75,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -100,7 +101,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/drop-table/makefile b/evolution/drop-table/makefile
index a08f0a1..a9ad2f9 100644
--- a/evolution/drop-table/makefile
+++ b/evolution/drop-table/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_drop_t_
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_drop_t_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/drop-table/test1.hxx b/evolution/drop-table/test1.hxx
index c1319c8..4e2413c 100644
--- a/evolution/drop-table/test1.hxx
+++ b/evolution/drop-table/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/drop-table/test2.hxx b/evolution/drop-table/test2.hxx
index 2178732..d842d5b 100644
--- a/evolution/drop-table/test2.hxx
+++ b/evolution/drop-table/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/drop-table/test3.hxx b/evolution/drop-table/test3.hxx
new file mode 100644
index 0000000..9fde448
--- /dev/null
+++ b/evolution/drop-table/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/drop-table/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/embedded/driver.cxx b/evolution/embedded/driver.cxx
new file mode 100644
index 0000000..964af16
--- /dev/null
+++ b/evolution/embedded/driver.cxx
@@ -0,0 +1,160 @@
+// file : evolution/embedded/driver.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test embedded schema migration.
+//
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+#include <odb/schema-catalog.hxx>
+
+#include <common/config.hxx> // DATABASE_XXX
+#include <common/common.hxx>
+
+#include "test2.hxx"
+#include "test3.hxx"
+#include "test2-odb.hxx"
+#include "test3-odb.hxx"
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ auto_ptr<database> db (create_database (argc, argv, false));
+
+ // 1 - base version
+ // 2 - migration
+ // 3 - current version
+ //
+ unsigned short pass (*argv[argc - 1] - '0');
+
+ switch (pass)
+ {
+ case 1:
+ {
+ using namespace v2;
+
+ {
+ transaction t (db->begin ());
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ t.commit ();
+ }
+
+ // PostgreSQL cannot continue a transaction after a query failed.
+ //
+ assert (db->schema_version () == 0);
+
+ {
+ transaction t (db->begin ());
+ schema_catalog::create_schema (*db, "", false);
+
+ assert (db->schema_version () == 1 && !db->schema_migration ());
+
+ schema_catalog::migrate_schema (*db, 2);
+ t.commit ();
+ }
+
+ assert (db->schema_version () == 2 && !db->schema_migration ());
+
+ {
+ transaction t (db->begin ());
+ object1 o1 (1);
+ o1.num = 123;
+ db->persist (o1);
+ t.commit ();
+ }
+ break;
+ }
+ case 2:
+ {
+ using namespace v2;
+ using namespace v3;
+
+ {
+ assert (db->schema_version () == 2 && !db->schema_migration ());
+
+ transaction t (db->begin ());
+ schema_catalog::migrate_schema_pre (*db, 3);
+ t.commit ();
+ }
+
+ assert (db->schema_version () == 3 && db->schema_migration ());
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object1> o1 (db->load<object1> (1));
+ object2 o2 (1);
+ o2.num = o1->num;
+ db->persist (o2);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ schema_catalog::migrate_schema_post (*db, 3);
+ t.commit ();
+
+ assert (db->schema_version () == 3 && !db->schema_migration ());
+ }
+ break;
+ }
+ case 3:
+ {
+ using namespace v3;
+
+ // In transaction.
+ //
+ {
+ transaction t (db->begin ());
+ assert (db->schema_version () == 3 && !db->schema_migration ());
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object2> o2 (db->load<object2> (1));
+ assert (o2->num == 123);
+ t.commit ();
+ }
+
+ // Test the case where there is still no version table.
+ //
+ db->schema_version (0, false);
+
+ {
+ transaction t (db->begin ());
+
+#ifdef DATABASE_ORACLE
+ db->execute ("DROP TABLE \"schema_version\"");
+#else
+ db->execute ("DROP TABLE schema_version");
+#endif
+ t.commit ();
+ }
+
+ assert (db->schema_version () == 0);
+ break;
+ }
+ default:
+ {
+ cerr << "unknown pass number '" << argv[argc - 1] << "'" << endl;
+ return 1;
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/evolution/embedded/makefile b/evolution/embedded/makefile
new file mode 100644
index 0000000..dfa675a
--- /dev/null
+++ b/evolution/embedded/makefile
@@ -0,0 +1,139 @@
+# file : evolution/embedded/makefile
+# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+common.l := $(out_root)/libcommon/common/common.l
+common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+# Build.
+#
+$(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
+gen1 := $(addprefix $(out_base)/,$(genf1))
+
+genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx
+gen2 := $(addprefix $(out_base)/,$(genf2))
+
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
+--generate-schema --schema-format embedded --at-once --table-prefix evo_embedded_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
+$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
+$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(common.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Make sure testN.hxx are compiled serially since they share the
+# changelog. Also add dependency on model.hxx
+#
+$(gen2): $(gen1)
+$(gen3): $(gen2)
+$(gen): $(src_base)/model.hxx
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+name := $(subst /,-,$(subst $(src_root)/evolution/,,$(src_base)))
+
+$(dist): db_id := @database@
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): export extra_headers := model.hxx
+$(dist): export name := $(name)
+$(dist): export extra_dist := $(call vc9projs,$(name)) \
+$(call vc10projs,$(name)) $(call vc11projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(extra_headers))
+ $(call meta-automake,../template/Makefile.am)
+ $(call meta-vc9projs,../template/template,$(name))
+ $(call meta-vc10projs,../template/template,$(name))
+ $(call meta-vc11projs,../template/template,$(name))
+
+# Test.
+#
+$(test): $(driver)
+ # Base schema.
+ $(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
+ # Migration.
+ $(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
+ # Current schema.
+ $(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+ $(call message,,rm -f $(out_base)/model.xml) # Changelog.
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver model.xml $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/vc11proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+ifdef cxx_standard
+$(gen): odb_options += --std $(cxx_standard)
+$(call include,$(odb_rules))
+endif
+
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/libcommon/makefile)
diff --git a/evolution/embedded/model.hxx b/evolution/embedded/model.hxx
new file mode 100644
index 0000000..f5e6beb
--- /dev/null
+++ b/evolution/embedded/model.hxx
@@ -0,0 +1,46 @@
+// file : evolution/embedded/model.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef MODEL_VERSION
+# error model.hxx included directly
+#endif
+
+#include <odb/core.hxx>
+
+#pragma db model version(1, MODEL_VERSION)
+
+#define MODEL_NAMESPACE_IMPL(V) v##V
+#define MODEL_NAMESPACE(V) MODEL_NAMESPACE_IMPL(V)
+
+namespace MODEL_NAMESPACE(MODEL_VERSION)
+{
+#if MODEL_VERSION == 2
+ #pragma db object
+ struct object1
+ {
+ object1 (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ int num;
+ };
+#endif
+
+#if MODEL_VERSION == 3
+ #pragma db object
+ struct object2
+ {
+ object2 (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ int num;
+ };
+#endif
+}
+
+#undef MODEL_NAMESPACE
+#undef MODEL_NAMESPACE_IMPL
diff --git a/evolution/embedded/test1.hxx b/evolution/embedded/test1.hxx
new file mode 100644
index 0000000..6e7748d
--- /dev/null
+++ b/evolution/embedded/test1.hxx
@@ -0,0 +1,10 @@
+// file : evolution/embedded/test1.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST1_HXX
+#define TEST1_HXX
+
+#pragma db model version(1, 1)
+
+#endif // TEST1_HXX
diff --git a/evolution/embedded/test2.hxx b/evolution/embedded/test2.hxx
new file mode 100644
index 0000000..78578e4
--- /dev/null
+++ b/evolution/embedded/test2.hxx
@@ -0,0 +1,12 @@
+// file : evolution/embedded/test2.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST2_HXX
+#define TEST2_HXX
+
+#define MODEL_VERSION 2
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST2_HXX
diff --git a/evolution/embedded/test3.hxx b/evolution/embedded/test3.hxx
new file mode 100644
index 0000000..ce613b6
--- /dev/null
+++ b/evolution/embedded/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/embedded/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/makefile b/evolution/makefile
index 9406d55..98816a3 100644
--- a/evolution/makefile
+++ b/evolution/makefile
@@ -15,6 +15,8 @@ drop-foreign-key \
add-index \
drop-index \
combined \
+embedded \
+version \
template
default := $(out_base)/
diff --git a/evolution/template/Makefile.am b/evolution/template/Makefile.am
index b5cd2d7..2d71bc3 100644
--- a/evolution/template/Makefile.am
+++ b/evolution/template/Makefile.am
@@ -34,16 +34,27 @@ test1-odb.hxx: test1.hxx
# test2.hxx
#
driver_SOURCES += test2.hxx
-nodist_driver_SOURCES += test2-odb.cxx
-BUILT_SOURCES += test2-odb.hxx
-CLEANFILES += 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
+nodist_driver_SOURCES = test2-odb.cxx
+BUILT_SOURCES = test2-odb.hxx
+CLEANFILES = test2-odb.hxx test2-odb.ixx test2-odb.cxx test2.sql
test2-odb.hxx: test2.hxx
$(ODB) $(AM_CPPFLAGS) $(ODBCPPFLAGS) $(CPPFLAGS) $(ODBFLAGS) __value__(odb_options2) --changelog model.xml $<
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# test3.hxx
+#
+driver_SOURCES += test3.hxx
+nodist_driver_SOURCES += test3-odb.cxx
+BUILT_SOURCES += test3-odb.hxx
+CLEANFILES += test3-odb.hxx test3-odb.ixx test3-odb.cxx test3.sql \
+test3-002-pre.sql test3-002-post.sql test3-003-pre.sql test3-003-post.sql
+
+test3-odb.hxx: test3.hxx
+ $(ODB) $(AM_CPPFLAGS) $(ODBCPPFLAGS) $(CPPFLAGS) $(ODBFLAGS) __value__(odb_options3) --changelog model.xml $<
+
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
test2-odb.hxx: test1-odb.hxx
-test1-odb.hxx test2-odb.hxx: model.hxx
+test3-odb.hxx: test2-odb.hxx
+test1-odb.hxx test2-odb.hxx test3-odb.hxx: model.hxx
diff --git a/evolution/template/driver.cxx b/evolution/template/driver.cxx
index 357055d..b2ff10e 100644
--- a/evolution/template/driver.cxx
+++ b/evolution/template/driver.cxx
@@ -15,10 +15,10 @@
#include <common/common.hxx>
-#include "test1.hxx"
#include "test2.hxx"
-#include "test1-odb.hxx"
+#include "test3.hxx"
#include "test2-odb.hxx"
+#include "test3-odb.hxx"
using namespace std;
using namespace odb::core;
@@ -29,7 +29,7 @@ main (int argc, char* argv[])
try
{
auto_ptr<database> db (create_database (argc, argv, false));
- bool embedded (schema_catalog::exists (*db, "test2"));
+ bool embedded (schema_catalog::exists (*db));
// 1 - base version
// 2 - migration
@@ -46,9 +46,10 @@ main (int argc, char* argv[])
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");
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+ schema_catalog::create_schema (*db, "", false);
+ schema_catalog::migrate_schema (*db, 2);
t.commit ();
}
@@ -67,7 +68,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ schema_catalog::migrate_schema_pre (*db, 3);
t.commit ();
}
@@ -80,7 +81,7 @@ main (int argc, char* argv[])
if (embedded)
{
transaction t (db->begin ());
- schema_catalog::migrate_schema_post (*db, 3, "test2");
+ schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
break;
diff --git a/evolution/template/makefile b/evolution/template/makefile
index c3fc5f7..f3a19bd 100644
--- a/evolution/template/makefile
+++ b/evolution/template/makefile
@@ -5,7 +5,7 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test1.hxx test2.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,36 +29,41 @@ $(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 model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx
gen1 := $(addprefix $(out_base)/,$(genf1))
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
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
---generate-schema --omit-create --at-once --table-prefix evo_template_ #@@ CHANGE THIS
-$(gen1) $(dist): export odb_options1 = $(odb_common_options) --schema-name \
-test1 --init-changelog --suppress-migration
-$(gen2) $(dist): export odb_options2 = $(odb_common_options) --schema-name \
-test2
+--generate-schema --at-once --table-prefix evo_template_ #@@ CHANGE THIS
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-# Make sure test2.hxx is compiled before test1.hxx since they share the
+# Make sure testN.hxx are compiled serially since they share the
# changelog. Also add dependency on model.hxx
#
$(gen2): $(gen1)
+$(gen3): $(gen2)
$(gen): $(src_base)/model.hxx
# Alias for default target.
@@ -87,15 +92,17 @@ $(dist):
#
$(test): $(driver)
# Drop everything.
+ $(call schema,$(out_base)/test3.sql)
$(call schema,$(out_base)/test2.sql)
$(call schema,$(out_base)/test1.sql)
- # Base schema (-post is always empty).
- $(call schema,$(out_base)/test2-002-pre.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
$(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
# Migration.
- $(call schema,$(out_base)/test2-003-pre.sql)
+ $(call schema,$(out_base)/test3-003-pre.sql)
$(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
- $(call schema,$(out_base)/test2-003-post.sql)
+ $(call schema,$(out_base)/test3-003-post.sql)
# Current schema.
$(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
@@ -107,14 +114,14 @@ $(clean): \
$(addsuffix .cxx.clean,$(cxx_od)) \
$(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
$(call message,,rm -f $(out_base)/model.xml) # Changelog.
- $(call message,,rm -f $(out_base)/test2-*.sql) # Migration files.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
# Generated .gitignore.
#
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf) $(gens)
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/template/template-vc10.vcxproj b/evolution/template/template-vc10.vcxproj
index d5e7ac8..70b8687 100644
--- a/evolution/template/template-vc10.vcxproj
+++ b/evolution/template/template-vc10.vcxproj
@@ -165,20 +165,29 @@ __custom_build_entry__(
test2.hxx,
odb test2.hxx,
odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options2), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1600 -I$(SolutionDir)\..\libcommon)) test2.hxx,
-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,
-model.xml;model.hxx)
+test2-odb.hxx;test2-odb.ixx;test2-odb.cxx;test2.sql;model.xml,
+test1-odb.hxx;model.hxx)
+__custom_build_entry__(
+test3.hxx,
+odb test3.hxx,
+odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options3), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1600 -I$(SolutionDir)\..\libcommon)) test3.hxx,
+test3-odb.hxx;test3-odb.ixx;test3-odb.cxx;test3.sql;test3-002-pre.sql;test3-002-post.sql;test3-003-pre.sql;test3-003-post.sql,
+test2-odb.hxx;model.hxx)
</ItemGroup>
<ItemGroup>
__header_entry__(test1-odb.hxx)
__header_entry__(test1-odb.ixx)
__header_entry__(test2-odb.hxx)
__header_entry__(test2-odb.ixx)
+__header_entry__(test3-odb.hxx)
+__header_entry__(test3-odb.ixx)
__header_entries__(extra_headers)
</ItemGroup>
<ItemGroup>
__source_entry__(driver.cxx)
__source_entry__(test1-odb.cxx)
__source_entry__(test2-odb.cxx)
+__source_entry__(test3-odb.cxx)
__source_entries__(extra_sources)
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/evolution/template/template-vc10.vcxproj.filters b/evolution/template/template-vc10.vcxproj.filters
index c467cdc..d6ac66e 100644
--- a/evolution/template/template-vc10.vcxproj.filters
+++ b/evolution/template/template-vc10.vcxproj.filters
@@ -17,12 +17,16 @@ __header_filter_entry__(test1-odb.ixx)
__header_filter_entry__(test2.hxx)
__header_filter_entry__(test2-odb.hxx)
__header_filter_entry__(test2-odb.ixx)
+__header_filter_entry__(test3.hxx)
+__header_filter_entry__(test3-odb.hxx)
+__header_filter_entry__(test3-odb.ixx)
__header_filter_entries__(extra_headers)
</ItemGroup>
<ItemGroup>
__source_filter_entry__(driver.cxx)
__source_filter_entry__(test1-odb.cxx)
__source_filter_entry__(test2-odb.cxx)
+__source_filter_entry__(test3-odb.cxx)
__source_filter_entries__(extra_sources)
</ItemGroup>
</Project>
diff --git a/evolution/template/template-vc11.vcxproj b/evolution/template/template-vc11.vcxproj
index d3bfc99..5895a46 100644
--- a/evolution/template/template-vc11.vcxproj
+++ b/evolution/template/template-vc11.vcxproj
@@ -169,20 +169,29 @@ __custom_build_entry__(
test2.hxx,
odb test2.hxx,
odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options2), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1700 -I$(SolutionDir)\..\libcommon)) test2.hxx,
-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,
-model.xml;model.hxx)
+test2-odb.hxx;test2-odb.ixx;test2-odb.cxx;test2.sql;model.xml,
+test1-odb.hxx;model.hxx)
+__custom_build_entry__(
+test3.hxx,
+odb test3.hxx,
+odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options3), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1700 -I$(SolutionDir)\..\libcommon)) test3.hxx,
+test3-odb.hxx;test3-odb.ixx;test3-odb.cxx;test3.sql;test3-002-pre.sql;test3-002-post.sql;test3-003-pre.sql;test3-003-post.sql,
+test2-odb.hxx;model.hxx)
</ItemGroup>
<ItemGroup>
__header_entry__(test1-odb.hxx)
__header_entry__(test1-odb.ixx)
__header_entry__(test2-odb.hxx)
__header_entry__(test2-odb.ixx)
+__header_entry__(test3-odb.hxx)
+__header_entry__(test3-odb.ixx)
__header_entries__(extra_headers)
</ItemGroup>
<ItemGroup>
__source_entry__(driver.cxx)
__source_entry__(test1-odb.cxx)
__source_entry__(test2-odb.cxx)
+__source_entry__(test3-odb.cxx)
__source_entries__(extra_sources)
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
diff --git a/evolution/template/template-vc11.vcxproj.filters b/evolution/template/template-vc11.vcxproj.filters
index c467cdc..d6ac66e 100644
--- a/evolution/template/template-vc11.vcxproj.filters
+++ b/evolution/template/template-vc11.vcxproj.filters
@@ -17,12 +17,16 @@ __header_filter_entry__(test1-odb.ixx)
__header_filter_entry__(test2.hxx)
__header_filter_entry__(test2-odb.hxx)
__header_filter_entry__(test2-odb.ixx)
+__header_filter_entry__(test3.hxx)
+__header_filter_entry__(test3-odb.hxx)
+__header_filter_entry__(test3-odb.ixx)
__header_filter_entries__(extra_headers)
</ItemGroup>
<ItemGroup>
__source_filter_entry__(driver.cxx)
__source_filter_entry__(test1-odb.cxx)
__source_filter_entry__(test2-odb.cxx)
+__source_filter_entry__(test3-odb.cxx)
__source_filter_entries__(extra_sources)
</ItemGroup>
</Project>
diff --git a/evolution/template/template-vc9.vcproj b/evolution/template/template-vc9.vcproj
index 79cfb0a..4c9b465 100644
--- a/evolution/template/template-vc9.vcproj
+++ b/evolution/template/template-vc9.vcproj
@@ -339,6 +339,7 @@
__source_entry__(driver.cxx)
__source_entry__(test1-odb.cxx)
__source_entry__(test2-odb.cxx)
+__source_entry__(test3-odb.cxx)
__source_entries__(extra_sources)
</Filter>
<Filter
@@ -358,10 +359,18 @@ __file_entry_custom_build__(
test2.hxx,
odb test2.hxx,
odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options2), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1500 -I$(SolutionDir)\..\libcommon)) test2.hxx,
-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,
-model.xml;model.hxx)
+test2-odb.hxx;test2-odb.ixx;test2-odb.cxx;test2.sql;model.xml,
+test1-odb.hxx;model.hxx)
__file_entry__(test2-odb.hxx)
__file_entry__(test2-odb.ixx)
+__file_entry_custom_build__(
+test3.hxx,
+odb test3.hxx,
+odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options3), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1500 -I$(SolutionDir)\..\libcommon)) test3.hxx,
+test3-odb.hxx;test3-odb.ixx;test3-odb.cxx;test3.sql;test3-002-pre.sql;test3-002-post.sql;test3-003-pre.sql;test3-003-post.sql,
+test2-odb.hxx;model.hxx)
+__file_entry__(test3-odb.hxx)
+__file_entry__(test3-odb.ixx)
__file_entries__(extra_headers)
</Filter>
</Files>
diff --git a/evolution/template/test1.hxx b/evolution/template/test1.hxx
index 668033d..d6d4ac7 100644
--- a/evolution/template/test1.hxx
+++ b/evolution/template/test1.hxx
@@ -5,8 +5,6 @@
#ifndef TEST1_HXX
#define TEST1_HXX
-#define MODEL_VERSION 2
-#include "model.hxx"
-#undef MODEL_VERSION
+#pragma db model version(1, 1)
#endif // TEST1_HXX
diff --git a/evolution/template/test2.hxx b/evolution/template/test2.hxx
index 5b8e48c..a349f54 100644
--- a/evolution/template/test2.hxx
+++ b/evolution/template/test2.hxx
@@ -5,7 +5,7 @@
#ifndef TEST2_HXX
#define TEST2_HXX
-#define MODEL_VERSION 3
+#define MODEL_VERSION 2
#include "model.hxx"
#undef MODEL_VERSION
diff --git a/evolution/template/test3.hxx b/evolution/template/test3.hxx
new file mode 100644
index 0000000..68366f4
--- /dev/null
+++ b/evolution/template/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/template/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX
diff --git a/evolution/tester b/evolution/tester
index 3f9e7e8..9bb1ec7 100755
--- a/evolution/tester
+++ b/evolution/tester
@@ -14,17 +14,19 @@ if test -f test1.sql; then
#
# Drop everything.
+ $top_builddir/db-driver test3.sql || exit 1
$top_builddir/db-driver test2.sql || exit 1
$top_builddir/db-driver test1.sql || exit 1
- # Base schema (-post is always empty).
- $top_builddir/db-driver test2-002-pre.sql || exit 1
+ # Base schema.
+ $top_builddir/db-driver test3-002-pre.sql || exit 1
+ $top_builddir/db-driver test3-002-post.sql || exit 1
./driver --options-file "$top_builddir/db.options" 1 || exit 1
# Migration.
- $top_builddir/db-driver test2-003-pre.sql || exit 1
+ $top_builddir/db-driver test3-003-pre.sql || exit 1
./driver --options-file "$top_builddir/db.options" 2 || exit 1
- $top_builddir/db-driver test2-003-post.sql || exit 1
+ $top_builddir/db-driver test3-003-post.sql || exit 1
# Current schema.
./driver --options-file "$top_builddir/db.options" 3 || exit 1
diff --git a/evolution/tester.bat b/evolution/tester.bat
index 5b949b4..e815522 100644
--- a/evolution/tester.bat
+++ b/evolution/tester.bat
@@ -28,15 +28,21 @@ if exist test*.sql (
rem Drop everything.
rem
+ call %topdir%\%1-driver.bat test3.sql
+ if errorlevel 1 goto error
+
call %topdir%\%1-driver.bat test2.sql
if errorlevel 1 goto error
call %topdir%\%1-driver.bat test1.sql
if errorlevel 1 goto error
- rem Base schema (-post is always empty).
+ rem Base schema.
rem
- call %topdir%\%1-driver.bat test2-002-pre.sql
+ call %topdir%\%1-driver.bat test3-002-pre.sql
+ if errorlevel 1 goto error
+
+ call %topdir%\%1-driver.bat test3-002-post.sql
if errorlevel 1 goto error
%dir%\driver.exe --options-file %topdir%\%1.options 1
@@ -44,13 +50,13 @@ if exist test*.sql (
rem Migration.
rem
- call %topdir%\%1-driver.bat test2-003-pre.sql
+ call %topdir%\%1-driver.bat test3-003-pre.sql
if errorlevel 1 goto error
%dir%\driver.exe --options-file %topdir%\%1.options 2
if errorlevel 1 goto error
- call %topdir%\%1-driver.bat test2-003-post.sql
+ call %topdir%\%1-driver.bat test3-003-post.sql
if errorlevel 1 goto error
rem Current schema.
diff --git a/evolution/version/driver.cxx b/evolution/version/driver.cxx
new file mode 100644
index 0000000..d69e195
--- /dev/null
+++ b/evolution/version/driver.cxx
@@ -0,0 +1,158 @@
+// file : evolution/version/driver.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test schema version access via the database instance.
+//
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+#include <odb/schema-catalog.hxx>
+
+#include <common/config.hxx> // DATABASE_XXX
+#include <common/common.hxx>
+
+#include "test2.hxx"
+#include "test3.hxx"
+#include "test2-odb.hxx"
+#include "test3-odb.hxx"
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ auto_ptr<database> db (create_database (argc, argv, false));
+ bool embedded (schema_catalog::exists (*db));
+
+ // 1 - base version
+ // 2 - migration
+ // 3 - current version
+ //
+ unsigned short pass (*argv[argc - 1] - '0');
+
+ switch (pass)
+ {
+ case 1:
+ {
+ using namespace v2;
+
+ if (embedded)
+ {
+ transaction t (db->begin ());
+ schema_catalog::drop_schema (*db);
+ schema_catalog::drop_schema (*db, "2");
+
+ assert (db->schema_version () == 0);
+
+ schema_catalog::create_schema (*db, "", false);
+
+ assert (db->schema_version () == 1 && !db->schema_migration ());
+
+ schema_catalog::migrate_schema (*db, 2);
+ t.commit ();
+ }
+
+ assert (db->schema_version () == 2 && !db->schema_migration ());
+
+ {
+ transaction t (db->begin ());
+ object1 o1 (1);
+ o1.num = 123;
+ db->persist (o1);
+ t.commit ();
+ }
+ break;
+ }
+ case 2:
+ {
+ using namespace v2;
+ using namespace v3;
+
+ if (embedded)
+ {
+ assert (db->schema_version () == 2 && !db->schema_migration ());
+
+ transaction t (db->begin ());
+ schema_catalog::migrate_schema_pre (*db, 3);
+ t.commit ();
+ }
+
+ assert (db->schema_version () == 3 && db->schema_migration ());
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object1> o1 (db->load<object1> (1));
+ object2 o2 (1);
+ o2.num = o1->num;
+ db->persist (o2);
+ t.commit ();
+ }
+
+ if (embedded)
+ {
+ transaction t (db->begin ());
+ schema_catalog::migrate_schema_post (*db, 3);
+ t.commit ();
+
+ assert (db->schema_version () == 3 && !db->schema_migration ());
+ }
+ break;
+ }
+ case 3:
+ {
+ using namespace v3;
+
+ // In transaction.
+ //
+ {
+ transaction t (db->begin ());
+ assert (db->schema_version () == 3 && !db->schema_migration ());
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object2> o2 (db->load<object2> (1));
+ assert (o2->num == 123);
+ t.commit ();
+ }
+
+ // Test the case where there is still no version table.
+ //
+ db->schema_version (0, false);
+
+ {
+ transaction t (db->begin ());
+
+#ifdef DATABASE_ORACLE
+ db->execute ("DROP TABLE \"schema_version\"");
+#else
+ db->execute ("DROP TABLE schema_version");
+#endif
+ t.commit ();
+ }
+
+ assert (db->schema_version () == 0);
+ break;
+ }
+ default:
+ {
+ cerr << "unknown pass number '" << argv[argc - 1] << "'" << endl;
+ return 1;
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/evolution/version/makefile b/evolution/version/makefile
new file mode 100644
index 0000000..eab7cb8
--- /dev/null
+++ b/evolution/version/makefile
@@ -0,0 +1,150 @@
+# file : evolution/version/makefile
+# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := test1.hxx test2.hxx test3.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+common.l := $(out_root)/libcommon/common/common.l
+common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+# Build.
+#
+$(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
+gen1 := $(addprefix $(out_base)/,$(genf1))
+
+genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx
+gen2 := $(addprefix $(out_base)/,$(genf2))
+
+genf3 := test3-odb.hxx test3-odb.ixx test3-odb.cxx
+gen3 := $(addprefix $(out_base)/,$(genf3))
+
+genf := $(genf1) $(genf2) $(genf3)
+gen := $(gen1) $(gen2) $(gen3)
+gens := test1.sql test2.sql test3.sql test3-002-pre.sql test3-002-post.sql \
+test3-003-pre.sql test3-003-post.sql
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): odb_common_options = --database $(db_id) --generate-query \
+--generate-schema --at-once --table-prefix evo_version_
+$(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog
+$(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \
+--schema-name 2 --suppress-migration
+$(gen3) $(dist): export odb_options3 = $(odb_common_options) --omit-create
+$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml
+$(gen2): odb_options += $(odb_options2) --changelog $(out_base)/model.xml
+$(gen3): odb_options += $(odb_options3) --changelog $(out_base)/model.xml
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(common.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Make sure testN.hxx are compiled serially since they share the
+# changelog. Also add dependency on model.hxx
+#
+$(gen2): $(gen1)
+$(gen3): $(gen2)
+$(gen): $(src_base)/model.hxx
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+name := $(subst /,-,$(subst $(src_root)/evolution/,,$(src_base)))
+
+$(dist): db_id := @database@
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): export extra_headers := model.hxx
+$(dist): export name := $(name)
+$(dist): export extra_dist := $(call vc9projs,$(name)) \
+$(call vc10projs,$(name)) $(call vc11projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(extra_headers))
+ $(call meta-automake,../template/Makefile.am)
+ $(call meta-vc9projs,../template/template,$(name))
+ $(call meta-vc10projs,../template/template,$(name))
+ $(call meta-vc11projs,../template/template,$(name))
+
+# Test.
+#
+$(test): $(driver)
+ # Drop everything.
+ $(call schema,$(out_base)/test3.sql)
+ $(call schema,$(out_base)/test2.sql)
+ $(call schema,$(out_base)/test1.sql)
+ # Base schema.
+ $(call schema,$(out_base)/test3-002-pre.sql)
+ $(call schema,$(out_base)/test3-002-post.sql)
+ $(call message,test $< base,$< --options-file $(dcf_root)/db.options 1)
+ # Migration.
+ $(call schema,$(out_base)/test3-003-pre.sql)
+ $(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2)
+ $(call schema,$(out_base)/test3-003-post.sql)
+ # Current schema.
+ $(call message,test $< current,$< --options-file $(dcf_root)/db.options 3)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+ $(call message,,rm -f $(out_base)/model.xml) # Changelog.
+ $(call message,,rm -f $(out_base)/test3-*.sql) # Migration files.
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver model.xml $(genf) $(gens)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/vc11proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+ifdef cxx_standard
+$(gen): odb_options += --std $(cxx_standard)
+$(call include,$(odb_rules))
+endif
+
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/libcommon/makefile)
diff --git a/evolution/version/model.hxx b/evolution/version/model.hxx
new file mode 100644
index 0000000..b30a194
--- /dev/null
+++ b/evolution/version/model.hxx
@@ -0,0 +1,46 @@
+// file : evolution/version/model.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef MODEL_VERSION
+# error model.hxx included directly
+#endif
+
+#include <odb/core.hxx>
+
+#pragma db model version(1, MODEL_VERSION)
+
+#define MODEL_NAMESPACE_IMPL(V) v##V
+#define MODEL_NAMESPACE(V) MODEL_NAMESPACE_IMPL(V)
+
+namespace MODEL_NAMESPACE(MODEL_VERSION)
+{
+#if MODEL_VERSION == 2
+ #pragma db object
+ struct object1
+ {
+ object1 (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ int num;
+ };
+#endif
+
+#if MODEL_VERSION == 3
+ #pragma db object
+ struct object2
+ {
+ object2 (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ int num;
+ };
+#endif
+}
+
+#undef MODEL_NAMESPACE
+#undef MODEL_NAMESPACE_IMPL
diff --git a/evolution/version/test1.hxx b/evolution/version/test1.hxx
new file mode 100644
index 0000000..138fd09
--- /dev/null
+++ b/evolution/version/test1.hxx
@@ -0,0 +1,10 @@
+// file : evolution/version/test1.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST1_HXX
+#define TEST1_HXX
+
+#pragma db model version(1, 1)
+
+#endif // TEST1_HXX
diff --git a/evolution/version/test2.hxx b/evolution/version/test2.hxx
new file mode 100644
index 0000000..60af1c0
--- /dev/null
+++ b/evolution/version/test2.hxx
@@ -0,0 +1,12 @@
+// file : evolution/version/test2.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST2_HXX
+#define TEST2_HXX
+
+#define MODEL_VERSION 2
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST2_HXX
diff --git a/evolution/version/test3.hxx b/evolution/version/test3.hxx
new file mode 100644
index 0000000..1e4deb3
--- /dev/null
+++ b/evolution/version/test3.hxx
@@ -0,0 +1,12 @@
+// file : evolution/version/test3.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#define MODEL_VERSION 3
+#include "model.hxx"
+#undef MODEL_VERSION
+
+#endif // TEST3_HXX