added basic support for making migrations
This commit is contained in:
32
src/model.h
32
src/model.h
@@ -86,6 +86,10 @@ public:
|
||||
void set_connector(ModelConnector * connector);
|
||||
ModelConnector * get_connector();
|
||||
|
||||
virtual void get_table_name(PT::WTextStream & stream, bool with_schema_name = true, ModelData * model_data = nullptr, bool clear_stream = true);
|
||||
virtual void get_table_name(std::wstring & str, bool with_schema_name = true, ModelData * model_data = nullptr, bool clear_string = true);
|
||||
virtual void get_table_name(std::string & str, bool with_schema_name = true, ModelData * model_data = nullptr, bool clear_string = true);
|
||||
|
||||
virtual void to_text(PT::TextStream & stream, ModelData * model_data, bool clear_stream = true, bool dump_mode = false);
|
||||
virtual void to_text(PT::TextStream & stream, ModelData & model_data, bool clear_stream = true, bool dump_mode = false);
|
||||
virtual void to_text(PT::TextStream & stream, bool clear_stream = true, bool dump_mode = false);
|
||||
@@ -122,6 +126,9 @@ public:
|
||||
// set object to default values
|
||||
virtual void clear();
|
||||
|
||||
virtual bool do_migration(int & current_table_version);
|
||||
|
||||
|
||||
// IMPROVE ME this will be protected
|
||||
// add set_field_value() functions for each POD type
|
||||
template<typename FieldValue>
|
||||
@@ -210,6 +217,9 @@ protected:
|
||||
|
||||
virtual void map_values_from_query();
|
||||
|
||||
virtual bool db_query(const char * raw_sql);
|
||||
virtual bool db_query(const std::string & raw_sql);
|
||||
virtual bool db_query(const PT::TextStream & raw_sql);
|
||||
|
||||
/////////////////////////////////
|
||||
/*
|
||||
@@ -972,6 +982,28 @@ protected:
|
||||
virtual void log_table_name(bool put_schema_name = true);
|
||||
virtual void log_table_name_with_field(const wchar_t * db_field_name = nullptr, bool put_schema_name = true);
|
||||
|
||||
template<typename ModelObject>
|
||||
bool do_migration(int & current_table_version, int destination_table_version, ModelObject * model_object, bool (ModelObject::*migration_function)())
|
||||
{
|
||||
bool status = true;
|
||||
|
||||
if( current_table_version < destination_table_version )
|
||||
{
|
||||
if( (model_object->*migration_function)() )
|
||||
{
|
||||
current_table_version = destination_table_version;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename ModelClass> friend class Finder;
|
||||
template<typename ModelClass> friend class Cursor;
|
||||
friend class BaseExpression;
|
||||
|
Reference in New Issue
Block a user