diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 20:32:06 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2024-01-25 20:32:06 +0300 |
commit | 0d49ea1fe08cf1eab41a00149393a291c65a59d7 (patch) | |
tree | 0391eb09309ca95282e200516937e64d89f3e1bb /odb-tests/evolution/alter-column/model.hxx | |
parent | fc3fb39c90ab7fe5fccbe3f3bc0eb2645157bb96 (diff) |
Turn odb-tests repository into package for muti-package repositoryodb-tests
Diffstat (limited to 'odb-tests/evolution/alter-column/model.hxx')
-rw-r--r-- | odb-tests/evolution/alter-column/model.hxx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/odb-tests/evolution/alter-column/model.hxx b/odb-tests/evolution/alter-column/model.hxx new file mode 100644 index 0000000..fc6661c --- /dev/null +++ b/odb-tests/evolution/alter-column/model.hxx @@ -0,0 +1,56 @@ +// file : evolution/alter-column/model.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef MODEL_VERSION +# error model.hxx included directly +#endif + +#include <string> + +#include <odb/core.hxx> +#include <odb/nullable.hxx> + +#include <common/config.hxx> // DATABASE_XXX + +#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_; + + // SQLite doesn't support altering of columns. + // +#ifndef DATABASE_SQLITE +#if MODEL_VERSION == 2 + odb::nullable<std::string> str; + + unsigned long num; +#else + // Use nullable to be able to access during migration. + // + #pragma db not_null + odb::nullable<std::string> str; + + odb::nullable<unsigned long> num; + + // Test adding NOT NULL column. It should be added NULL in pre + // and then converted to NOT NULL in post. + // + #pragma db not_null + odb::nullable<unsigned long> num1; +#endif +#endif + }; +} + +#undef MODEL_NAMESPACE +#undef MODEL_NAMESPACE_IMPL |