Reworked migrations. Now they automatically propagate through the node hierarchy. Also they have parameters.

This commit is contained in:
Relintai 2022-01-13 23:45:38 +01:00
parent 127219fe34
commit 6416ecc5e0
10 changed files with 31 additions and 27 deletions

View File

@ -104,12 +104,34 @@ void WebNode::create_table() {
void WebNode::drop_table() { void WebNode::drop_table() {
} }
void WebNode::migrate() { void WebNode::udpate_table() {
} }
void WebNode::create_default_entries() { void WebNode::create_default_entries() {
} }
void WebNode::migrate(const bool clear, const bool seed_db) {
_migrate(clear, seed_db);
for (int i = 0; i < _children.size(); ++i) {
WebNode *c = Object::cast_to<WebNode>(_children[i]);
c->migrate(clear, seed_db);
}
}
void WebNode::_migrate(const bool clear, const bool seed_db) {
if (clear) {
drop_table();
create_table();
} else {
udpate_table();
}
if (seed_db) {
create_default_entries();
}
}
WebServer *WebNode::get_server() { WebServer *WebNode::get_server() {
// todo this shoult probably be cached // todo this shoult probably be cached
return Object::cast_to<WebServer>(get_tree()); return Object::cast_to<WebServer>(get_tree());

View File

@ -42,9 +42,12 @@ public:
virtual void create_table(); virtual void create_table();
virtual void drop_table(); virtual void drop_table();
virtual void migrate(); virtual void udpate_table();
virtual void create_default_entries(); virtual void create_default_entries();
virtual void migrate(const bool clear, const bool seed);
virtual void _migrate(const bool clear, const bool seed);
WebServer *get_server(); WebServer *get_server();
WebNode *get_root(); WebNode *get_root();

View File

@ -2,10 +2,6 @@
#include "core/database/database.h" #include "core/database/database.h"
void Object::migrate() {
}
Object::Object() { Object::Object() {
db = nullptr; db = nullptr;
} }

View File

@ -66,12 +66,6 @@ public:
static void get_valid_parents_static(Vector<String> *p_parents) {} static void get_valid_parents_static(Vector<String> *p_parents) {}
static void _get_valid_parents_static(Vector<String> *p_parents) {} static void _get_valid_parents_static(Vector<String> *p_parents) {}
//dbconnection
//setting object?
//FileCache? -> set it to the global singleton by default?
virtual void migrate();
Object(); Object();
virtual ~Object(); virtual ~Object();

View File

@ -36,7 +36,7 @@ void MessagePage::handle_request_main(Request *request) {
request->compile_and_send_body(); request->compile_and_send_body();
} }
void MessagePage::migrate() { void MessagePage::_migrate(const bool clear, const bool seed_db) {
Ref<TableBuilder> t = db->get_table_builder(); Ref<TableBuilder> t = db->get_table_builder();
t->drop_table("message_page"); t->drop_table("message_page");

View File

@ -15,7 +15,7 @@ class MessagePage : public WebNode {
public: public:
void handle_request_main(Request *request); void handle_request_main(Request *request);
void migrate(); void _migrate(const bool clear, const bool seed_db);
MessagePage(); MessagePage();
~MessagePage(); ~MessagePage();

View File

@ -808,11 +808,6 @@ void RBACController::drop_table() {
tb->drop_table_if_exists(_rbac_permissions_table)->drop_table_if_exists(_rbac_ranks_table)->run_query(); tb->drop_table_if_exists(_rbac_permissions_table)->drop_table_if_exists(_rbac_ranks_table)->run_query();
//tb->print(); //tb->print();
} }
void RBACController::migrate() {
drop_table();
create_table();
create_default_entries();
}
void RBACController::create_default_entries() { void RBACController::create_default_entries() {
Ref<RBACRank> admin; Ref<RBACRank> admin;

View File

@ -89,7 +89,6 @@ public:
void create_table(); void create_table();
void drop_table(); void drop_table();
void migrate();
void create_default_entries(); void create_default_entries();
static RBACController *get_singleton(); static RBACController *get_singleton();

View File

@ -740,12 +740,8 @@ void UserController::drop_table() {
tb->drop_table_if_exists(_table_name)->run_query(); tb->drop_table_if_exists(_table_name)->run_query();
} }
void UserController::migrate() {
drop_table();
create_table();
}
void UserController::create_test_users() { void UserController::create_default_entries() {
Ref<User> user; Ref<User> user;
user = create_user(); user = create_user();

View File

@ -82,8 +82,7 @@ public:
virtual void create_table(); virtual void create_table();
virtual void drop_table(); virtual void drop_table();
virtual void migrate(); virtual void create_default_entries();
virtual void create_test_users();
static UserController *get_singleton(); static UserController *get_singleton();