HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ORMMigrationBuilder.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ORMMigrationBuilder.h
7  *
8  * COMMENTS:
9  *
10  *
11  */
12 
13 #ifndef __UT_ORMMIGRATIONBUILDER_H__
14 #define __UT_ORMMIGRATIONBUILDER_H__
15 
16 #include "UT_API.h"
17 
18 #include "UT_StringHolder.h"
19 #include "UT_Array.h"
20 #include "UT_UniquePtr.h"
21 #include "UT_Map.h"
22 #include "UT_NonCopyable.h"
23 #include "UT_ORMColumn.h"
24 #include "UT_ErrorCode.h"
25 
26 class UT_IORMOperation;
33 class UT_ORMModelMeta;
35 
36 namespace UT
37 {
38 enum class OrmMigError
39 {
40  UT_MIG_OK,
46 };
47 
49 
50 inline UT_ErrorCode
52 {
53  return UT_ErrorCode{static_cast<int>(e), GetOrmMigErrorCategory()};
54 }
55 } // namespace UT
56 
57 namespace std
58 {
59 template <>
60 struct is_error_code_enum<UT::OrmMigError> : true_type
61 {
62 };
63 } // namespace std
64 
66 {
67 public:
69  : myBuilder(builder)
70  {
71  }
74 
75  void createModel(
76  const UT_StringHolder& table_name,
77  const UT_Array<UT_ORMColumn>& columns,
78  UT_ErrorCode& ec);
79  void dropModel(const UT_StringRef& table_name, UT_ErrorCode& ec);
80  void addField(
81  const UT_StringRef& model_name,
82  const UT_ORMColumn& col,
83  UT_ErrorCode& ec);
84  void renameField(
85  const UT_StringRef& model_name,
86  const UT_StringRef& cur_name,
87  const UT_StringHolder& new_name,
88  UT_ErrorCode& ec);
89  void removeField(
90  const UT_StringRef& model_name,
91  const UT_StringRef& name,
92  UT_ErrorCode& ec);
93 
94 private:
95  UT_ORMMigrationBuilder& myBuilder;
96 };
97 
99 {
100 public:
101  explicit UT_ORMMigration(
102  const UT_StringHolder& model_name,
103  const UT_StringHolder& name)
104  : myModelName(model_name), myName(name)
105  {
106  }
107  ~UT_ORMMigration() = default;
109 
110  UT_ORMCreateTableOperation& createModel(const UT_StringHolder& table_name);
111  UT_ORMDropTableOperation& dropModel(const UT_StringHolder& table_name);
112  UT_ORMAddFieldOperation& addField(
113  const UT_StringHolder& model_name,
114  UT_ORMColumn&& col);
115  UT_ORMRenameFieldOperation& renameField(
116  const UT_StringHolder& model_name,
117  const UT_StringHolder& cur_name,
118  const UT_StringHolder& new_name);
119  UT_ORMRemoveFieldOperation& removeField(
120  const UT_StringHolder& model_name,
121  const UT_StringHolder& name);
122 
126 };
127 
129 {
130 public:
131  struct Model
132  {
135  };
136 
137  UT_ORMMigrationBuilder() = default;
140 
141  bool hasModel(const UT_StringRef& name);
142 
143  UT_ORMMigration& addMigration(
144  const UT_StringHolder& table_name,
145  const UT_StringHolder& name);
146 
147  UT_Map<UT_StringHolder, Model>& models() { return myModels; }
148  const UT_Map<UT_StringHolder, Model>& models() const { return myModels; }
149 
150  const UT_Array<UT_ORMMigration>& migrations() const { return myMigrations; }
151 
153  {
154  return myRegisteredMetas;
155  }
157  {
158  myRegisteredMetas.emplace_back(meta);
159  }
160 
161 private:
162  friend class UT_ORMMigration;
164 
165  void createModel_(
166  const UT_StringHolder& table_name,
167  const UT_Array<UT_ORMColumn>& cols,
168  UT_ErrorCode& ec);
169  void dropModel_(const UT_StringRef& table_name, UT_ErrorCode& ec);
170  void addField_(
171  const UT_StringRef& model_name,
172  const UT_ORMColumn& field,
173  UT_ErrorCode& ec);
174  void renameField_(
175  const UT_StringRef& model_name,
176  const UT_StringRef& cur_name,
177  const UT_StringHolder& new_name,
178  UT_ErrorCode& ec);
179  void removeField_(
180  const UT_StringRef& model_name,
181  const UT_StringRef& name,
182  UT_ErrorCode& ec);
183 
184  UT_Array<const UT_ORMModelMeta*> myRegisteredMetas;
186  UT_Array<UT_ORMMigration> myMigrations;
187 };
188 
189 #endif // __UT_ORMMIGRATIONBUILDER_H__
Unsorted map container.
Definition: UT_Map.h:107
const UT_StringHolder myName
const UT_Array< const UT_ORMModelMeta * > & registeredModelMetas() const
void removeField(const UT_StringRef &model_name, const UT_StringRef &name, UT_ErrorCode &ec)
#define UT_API
Definition: UT_API.h:14
void dropModel(const UT_StringRef &table_name, UT_ErrorCode &ec)
std::error_category UT_ErrorCategory
Definition: UT_ErrorCode.h:22
const UT_Array< UT_ORMMigration > & migrations() const
void registerModelMeta(const UT_ORMModelMeta *meta)
UT_Map< UT_StringHolder, Model > & models()
void addField(const UT_StringRef &model_name, const UT_ORMColumn &col, UT_ErrorCode &ec)
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
void renameField(const UT_StringRef &model_name, const UT_StringRef &cur_name, const UT_StringHolder &new_name, UT_ErrorCode &ec)
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_ErrorCode make_error_code(UT::OrmMigError e)
const UT_StringHolder myModelName
UT_ORMMigration(const UT_StringHolder &model_name, const UT_StringHolder &name)
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
UT_API const UT_ErrorCategory & GetOrmMigErrorCategory()
UT_ORMMigrationChangeNotifier(UT_ORMMigrationBuilder &builder)
UT_Array< UT_ORMColumn > myFields
UT_Array< UT_UniquePtr< UT_IORMOperation > > myOperations
const UT_Map< UT_StringHolder, Model > & models() const
UT_NON_COPYABLE(UT_ORMMigrationChangeNotifier)
void createModel(const UT_StringHolder &table_name, const UT_Array< UT_ORMColumn > &columns, UT_ErrorCode &ec)