aboutsummaryrefslogtreecommitdiff
path: root/evolution/alter-column/model.hxx
blob: ff38df0a428d65a8a142fd7b31a6352e69b721aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// file      : evolution/alter-column/model.hxx
// copyright : Copyright (c) 2009-2015 Code Synthesis Tools CC
// 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