diff --git a/core/database.cpp b/core/database.cpp index 6fb3545..785978a 100644 --- a/core/database.cpp +++ b/core/database.cpp @@ -8,6 +8,7 @@ void Database::connect(const std::string &connection_str) { } QueryResult *Database::query(const std::string &query) { + return nullptr; } void Database::query_run(const std::string &query) { } diff --git a/core/table_builder.cpp b/core/table_builder.cpp index 44f5243..b859b07 100644 --- a/core/table_builder.cpp +++ b/core/table_builder.cpp @@ -40,6 +40,10 @@ TableBuilder *TableBuilder::next_row() { return this; } +TableBuilder *TableBuilder::drop_table(const std::string &name) { + +} + void TableBuilder::finalize() { } diff --git a/core/table_builder.h b/core/table_builder.h index 6955e1f..5970816 100644 --- a/core/table_builder.h +++ b/core/table_builder.h @@ -16,6 +16,8 @@ public: virtual TableBuilder *primary_key(); virtual TableBuilder *next_row(); + virtual TableBuilder *drop_table(const std::string &name); + virtual void finalize(); TableBuilder(); diff --git a/database/mysql/mysql_table_builder.cpp b/database/mysql/mysql_table_builder.cpp index 6ff5c08..dcf46d1 100644 --- a/database/mysql/mysql_table_builder.cpp +++ b/database/mysql/mysql_table_builder.cpp @@ -64,6 +64,11 @@ void MysqlTableBuilder::finalize() { result += ");"; } +TableBuilder *MysqlTableBuilder::drop_table(const std::string &name) { + result += "DROP TABLE " + name + ";"; + + return this; +} MysqlTableBuilder::MysqlTableBuilder() { } diff --git a/database/mysql/mysql_table_builder.h b/database/mysql/mysql_table_builder.h index ddd7260..55e7880 100644 --- a/database/mysql/mysql_table_builder.h +++ b/database/mysql/mysql_table_builder.h @@ -18,6 +18,8 @@ public: TableBuilder *primary_key(); TableBuilder *next_row(); + TableBuilder *drop_table(const std::string &name); + void finalize(); MysqlTableBuilder(); diff --git a/modules/message_page/message_page.cpp b/modules/message_page/message_page.cpp index a7d43d7..c96c5cc 100644 --- a/modules/message_page/message_page.cpp +++ b/modules/message_page/message_page.cpp @@ -43,6 +43,13 @@ void MessagePage::index(Request *request) { void MessagePage::migrate() { TableBuilder *t = db->get_table_builder(); + t->drop_table("message_page"); + db->query_run(t->result); + + printf("%s\n", t->result.c_str()); + + t->result.clear(); + t->create_table("message_page")->integer("id")->auto_increment()->primary_key()->next_row()->varchar("text", 30)->finalize(); printf("%s\n", t->result.c_str());