aboutsummaryrefslogtreecommitdiff
path: root/evolution/combined/model.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-08 15:41:25 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-10 18:46:47 +0200
commitf57a6e7a73e425c2301e62b49c728c12ee801bcc (patch)
tree8d362157ddd60c7f9dca45ec9d294518f975cd81 /evolution/combined/model.hxx
parentacd66db1ce8aa960b34710857ce990dd048cd3ae (diff)
Add combined schema evolution test
Diffstat (limited to 'evolution/combined/model.hxx')
-rw-r--r--evolution/combined/model.hxx156
1 files changed, 156 insertions, 0 deletions
diff --git a/evolution/combined/model.hxx b/evolution/combined/model.hxx
new file mode 100644
index 0000000..2aede90
--- /dev/null
+++ b/evolution/combined/model.hxx
@@ -0,0 +1,156 @@
+// file : evolution/combined/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 <string>
+#include <vector>
+
+#include <odb/core.hxx>
+#include <odb/nullable.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)
+{
+ #pragma db object
+ struct object1
+ {
+ object1 (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+ };
+
+ #pragma db object
+ struct object
+ {
+ #pragma db id
+ std::string id_;
+
+ //
+ // Pre pass 1.
+ //
+
+ // Drop unique index.
+ //
+#if MODEL_VERSION == 2
+ #pragma db unique
+#endif
+ unsigned long dui;
+
+ // Alter table drop foreign key.
+ //
+#if MODEL_VERSION == 2
+ object1* dfk;
+#else
+ #pragma db null
+ unsigned long dfk;
+#endif
+
+ // Add table.
+ //
+#if MODEL_VERSION == 3
+ std::vector<std::string> at;
+#endif
+
+ // Add column.
+ //
+#if MODEL_VERSION == 3
+ #pragma db default(999)
+ unsigned long ac1;
+
+ odb::nullable<unsigned long> ac2;
+
+ #pragma db not_null // Initially added as NULL, converted to NOT NULL.
+ odb::nullable<unsigned long> ac3;
+#endif
+
+ // Alter column NULL.
+ //
+#if MODEL_VERSION == 2
+ unsigned long acn;
+#else
+ odb::nullable<unsigned long> acn;
+#endif
+
+ //
+ // Pre pass 2.
+ //
+
+ // Add non-unique indexes.
+ //
+#if MODEL_VERSION == 3
+ #pragma db index
+#endif
+ unsigned long anui;
+
+ //
+ // Post pass 1.
+ //
+
+ // Drop non-unique indexes.
+ //
+#if MODEL_VERSION == 2
+ #pragma db index
+#endif
+ unsigned long dnui;
+
+ //
+ // Post pass 2.
+ //
+
+ // Drop table.
+ //
+#if MODEL_VERSION == 2
+ std::vector<unsigned long> dt;
+#endif
+
+ // Drop column.
+ //
+#if MODEL_VERSION == 2
+ unsigned long dc;
+#endif
+
+ // Alter column NOT NULL.
+ //
+#if MODEL_VERSION == 3
+ #pragma db not_null
+#endif
+ odb::nullable<unsigned long> acnn;
+
+ // Alter table add foreign key.
+ //
+#if MODEL_VERSION == 2
+ #pragma db null
+ unsigned long afk;
+#else
+ object1* afk;
+#endif
+
+ // Add unique index.
+ //
+#if MODEL_VERSION == 3
+ #pragma db unique
+#endif
+ unsigned long aui;
+
+ public:
+#if MODEL_VERSION == 2
+ object (std::string id = ""): id_ (id), dfk (0) {}
+ ~object () {delete dfk;}
+#else
+ object (std::string id = ""): id_ (id), afk (0) {}
+ ~object () {delete afk;}
+#endif
+ };
+}
+
+#undef MODEL_NAMESPACE
+#undef MODEL_NAMESPACE_IMPL