added support for Model migrations
now we have a table core.migration and each model (User, Group, Item, ItemContent and a new Migration) have its own row in the table with a version number added to config: db_make_migration_if_needed and db_stop_if_migration_fails (need description yet)
This commit is contained in:
@@ -50,7 +50,7 @@
|
||||
#include "functions/functions.h"
|
||||
#include "utf8/utf8.h"
|
||||
#include "convert/convert.h"
|
||||
|
||||
#include "models/migration.h"
|
||||
|
||||
|
||||
namespace Winix
|
||||
@@ -272,6 +272,52 @@ return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::DoDatabaseMigration()
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
Migration migration;
|
||||
User user;
|
||||
ItemContent item_content;
|
||||
Item item;
|
||||
Group group;
|
||||
|
||||
ok = ok && Migration::do_migration(&model_connector, migration);
|
||||
ok = ok && Migration::do_migration(&model_connector, user);
|
||||
|
||||
/*
|
||||
* do migration of ItemContent before Item
|
||||
* Item::do_migration_to_3() requires that ItemContent should have new columns
|
||||
*
|
||||
*/
|
||||
ok = ok && Migration::do_migration(&model_connector, item_content);
|
||||
ok = ok && Migration::do_migration(&model_connector, item);
|
||||
ok = ok && Migration::do_migration(&model_connector, group);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool App::TryToMakeDatabaseMigration()
|
||||
{
|
||||
if( config.db_make_migration_if_needed )
|
||||
{
|
||||
if( !DoDatabaseMigration() )
|
||||
{
|
||||
if( config.db_stop_if_migration_fails )
|
||||
{
|
||||
log << log1 << "App: database migration failed, stopping winix" << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool App::Init()
|
||||
{
|
||||
postgresql_connector.set_conn_param(config.db_database, config.db_user, config.db_pass);
|
||||
@@ -283,20 +329,11 @@ bool App::Init()
|
||||
model_connector.set_db_connector(postgresql_connector);
|
||||
model_connector.set_logger(log);
|
||||
|
||||
// temporary
|
||||
if( config.space.to_bool(L"do_migration_to_winix_fullmorm", false) )
|
||||
{
|
||||
Item item_temp;
|
||||
item_temp.set_connector(model_connector);
|
||||
item_temp.do_migration(&model_connector, log);
|
||||
|
||||
log << log1 << "Migrations complete, now remove do_migration_to_winix_fullmorm from the config" << logend;
|
||||
std::exit(0);
|
||||
}
|
||||
if( !TryToMakeDatabaseMigration() )
|
||||
return false;
|
||||
|
||||
db_conn.SetConnParam(config.db_database, config.db_user, config.db_pass);
|
||||
db_conn.WaitForConnection();
|
||||
db.PostgreSQLsmallerThan10(config.db_postgresql_smaller_than_10);
|
||||
db.LogQueries(config.log_db_query);
|
||||
|
||||
cur.request->Clear();
|
||||
|
||||
@@ -266,6 +266,10 @@ private:
|
||||
|
||||
void CreateStaticTree();
|
||||
|
||||
bool DoDatabaseMigration();
|
||||
bool TryToMakeDatabaseMigration();
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// !! move to the session manager?
|
||||
time_t last_sessions_save;
|
||||
|
||||
@@ -194,7 +194,8 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||
db_database = Text(L"db_database");
|
||||
db_user = Text(L"db_user");
|
||||
db_pass = Text(L"db_pass");
|
||||
db_postgresql_smaller_than_10 = Bool(L"db_postgresql_smaller_than_10", false);
|
||||
db_make_migration_if_needed = Bool(L"db_make_migration_if_needed", true);
|
||||
db_stop_if_migration_fails = Bool(L"db_stop_if_migration_fails", true);
|
||||
|
||||
item_url_empty = Text(L"item_url_empty");
|
||||
|
||||
|
||||
@@ -198,10 +198,11 @@ public:
|
||||
std::wstring db_user;
|
||||
std::wstring db_pass;
|
||||
|
||||
// is the PostgreSQL later than 10
|
||||
// default false
|
||||
// if true then we are not using ROW() statements in sql query
|
||||
bool db_postgresql_smaller_than_10;
|
||||
// make database migration if needed
|
||||
//
|
||||
bool db_make_migration_if_needed;
|
||||
|
||||
bool db_stop_if_migration_fails;
|
||||
|
||||
// the name of the cookie which has the session identifier
|
||||
std::wstring http_session_id_name;
|
||||
|
||||
Reference in New Issue
Block a user