summaryrefslogtreecommitdiff
path: root/odb-tests/evolution/drop-column
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/evolution/drop-column')
-rw-r--r--odb-tests/evolution/drop-column/buildfile64
-rw-r--r--odb-tests/evolution/drop-column/driver.cxx17
-rw-r--r--odb-tests/evolution/drop-column/testscript54
3 files changed, 129 insertions, 6 deletions
diff --git a/odb-tests/evolution/drop-column/buildfile b/odb-tests/evolution/drop-column/buildfile
new file mode 100644
index 0000000..c508f76
--- /dev/null
+++ b/odb-tests/evolution/drop-column/buildfile
@@ -0,0 +1,64 @@
+# file : evolution/drop-column/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+ assert (!$multi) "multi-database mode is not supported by this test"
+
+db = ($databases[0])
+
+import libodb = libodb%lib{odb}
+
+import libs = libodb-$db%lib{odb-$db}
+import libs += lib{common}
+
+hdrs = test1 test2 test3
+
+exe{driver}: {hxx cxx}{* -*-odb} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $libodb
+
+for h: $hdrs
+ exe{driver}: {hxx ixx cxx}{$h-odb}: hxx{$h} libue{test-meta} hxx{model}
+
+# Make sure testN.hxx are compiled serially since they share the changelog.
+#
+# @@ TODO: make order-only when supported by build2.
+#
+{hxx ixx cxx}{test3-odb}: {hxx ixx cxx}{test2-odb}: {hxx ixx cxx}{test1-odb}
+
+exe{driver}: libue{test-meta} $libs
+
+# Specify the ODB custom options to be used by the odb_compile ad hoc rule
+# (see build/root.build for details).
+#
+odb_options = --table-prefix evo_drop_c_ \
+ --schema-version-table evo_drop_c_sv \
+ --generate-schema \
+ --generate-query \
+ --at-once \
+ --changelog $out_base/model.xml \
+ --sqlite-override-null
+
+<{hxx ixx cxx}{test1-odb}>: odb_options += --init-changelog
+<{hxx ixx cxx}{test2-odb}>: odb_options += --omit-create --suppress-migration
+
+<{hxx ixx cxx}{test3-odb}>:
+{
+ odb_options += --omit-create
+ schema_versions = 002 003
+}
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../alias{database-client}: include = adhoc
+
+testscript@./:
+{
+ db = $db
+ schemas = $hdrs
+}
diff --git a/odb-tests/evolution/drop-column/driver.cxx b/odb-tests/evolution/drop-column/driver.cxx
index 7f0c253..6f2a735 100644
--- a/odb-tests/evolution/drop-column/driver.cxx
+++ b/odb-tests/evolution/drop-column/driver.cxx
@@ -4,21 +4,23 @@
// Test dropping a column.
//
-#include <memory> // std::auto_ptr
-#include <cassert>
+#include <memory> // std::unique_ptr
#include <iostream>
#include <odb/database.hxx>
#include <odb/transaction.hxx>
#include <odb/schema-catalog.hxx>
-#include <common/common.hxx>
+#include <libcommon/common.hxx>
#include "test2.hxx"
#include "test3.hxx"
#include "test2-odb.hxx"
#include "test3-odb.hxx"
+#undef NDEBUG
+#include <cassert>
+
using namespace std;
using namespace odb::core;
@@ -27,7 +29,10 @@ main (int argc, char* argv[])
{
try
{
- auto_ptr<database> db (create_database (argc, argv, false));
+ unique_ptr<database> db (create_database (argc, argv, false));
+
+ db->schema_version_table ("evo_drop_c_sv");
+
bool embedded (schema_catalog::exists (*db));
// 1 - base version
@@ -79,7 +84,7 @@ main (int argc, char* argv[])
//
{
transaction t (db->begin ());
- auto_ptr<object> p (db->load<object> (1));
+ unique_ptr<object> p (db->load<object> (1));
assert (p->str == "abc");
assert (p->num == 123);
@@ -104,7 +109,7 @@ main (int argc, char* argv[])
//
{
transaction t (db->begin ());
- auto_ptr<object> p (db->load<object> (1));
+ unique_ptr<object> p (db->load<object> (1));
assert (p->str == "" && p->ptr == 0);
db->erase<object1> (value (1, 2)); // SQLite logical delete test.
t.commit ();
diff --git a/odb-tests/evolution/drop-column/testscript b/odb-tests/evolution/drop-column/testscript
new file mode 100644
index 0000000..abb81a8
--- /dev/null
+++ b/odb-tests/evolution/drop-column/testscript
@@ -0,0 +1,54 @@
+# file : evolution/drop-column/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../database-options.testscript
+.include ../../$db-schema.testscript
+
+test.arguments += $($(db)_options)
+
+: basics
+:
+if! $sqlite
+{
+ ss =; # Schema modification base file names.
+
+ # Drop everything.
+ #
+ for s: $schemas
+ ss =+ $s
+ end;
+
+ # Add base schema.
+ #
+ ss += test3-002-pre test3-002-post;
+
+ # Add migration.
+ #
+ ss += test3-003-pre test3-003-post;
+
+ # Run tests.
+ #
+ for s: $ss
+ f = $out_base/"$s".sql
+
+ if $mysql
+ cat $f | $create_schema_cmd
+ elif $pgsql
+ $create_schema_cmd -f $f
+ end
+
+ if ($s == 'test3-002-post')
+ $* 1
+ elif ($s == 'test3-003-pre')
+ $* 2
+ elif ($s == 'test3-003-post')
+ $* 3
+ end
+ end
+}
+else
+{
+ $* 1 &odb-test.db;
+ $* 2;
+ $* 3
+}