From 516523183fad016a26c7400d784eb9c0343b7964 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 3 Apr 2013 11:22:42 +0200 Subject: Generate add/drop table migration statements --- Makefile.am | 2 +- build.bat | 6 + common/changelog/makefile | 5 +- common/makefile | 2 +- evolution/Makefile.am | 6 + evolution/add-table/driver.cxx | 107 +++++++ evolution/add-table/makefile | 142 +++++++++ evolution/add-table/model.hxx | 49 +++ evolution/add-table/test1.hxx | 12 + evolution/add-table/test2.hxx | 12 + evolution/drop-table/driver.cxx | 111 +++++++ evolution/drop-table/makefile | 142 +++++++++ evolution/drop-table/model.hxx | 49 +++ evolution/drop-table/test1.hxx | 12 + evolution/drop-table/test2.hxx | 12 + evolution/evolution-vc10.sln | 15 + evolution/evolution-vc11.sln | 15 + evolution/evolution-vc9.sln | 15 + evolution/makefile | 52 ++++ evolution/template/Makefile.am | 49 +++ evolution/template/driver.cxx | 100 ++++++ evolution/template/makefile | 142 +++++++++ evolution/template/model.hxx | 41 +++ evolution/template/template-vc10.vcxproj | 187 ++++++++++++ evolution/template/template-vc10.vcxproj.filters | 28 ++ evolution/template/template-vc11.vcxproj | 191 ++++++++++++ evolution/template/template-vc11.vcxproj.filters | 28 ++ evolution/template/template-vc9.vcproj | 370 +++++++++++++++++++++++ evolution/template/test1.hxx | 12 + evolution/template/test2.hxx | 12 + evolution/test.bat | 80 +++++ evolution/tester | 38 +++ evolution/tester.bat | 82 +++++ makefile | 4 +- test.bat | 2 +- 35 files changed, 2125 insertions(+), 7 deletions(-) create mode 100644 evolution/Makefile.am create mode 100644 evolution/add-table/driver.cxx create mode 100644 evolution/add-table/makefile create mode 100644 evolution/add-table/model.hxx create mode 100644 evolution/add-table/test1.hxx create mode 100644 evolution/add-table/test2.hxx create mode 100644 evolution/drop-table/driver.cxx create mode 100644 evolution/drop-table/makefile create mode 100644 evolution/drop-table/model.hxx create mode 100644 evolution/drop-table/test1.hxx create mode 100644 evolution/drop-table/test2.hxx create mode 100644 evolution/evolution-vc10.sln create mode 100644 evolution/evolution-vc11.sln create mode 100644 evolution/evolution-vc9.sln create mode 100644 evolution/makefile create mode 100644 evolution/template/Makefile.am create mode 100644 evolution/template/driver.cxx create mode 100644 evolution/template/makefile create mode 100644 evolution/template/model.hxx create mode 100644 evolution/template/template-vc10.vcxproj create mode 100644 evolution/template/template-vc10.vcxproj.filters create mode 100644 evolution/template/template-vc11.vcxproj create mode 100644 evolution/template/template-vc11.vcxproj.filters create mode 100644 evolution/template/template-vc9.vcproj create mode 100644 evolution/template/test1.hxx create mode 100644 evolution/template/test2.hxx create mode 100644 evolution/test.bat create mode 100755 evolution/tester create mode 100644 evolution/tester.bat diff --git a/Makefile.am b/Makefile.am index ed99581..1c7c524 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ # copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC # license : GNU GPL v2; see accompanying LICENSE file -SUBDIRS = libcommon common +SUBDIRS = libcommon common evolution if ODB_TESTS_BOOST SUBDIRS += boost diff --git a/build.bat b/build.bat index 0f55142..8c7b5ad 100644 --- a/build.bat +++ b/build.bat @@ -93,6 +93,12 @@ for %%c in (%confs%) do ( ) ) +for %%c in (%confs%) do ( + for %%p in (%plats%) do ( + call :run_build evolution/evolution-%1-vc%vcver%.sln %%c %%p + ) +) + if not "_%failed%_" == "__" goto error echo. diff --git a/common/changelog/makefile b/common/changelog/makefile index 0e4ecf9..8d5e96d 100644 --- a/common/changelog/makefile +++ b/common/changelog/makefile @@ -38,8 +38,8 @@ gen := $(addprefix $(out_base)/,$(genf)) $(gen): $(odb) FORCE # Force regeneration even if up to date. $(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --database $(db_id) \ ---generate-schema-only --schema-format sql --changelog-dir $(out_base) +$(gen): export odb_options += --database $(db_id) --generate-schema-only \ +--schema-format sql --suppress-migration --changelog-dir $(out_base) $(gen): cpp_options := -I$(src_base) $(gen): $(common.l.cpp-options) @@ -47,6 +47,7 @@ ifdef STEP ifeq ($(STEP),1) $(gen): cpp_options += -DBVER=1 -DCVER=1 # Initialize. +$(gen): odb_options += --init-changelog # Suppress notice. else ifeq ($(STEP),2) $(gen): cpp_options += -DBVER=1 -DCVER=2 # Diff. else ifeq ($(STEP),3) diff --git a/common/makefile b/common/makefile index 3eb05e2..ebf969a 100644 --- a/common/makefile +++ b/common/makefile @@ -79,7 +79,7 @@ $(dist): name := $(name) $(dist): export dirs := $(filter-out $(no_dist_tests),$(tests)) $(dist): export thread_dirs := $(thread_tests) $(dist): export cxx11_dirs := $(cxx11_tests) -$(dist): export extra_dist := test.bat $(call vc9slns,$(name)) \ +$(dist): export extra_dist := test.bat $(call vc9slns,$(name)) \ $(call vc10slns,$(name)) $(call vc11slns,$(name)) $(dist): $(addprefix $(out_base)/,$(addsuffix /.dist,$(all_tests))) $(call meta-automake) diff --git a/evolution/Makefile.am b/evolution/Makefile.am new file mode 100644 index 0000000..1c12027 --- /dev/null +++ b/evolution/Makefile.am @@ -0,0 +1,6 @@ +# file : evolution/Makefile.am +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +SUBDIRS = __path__(dirs) +EXTRA_DIST = __file__(extra_dist) diff --git a/evolution/add-table/driver.cxx b/evolution/add-table/driver.cxx new file mode 100644 index 0000000..7e9b2ad --- /dev/null +++ b/evolution/add-table/driver.cxx @@ -0,0 +1,107 @@ +// file : evolution/add-table/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test adding a new table (object, container). +// + +#include // std::auto_ptr +#include +#include + +#include +#include + +#include + +#include "test1.hxx" +#include "test2.hxx" +#include "test1-odb.hxx" +#include "test2-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // 1 - base version + // 2 - migration + // 3 - current version + // + unsigned short pass (*argv[argc - 1] - '0'); + + switch (pass) + { + case 1: + { + using namespace v2; + + object o (1); + o.str = "abc"; + + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + break; + } + case 2: + { + using namespace v3; + + object1 o1; + o1.nums.push_back (1); + o1.nums.push_back (2); + o1.nums.push_back (3); + + { + transaction t (db->begin ()); + o1.o = db->load (1); + db->persist (o1); + t.commit (); + } + + break; + } + case 3: + { + using namespace v3; + + typedef odb::query query; + typedef odb::result result; + + { + transaction t (db->begin ()); + + result r (db->query (query::o->str == "abc")); + result::iterator i (r.begin ()), e (r.end ()); + + assert (i != e && + i->o->id_ == 1 && + i->nums[0] == 1 && i->nums[1] == 2 && i->nums[2] == 3); + assert (++i == e); + + t.commit (); + } + + 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/add-table/makefile b/evolution/add-table/makefile new file mode 100644 index 0000000..36639ac --- /dev/null +++ b/evolution/add-table/makefile @@ -0,0 +1,142 @@ +# file : evolution/add-table/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 +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 test1.sql model.xml +gen1 := $(addprefix $(out_base)/,$(genf1)) + +genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx test2.sql \ +test2-002-pre.sql test2-002-post.sql test2-003-pre.sql test2-003-post.sql +gen2 := $(addprefix $(out_base)/,$(genf2)) + +genf := $(genf1) $(genf2) +gen := $(gen1) $(gen2) + +$(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 +$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml +$(gen2): odb_options += $(odb_options2) --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 +# changelog. Also add dependency on model.hxx +# +$(gen2): $(gen1) +$(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)/test1.sql) + $(call schema,$(out_base)/test2.sql) + # Base schema (-post is always empty). + $(call schema,$(out_base)/test2-002-pre.sql) + $(call message,test $< base,$< --options-file $(dcf_root)/db.options 1) + # Migration. + $(call schema,$(out_base)/test2-003-pre.sql) + $(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2) + $(call schema,$(out_base)/test2-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)/test2-*.sql) # Migration files. + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(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/add-table/model.hxx b/evolution/add-table/model.hxx new file mode 100644 index 0000000..808e647 --- /dev/null +++ b/evolution/add-table/model.hxx @@ -0,0 +1,49 @@ +// file : evolution/add-table/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 +#include + +#include + +#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) +{ + #pragma db object + struct object + { + object (unsigned long id = 0): id_ (id) {} + + #pragma db id + unsigned long id_; + + std::string str; + }; + +#if MODEL_VERSION == 3 + #pragma db object + struct object1 + { + object1 (): o (0) {} + ~object1 () {delete o;} + + #pragma db id auto + unsigned long id_; + + object* o; + std::vector nums; + }; +#endif +} + +#undef MODEL_NAMESPACE +#undef MODEL_NAMESPACE_IMPL diff --git a/evolution/add-table/test1.hxx b/evolution/add-table/test1.hxx new file mode 100644 index 0000000..2e9b12d --- /dev/null +++ b/evolution/add-table/test1.hxx @@ -0,0 +1,12 @@ +// file : evolution/add-table/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 + +#define MODEL_VERSION 2 +#include "model.hxx" +#undef MODEL_VERSION + +#endif // TEST1_HXX diff --git a/evolution/add-table/test2.hxx b/evolution/add-table/test2.hxx new file mode 100644 index 0000000..0de1de5 --- /dev/null +++ b/evolution/add-table/test2.hxx @@ -0,0 +1,12 @@ +// file : evolution/add-table/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 3 +#include "model.hxx" +#undef MODEL_VERSION + +#endif // TEST2_HXX diff --git a/evolution/drop-table/driver.cxx b/evolution/drop-table/driver.cxx new file mode 100644 index 0000000..2a48ed5 --- /dev/null +++ b/evolution/drop-table/driver.cxx @@ -0,0 +1,111 @@ +// file : evolution/drop-table/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test dropping a table (object, container). +// + +#include // std::auto_ptr +#include +#include + +#include +#include + +#include + +#include "test1.hxx" +#include "test2.hxx" +#include "test1-odb.hxx" +#include "test2-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // 1 - base version + // 2 - migration + // 3 - current version + // + unsigned short pass (*argv[argc - 1] - '0'); + + switch (pass) + { + case 1: + { + using namespace v2; + + object1 o1; + o1.o = new object (1); + o1.o->str = "abc"; + o1.nums.push_back (1); + o1.nums.push_back (2); + o1.nums.push_back (3); + + { + transaction t (db->begin ()); + db->persist (o1.o); + db->persist (o1); + t.commit (); + } + break; + } + case 2: + { + using namespace v2; // @@ v3; soft immediate drop + + // Both object and object1 are still there so we can migrate the data. + // + typedef odb::query query; + typedef odb::result result; + + { + transaction t (db->begin ()); + + result r (db->query (query::o->str == "abc")); + result::iterator i (r.begin ()), e (r.end ()); + + assert (i != e && + i->o->id_ == 1 && + i->nums[0] == 1 && i->nums[1] == 2 && i->nums[2] == 3); + assert (++i == e); + + t.commit (); + } + + break; + } + case 3: + { + using namespace v3; + + // Only object is still there. + // + { + transaction t (db->begin ()); + auto_ptr p (db->load (1)); + assert (p->str == "abc"); + t.commit (); + } + + 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/drop-table/makefile b/evolution/drop-table/makefile new file mode 100644 index 0000000..be85fd6 --- /dev/null +++ b/evolution/drop-table/makefile @@ -0,0 +1,142 @@ +# file : evolution/drop-table/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 +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 test1.sql model.xml +gen1 := $(addprefix $(out_base)/,$(genf1)) + +genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx test2.sql \ +test2-002-pre.sql test2-002-post.sql test2-003-pre.sql test2-003-post.sql +gen2 := $(addprefix $(out_base)/,$(genf2)) + +genf := $(genf1) $(genf2) +gen := $(gen1) $(gen2) + +$(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 +$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml +$(gen2): odb_options += $(odb_options2) --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 +# changelog. Also add dependency on model.hxx +# +$(gen2): $(gen1) +$(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)/test1.sql) + $(call schema,$(out_base)/test2.sql) + # Base schema (-post is always empty). + $(call schema,$(out_base)/test2-002-pre.sql) + $(call message,test $< base,$< --options-file $(dcf_root)/db.options 1) + # Migration. + $(call schema,$(out_base)/test2-003-pre.sql) + $(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2) + $(call schema,$(out_base)/test2-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)/test2-*.sql) # Migration files. + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(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/drop-table/model.hxx b/evolution/drop-table/model.hxx new file mode 100644 index 0000000..f5bbd9e --- /dev/null +++ b/evolution/drop-table/model.hxx @@ -0,0 +1,49 @@ +// file : evolution/drop-table/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 +#include + +#include + +#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) +{ + #pragma db object + struct object + { + object (unsigned long id = 0): id_ (id) {} + + #pragma db id + unsigned long id_; + + std::string str; + }; + +#if MODEL_VERSION == 2 + #pragma db object + struct object1 + { + object1 (): o (0) {} + ~object1 () {delete o;} + + #pragma db id auto + unsigned long id_; + + object* o; + std::vector nums; + }; +#endif +} + +#undef MODEL_NAMESPACE +#undef MODEL_NAMESPACE_IMPL diff --git a/evolution/drop-table/test1.hxx b/evolution/drop-table/test1.hxx new file mode 100644 index 0000000..c1319c8 --- /dev/null +++ b/evolution/drop-table/test1.hxx @@ -0,0 +1,12 @@ +// file : evolution/drop-table/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 + +#define MODEL_VERSION 2 +#include "model.hxx" +#undef MODEL_VERSION + +#endif // TEST1_HXX diff --git a/evolution/drop-table/test2.hxx b/evolution/drop-table/test2.hxx new file mode 100644 index 0000000..2178732 --- /dev/null +++ b/evolution/drop-table/test2.hxx @@ -0,0 +1,12 @@ +// file : evolution/drop-table/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 3 +#include "model.hxx" +#undef MODEL_VERSION + +#endif // TEST2_HXX diff --git a/evolution/evolution-vc10.sln b/evolution/evolution-vc10.sln new file mode 100644 index 0000000..9a5dc32 --- /dev/null +++ b/evolution/evolution-vc10.sln @@ -0,0 +1,15 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +__projects__ +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +__solution_configurations__ + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +__project_configurations__ + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/evolution/evolution-vc11.sln b/evolution/evolution-vc11.sln new file mode 100644 index 0000000..436eeea --- /dev/null +++ b/evolution/evolution-vc11.sln @@ -0,0 +1,15 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +__projects__ +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +__solution_configurations__ + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +__project_configurations__ + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/evolution/evolution-vc9.sln b/evolution/evolution-vc9.sln new file mode 100644 index 0000000..2ec9432 --- /dev/null +++ b/evolution/evolution-vc9.sln @@ -0,0 +1,15 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +__projects__ +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution +__solution_configurations__ + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution +__project_configurations__ + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/evolution/makefile b/evolution/makefile new file mode 100644 index 0000000..f9e1d25 --- /dev/null +++ b/evolution/makefile @@ -0,0 +1,52 @@ +# file : evolution/makefile +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : GNU GPL; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make + +tests := \ +add-table \ +drop-table \ +template + +default := $(out_base)/ +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +all_tests := $(tests) +build_tests := $(tests) + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(build_tests))) + +name := evolution +$(dist): name := $(name) +$(dist): data_dist := tester.bat +$(dist): exec_dist := tester +$(dist): export dirs := $(filter-out $(no_dist_tests),$(tests)) +$(dist): export extra_dist := $(data_dist) $(exec_dist) test.bat \ +$(call vc9slns,$(name)) $(call vc10slns,$(name)) $(call vc11slns,$(name)) +$(dist): $(addprefix $(out_base)/,$(addsuffix /.dist,$(all_tests))) + $(call dist-data,$(data_dist)) + $(call dist-exec,$(exec_dist)) + $(call meta-automake) + $(call meta-vc9slns,$(name)) + $(call meta-vc10slns,$(name)) + $(call meta-vc11slns,$(name)) + $(call meta-vctest,$(name)-mysql-vc10.sln,test.bat) + +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(build_tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(all_tests))) + +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9sln.make) +$(call include,$(bld_root)/meta/vc10sln.make) +$(call include,$(bld_root)/meta/vc11sln.make) +$(call include,$(bld_root)/meta/vctest.make) +$(call include,$(bld_root)/meta/automake.make) + +ifneq ($(filter $(MAKECMDGOALS),dist clean),) +$(foreach t,$(all_tests),$(call import,$(src_base)/$t/makefile)) +else +$(foreach t,$(build_tests),$(call import,$(src_base)/$t/makefile)) +endif diff --git a/evolution/template/Makefile.am b/evolution/template/Makefile.am new file mode 100644 index 0000000..b5cd2d7 --- /dev/null +++ b/evolution/template/Makefile.am @@ -0,0 +1,49 @@ +# file : evolution/template/Makefile.am +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +EXTRA_DIST = __file__(extra_dist) + +noinst_PROGRAMS = driver +driver_SOURCES = driver.cxx __path__(extra_sources) __path__(extra_headers) +LDADD = $(top_builddir)/libcommon/common/libcommon.la +AM_CPPFLAGS = -I'$(top_builddir)/libcommon' -I'$(top_srcdir)/libcommon' +AM_CPPFLAGS += -I'$(builddir)' -I'$(srcdir)' + +TESTS=$(top_srcdir)/evolution/tester +TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; + +ODB = @ODB@ +ODBFLAGS = @ODBFLAGS@ +ODBCPPFLAGS = @ODBCPPFLAGS@ + +if HAVE_CXX11 +ODBFLAGS += --std c++11 +endif + +# test1.hxx +# +driver_SOURCES += test1.hxx +nodist_driver_SOURCES = test1-odb.cxx +BUILT_SOURCES = test1-odb.hxx +CLEANFILES = test1-odb.hxx test1-odb.ixx test1-odb.cxx test1.sql model.xml + +test1-odb.hxx: test1.hxx + $(ODB) $(AM_CPPFLAGS) $(ODBCPPFLAGS) $(CPPFLAGS) $(ODBFLAGS) __value__(odb_options1) --changelog model.xml $< + +# 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 + +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 +# changelog. Also add dependency on model.hxx +# +test2-odb.hxx: test1-odb.hxx +test1-odb.hxx test2-odb.hxx: model.hxx diff --git a/evolution/template/driver.cxx b/evolution/template/driver.cxx new file mode 100644 index 0000000..1e2ad90 --- /dev/null +++ b/evolution/template/driver.cxx @@ -0,0 +1,100 @@ +// file : evolution/template/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// PLACE TEST DESCRIPTION HERE +// + +#include // std::auto_ptr +#include +#include + +#include +#include + +#include + +#include "test1.hxx" +#include "test2.hxx" +#include "test1-odb.hxx" +#include "test2-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // 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 ()); + dummy d (1); + db->persist (d); + t.commit (); + } + break; + } + case 2: + { + using namespace v3; + + { + transaction t (db->begin ()); + auto_ptr p (db->load (1)); + t.commit (); + } + break; + } + case 3: + { + using namespace v3; + + object o; + + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p (db->load (o.id_)); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p (db->load (1)); + t.commit (); + } + 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/template/makefile b/evolution/template/makefile new file mode 100644 index 0000000..0ac359f --- /dev/null +++ b/evolution/template/makefile @@ -0,0 +1,142 @@ +# file : evolution/template/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 +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 test1.sql model.xml +gen1 := $(addprefix $(out_base)/,$(genf1)) + +genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx test2.sql \ +test2-002-pre.sql test2-002-post.sql test2-003-pre.sql test2-003-post.sql +gen2 := $(addprefix $(out_base)/,$(genf2)) + +genf := $(genf1) $(genf2) +gen := $(gen1) $(gen2) + +$(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 +$(gen1): odb_options += $(odb_options1) --changelog $(out_base)/model.xml +$(gen2): odb_options += $(odb_options2) --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 +# changelog. Also add dependency on model.hxx +# +$(gen2): $(gen1) +$(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)/test1.sql) + $(call schema,$(out_base)/test2.sql) + # Base schema (-post is always empty). + $(call schema,$(out_base)/test2-002-pre.sql) + $(call message,test $< base,$< --options-file $(dcf_root)/db.options 1) + # Migration. + $(call schema,$(out_base)/test2-003-pre.sql) + $(call message,test $< migration,$< --options-file $(dcf_root)/db.options 2) + $(call schema,$(out_base)/test2-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)/test2-*.sql) # Migration files. + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(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/template/model.hxx b/evolution/template/model.hxx new file mode 100644 index 0000000..ef6c9d0 --- /dev/null +++ b/evolution/template/model.hxx @@ -0,0 +1,41 @@ +// file : evolution/template/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 + +#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 == 3 + #pragma db object + struct object + { + #pragma db id auto + unsigned long id_; + }; +#endif + + // The presence of this object makes sure that there are no empty + // changesets and we get the complete set of migration files. + // + #pragma db object + struct dummy + { + dummy (unsigned long id = 0): id_ (id) {} + + #pragma db id + unsigned long id_; + }; +} + +#undef MODEL_NAMESPACE +#undef MODEL_NAMESPACE_IMPL diff --git a/evolution/template/template-vc10.vcxproj b/evolution/template/template-vc10.vcxproj new file mode 100644 index 0000000..d5e7ac8 --- /dev/null +++ b/evolution/template/template-vc10.vcxproj @@ -0,0 +1,187 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {__uuid__()} + Win32Proj + __value__(name) + + + + Application + true + Unicode + + + Application + true + Unicode + + + Application + false + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(Configuration)\ + driver + + + true + $(Platform)\$(Configuration)\ + driver + + + false + $(Configuration)\ + driver + + + false + $(Platform)\$(Configuration)\ + driver + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib\common-d.lib;odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) + Console + true + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib64\common-d.lib;odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib\common.lib;odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib64\common.lib;odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) + Console + true + true + true + + + +__custom_build_entry__( +test1.hxx, +odb test1.hxx, +odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options1), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1600 -I$(SolutionDir)\..\libcommon)) test1.hxx, +test1-odb.hxx;test1-odb.ixx;test1-odb.cxx;test1.sql;model.xml, +model.hxx) +__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) + + +__header_entry__(test1-odb.hxx) +__header_entry__(test1-odb.ixx) +__header_entry__(test2-odb.hxx) +__header_entry__(test2-odb.ixx) +__header_entries__(extra_headers) + + +__source_entry__(driver.cxx) +__source_entry__(test1-odb.cxx) +__source_entry__(test2-odb.cxx) +__source_entries__(extra_sources) + + + + + diff --git a/evolution/template/template-vc10.vcxproj.filters b/evolution/template/template-vc10.vcxproj.filters new file mode 100644 index 0000000..c467cdc --- /dev/null +++ b/evolution/template/template-vc10.vcxproj.filters @@ -0,0 +1,28 @@ + + + + + {__uuid__()} + cxx + + + {__uuid__()} + h;hxx;ixx;txx + + + +__header_filter_entry__(test1.hxx) +__header_filter_entry__(test1-odb.hxx) +__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_entries__(extra_headers) + + +__source_filter_entry__(driver.cxx) +__source_filter_entry__(test1-odb.cxx) +__source_filter_entry__(test2-odb.cxx) +__source_filter_entries__(extra_sources) + + diff --git a/evolution/template/template-vc11.vcxproj b/evolution/template/template-vc11.vcxproj new file mode 100644 index 0000000..d3bfc99 --- /dev/null +++ b/evolution/template/template-vc11.vcxproj @@ -0,0 +1,191 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {__uuid__()} + Win32Proj + __value__(name) + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + $(Configuration)\ + driver + + + true + $(Platform)\$(Configuration)\ + driver + + + false + $(Configuration)\ + driver + + + false + $(Platform)\$(Configuration)\ + driver + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib\common-d.lib;odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) + Console + true + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib64\common-d.lib;odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib\common.lib;odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;_CONSOLE;__upcase__(database_)__upcase__(__value__(database));HAVE_CONFIG_VC_H;%(PreprocessorDefinitions) + $(SolutionDir)\..\libcommon + 4068;4355;4800;4290;%(DisableSpecificWarnings) + + + $(SolutionDir)\..\libcommon\lib64\common.lib;odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) + Console + true + true + true + + + +__custom_build_entry__( +test1.hxx, +odb test1.hxx, +odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options1), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1700 -I$(SolutionDir)\..\libcommon)) test1.hxx, +test1-odb.hxx;test1-odb.ixx;test1-odb.cxx;test1.sql;model.xml, +model.hxx) +__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) + + +__header_entry__(test1-odb.hxx) +__header_entry__(test1-odb.ixx) +__header_entry__(test2-odb.hxx) +__header_entry__(test2-odb.ixx) +__header_entries__(extra_headers) + + +__source_entry__(driver.cxx) +__source_entry__(test1-odb.cxx) +__source_entry__(test2-odb.cxx) +__source_entries__(extra_sources) + + + + + diff --git a/evolution/template/template-vc11.vcxproj.filters b/evolution/template/template-vc11.vcxproj.filters new file mode 100644 index 0000000..c467cdc --- /dev/null +++ b/evolution/template/template-vc11.vcxproj.filters @@ -0,0 +1,28 @@ + + + + + {__uuid__()} + cxx + + + {__uuid__()} + h;hxx;ixx;txx + + + +__header_filter_entry__(test1.hxx) +__header_filter_entry__(test1-odb.hxx) +__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_entries__(extra_headers) + + +__source_filter_entry__(driver.cxx) +__source_filter_entry__(test1-odb.cxx) +__source_filter_entry__(test2-odb.cxx) +__source_filter_entries__(extra_sources) + + diff --git a/evolution/template/template-vc9.vcproj b/evolution/template/template-vc9.vcproj new file mode 100644 index 0000000..79cfb0a --- /dev/null +++ b/evolution/template/template-vc9.vcproj @@ -0,0 +1,370 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +__source_entry__(driver.cxx) +__source_entry__(test1-odb.cxx) +__source_entry__(test2-odb.cxx) +__source_entries__(extra_sources) + + +__file_entry_custom_build__( +test1.hxx, +odb test1.hxx, +odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options1), @database@, __value__(database)) --changelog model.xml -DHAVE_CONFIG_VC_H -DODB_MSC_VER=1500 -I$(SolutionDir)\..\libcommon)) test1.hxx, +test1-odb.hxx;test1-odb.ixx;test1-odb.cxx;test1.sql;model.xml, +model.hxx) +__file_entry__(test1-odb.hxx) +__file_entry__(test1-odb.ixx) +__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) +__file_entry__(test2-odb.hxx) +__file_entry__(test2-odb.ixx) +__file_entries__(extra_headers) + + + + + diff --git a/evolution/template/test1.hxx b/evolution/template/test1.hxx new file mode 100644 index 0000000..668033d --- /dev/null +++ b/evolution/template/test1.hxx @@ -0,0 +1,12 @@ +// file : evolution/template/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 + +#define MODEL_VERSION 2 +#include "model.hxx" +#undef MODEL_VERSION + +#endif // TEST1_HXX diff --git a/evolution/template/test2.hxx b/evolution/template/test2.hxx new file mode 100644 index 0000000..5b8e48c --- /dev/null +++ b/evolution/template/test2.hxx @@ -0,0 +1,12 @@ +// file : evolution/template/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 3 +#include "model.hxx" +#undef MODEL_VERSION + +#endif // TEST2_HXX diff --git a/evolution/test.bat b/evolution/test.bat new file mode 100644 index 0000000..b86171c --- /dev/null +++ b/evolution/test.bat @@ -0,0 +1,80 @@ +@echo off +rem file : evolution/test.bat +rem copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +rem license : GNU GPL v2; see accompanying LICENSE file + +setlocal + +set "tests=__path__(dirs) __path__(thread_dirs)" +set "confs=__path__(configurations)" +set "plats=__path__(platforms)" +set "curdir=%CD%" +set "topdir=%curdir%\.." +set "failed=" + +if "_%1_" == "__" ( + echo no database specified + goto usage +) + +goto start + +rem +rem %1 - test directory +rem %2 - configuration +rem %3 - platform +rem %4 - database +rem +:run_test + cd %1 + + if "_%3_" == "_Win32_" ( + set "dir=%2" + ) else ( + set "dir=%3\%2" + ) + + if exist %dir%\driver.exe ( + echo %1\%3\%2 + call %topdir%\evolution\tester.bat %4 %2 %3 + if errorlevel 1 ( + set "failed=%failed% %1\%3\%2" + ) + ) + + cd %curdir% +goto :eof + +:start + +for %%t in (%tests%) do ( + for %%c in (%confs%) do ( + for %%p in (%plats%) do ( + call :run_test %%t %%c %%p %1 + ) + ) +) + +if not "_%failed%_" == "__" goto error + +echo. +echo ALL TESTS PASSED +echo. +goto end + +:usage +echo. +echo usage: test.bat database +echo. + +:error +if not "_%failed%_" == "__" ( + echo. + for %%t in (%failed%) do echo FAILED: %%t + echo. +) +endlocal +exit /b 1 + +:end +endlocal diff --git a/evolution/tester b/evolution/tester new file mode 100755 index 0000000..5ccb839 --- /dev/null +++ b/evolution/tester @@ -0,0 +1,38 @@ +#! /bin/sh + +# file : evolution/tester.in +# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +# +# Run an evolution test. The test driver is in the current directory. The +# data files, if any, are in $srcdir. +# + +if test -f test1.sql; then + # Standalone schema. + # + + # Drop everything. + $top_builddir/db-driver test1.sql || exit 1 + $top_builddir/db-driver test2.sql || exit 1 + + # Base schema (-post is always empty). + $top_builddir/db-driver test2-002-pre.sql || exit 1 + ./driver --options-file "$top_builddir/db.options" 1 || exit 1 + + # Migration. + $top_builddir/db-driver test2-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 + + # Current schema. + ./driver --options-file "$top_builddir/db.options" 3 || exit 1 + +else + # Embedded schema. Just run the driver. + # + ./driver --options-file "$top_builddir/db.options" 1 || exit 1 + ./driver --options-file "$top_builddir/db.options" 2 || exit 1 + ./driver --options-file "$top_builddir/db.options" 3 || exit 1 +fi diff --git a/evolution/tester.bat b/evolution/tester.bat new file mode 100644 index 0000000..ea40b35 --- /dev/null +++ b/evolution/tester.bat @@ -0,0 +1,82 @@ +@echo off +rem file : evolution/tester.bat +rem copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +rem license : GNU GPL v2; see accompanying LICENSE file + +rem +rem Run an evolution test. The test directory is the current directory. +rem +rem %1 database +rem %2 configuration, for example, Debug or Release +rem %3 platform, for example Win32 or x64 +rem topdir variable containing the path to top project directory +rem + +setlocal + +set "PATH=%topdir%\libcommon\bin64;%topdir%\libcommon\bin;%PATH%" + +if "_%3_" == "_Win32_" ( + set "dir=%2" +) else ( + set "dir=%3\%2" +) + +if exist test*.sql ( + rem Standalone schema. + rem + + rem Drop everything. + rem + call %topdir%\%1-driver.bat test1.sql + if errorlevel 1 goto error + + call %topdir%\%1-driver.bat test2.sql + if errorlevel 1 goto error + + rem Base schema (-post is always empty). + rem + call %topdir%\%1-driver.bat test2-002-pre.sql + if errorlevel 1 goto error + + %dir%\driver.exe --options-file %topdir%\%1.options 1 + if errorlevel 1 goto error + + rem Migration. + rem + call %topdir%\%1-driver.bat test2-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 + if errorlevel 1 goto error + + rem Current schema. + rem + %dir%\driver.exe --options-file %topdir%\%1.options 3 + if errorlevel 1 goto error + +) else ( + + rem Embedded schema. Just run the driver. + rem + %dir%\driver.exe --options-file %topdir%\%1.options 1 + if errorlevel 1 goto error + + %dir%\driver.exe --options-file %topdir%\%1.options 2 + if errorlevel 1 goto error + + %dir%\driver.exe --options-file %topdir%\%1.options 3 + if errorlevel 1 goto error +) + +goto end + +:error +endlocal +exit /b 1 + +:end +endlocal diff --git a/makefile b/makefile index 1391a20..99c61e7 100644 --- a/makefile +++ b/makefile @@ -4,8 +4,8 @@ include $(dir $(lastword $(MAKEFILE_LIST)))build/bootstrap.make -all_dirs := libcommon common mysql sqlite pgsql oracle mssql boost qt -dirs := common boost qt +all_dirs := libcommon common evolution mysql sqlite pgsql oracle mssql boost qt +dirs := common evolution boost qt dirs += $(db_id) default := $(out_base)/ diff --git a/test.bat b/test.bat index bb7b3a9..8e40afd 100644 --- a/test.bat +++ b/test.bat @@ -38,7 +38,7 @@ goto :eof :start -for %%d in (common %1 boost\common boost\%1 qt\common qt\%1) do ( +for %%d in (common evolution %1 boost\common boost\%1 qt\common qt\%1) do ( call :run_test %%d %1 ) -- cgit v1.1