aboutsummaryrefslogtreecommitdiff
path: root/evolution/combined/model.hxx
blob: 2aede904c4953da5db5878bdeaf6f1e2dcc670cb (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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