PERSISTENCE: split database model definitions

master
Martin Gerhardy 2017-09-19 20:27:07 +02:00
parent 8e96b9f344
commit 4402f99bc1
8 changed files with 113 additions and 109 deletions

View File

@ -1,106 +0,0 @@
//
// table descriptions for the databasetool.
//
// the databasetool binary will generate model files for the
// table definitions in this file.
//
// Valid types
// * password
// * string
// * int
// * long
// * timestamp
//
// If no classname is specified, the table name will be used with 'Model' as postfix.
// Example:
// Table user with be UserModel if no other classname was specified
//
// All models will be put into a persistence namespace
//
// table <TABLENAME> {
// classname <STRING> (overrides the automatically determined name)
// namespace <STRING> (c++ namespace where the class is put into)
// field <FIELDNAME> {
// type <FIELDTYPE>
// notnull (optional)
// length <LENGTH> (optional)
// default <DEFAULTVALUE> (optional)
// }
// constraints {
// <FIELDNAME> unique
// <FIELDNAME> primarykey
// <FIELDNAME2> primarykey
// <FIELDNAME> autoincrement
// (<FIELD1>, <FIELD2>) unique
// }
// }
table event {
namespace backend
field id {
type long
}
field type {
type long
notnull
}
field startdate {
type timestamp
notnull
}
field enddate {
type timestamp
notnull
}
constraints {
id primarykey
id autoincrement
}
}
table event_point {
namespace backend
field eventid {
type long
}
field userid {
type long
}
field key {
type string
notnull
}
field points {
type long
notnull
}
constraints {
(userid, eventid, key) unique
}
}
table user {
namespace backend
field id {
type long
}
field email {
type string
notnull
}
field password {
type password
length 128
notnull
}
field registrationdate {
type timestamp
default "NOW()"
notnull
}
constraints {
email unique
id primarykey
id autoincrement
}
}

View File

@ -37,7 +37,7 @@ set(LIB backend)
add_library(${LIB} ${SRCS})
engine_target_link_libraries(TARGET ${LIB} DEPENDENCIES network io core util voxel attrib eventmgr poi cooldown persistence ai stock util)
set_target_properties(${LIB} PROPERTIES FOLDER ${LIB})
generate_db_models(${LIB} ${ROOT_DIR}/data/server/database/tables.tbl DatabaseModels.h)
generate_db_models(${LIB} ${CMAKE_CURRENT_SOURCE_DIR}/tables.tbl BackendModels.h)
gtest_suite_files(tests
tests/DatabaseModelTest.cpp

View File

@ -10,7 +10,8 @@
#include "io/Filesystem.h"
#include "cooldown/CooldownProvider.h"
#include "persistence/ConnectionPool.h"
#include "DatabaseModels.h"
#include "BackendModels.h"
#include "EventMgrModels.h"
#include "backend/entity/User.h"
#include "backend/entity/ai/AIRegistry.h"
#include "backend/entity/ai/AICommon.h"

View File

@ -0,0 +1,25 @@
table user {
namespace backend
field id {
type long
}
field email {
type string
notnull
}
field password {
type password
length 128
notnull
}
field registrationdate {
type timestamp
default "NOW()"
notnull
}
constraints {
email unique
id primarykey
id autoincrement
}
}

View File

@ -3,8 +3,9 @@ set(SRCS
)
set(LIB eventmgr)
add_library(${LIB} ${SRCS})
engine_target_link_libraries(TARGET ${LIB} DEPENDENCIES core commonlua network)
engine_target_link_libraries(TARGET ${LIB} DEPENDENCIES core commonlua network persistence)
set_target_properties(${LIB} PROPERTIES FOLDER ${LIB})
generate_db_models(${LIB} ${CMAKE_CURRENT_SOURCE_DIR}/tables.tbl EventMgrModels.h)
gtest_suite_files(tests
tests/EventMgrTest.cpp

View File

@ -3,6 +3,7 @@
*/
#include "EventMgr.h"
#include "EventMgrModels.h"
namespace eventmgr {

View File

@ -0,0 +1,43 @@
table event {
namespace backend
field id {
type long
}
field type {
type long
notnull
}
field startdate {
type timestamp
notnull
}
field enddate {
type timestamp
notnull
}
constraints {
id primarykey
id autoincrement
}
}
table event_point {
namespace backend
field eventid {
type long
}
field userid {
type long
}
field key {
type string
notnull
}
field points {
type long
notnull
}
constraints {
(userid, eventid, key) unique
}
}

View File

@ -0,0 +1,39 @@
# Table descriptions for the databasetool.
The databasetool binary will generate model files for the
table definitions in this file.
## Valid types
* password
* string
* int
* long
* timestamp
If no classname is specified, the table name will be used with `Model` as postfix.
**Example:**
Table user with be UserModel if no other classname was specified
All models will be put into a persistence namespace.
```
table <TABLENAME> {
classname <STRING> (overrides the automatically determined name)
namespace <STRING> (c++ namespace where the class is put into)
field <FIELDNAME> {
type <FIELDTYPE>
notnull (optional)
length <LENGTH> (optional)
default <DEFAULTVALUE> (optional)
}
constraints {
<FIELDNAME> unique
<FIELDNAME> primarykey
<FIELDNAME2> primarykey
<FIELDNAME> autoincrement
(<FIELD1>, <FIELD2>) unique
}
}
```