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();
|
||||
|
Reference in New Issue
Block a user