mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-02 08:57:44 +00:00
Ongoing implementation of migration utility
This commit is contained in:
parent
825d81ab53
commit
d68377f174
4 changed files with 84 additions and 10 deletions
|
@ -37,7 +37,7 @@ add_subdirectory( "deps/mysqlConnector" )
|
|||
add_subdirectory( "src/common" )
|
||||
|
||||
add_subdirectory( "src/servers" )
|
||||
#add_subdirectory( "src/dbm" )
|
||||
add_subdirectory( "src/dbm" )
|
||||
|
||||
add_subdirectory( "src/tools/exd_common_gen" )
|
||||
add_subdirectory( "src/tools/exd_struct_gen" )
|
||||
|
|
|
@ -14,6 +14,21 @@ DbManager::~DbManager()
|
|||
|
||||
}
|
||||
|
||||
bool DbManager::execute( const std::string& sql )
|
||||
{
|
||||
try
|
||||
{
|
||||
auto stmt = m_pConnection->createStatement();
|
||||
bool result = stmt->execute( sql );
|
||||
return result;
|
||||
}
|
||||
catch( std::runtime_error& e )
|
||||
{
|
||||
m_lastError = e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DbManager::connect()
|
||||
{
|
||||
std::shared_ptr< Mysql::MySqlBase > base( new Mysql::MySqlBase() );
|
||||
|
@ -67,3 +82,55 @@ Mode DbManager::getMode() const
|
|||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
bool DbManager::performAction()
|
||||
{
|
||||
bool result = false;
|
||||
execute( " SET autocommit = 0 " );
|
||||
m_pConnection->beginTransaction();
|
||||
|
||||
switch( m_mode )
|
||||
{
|
||||
case Mode::INIT:
|
||||
result = modeInit();
|
||||
break;
|
||||
case Mode::LIQUIDATE:
|
||||
break;
|
||||
case Mode::UPDATE:
|
||||
break;
|
||||
case Mode::CHECK:
|
||||
break;
|
||||
case Mode::CLEAN_CHARS:
|
||||
break;
|
||||
}
|
||||
if( !result )
|
||||
m_pConnection->rollbackTransaction();
|
||||
else
|
||||
m_pConnection->commitTransaction();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DbManager::modeInit()
|
||||
{
|
||||
|
||||
bool result = false;
|
||||
|
||||
if( selectSchema() )
|
||||
{
|
||||
m_lastError = "Database already existing, use <liquidate> mode first to remove it.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !execute( "CREATE DATABASE " + m_database ) )
|
||||
return false;
|
||||
|
||||
if( !execute( "CREATE TABLE `dbversion` (\n"
|
||||
" `major` int(11) NOT NULL,\n"
|
||||
" `minor` int(11) NOT NULL\n"
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=latin1;" ) )
|
||||
return false;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,12 @@ class DbManager
|
|||
bool connect();
|
||||
bool selectSchema();
|
||||
|
||||
bool execute( const std::string& sql );
|
||||
|
||||
bool performAction();
|
||||
|
||||
bool modeInit();
|
||||
|
||||
virtual ~DbManager();
|
||||
|
||||
const std::string& getLastError();
|
||||
|
|
|
@ -43,13 +43,8 @@ std::vector< std::string > getAllFilesInDir( const std::string& dirPath,
|
|||
( std::find( dirSkipList.begin(), dirSkipList.end(), iter->path().filename() ) != dirSkipList.end() ) )
|
||||
{
|
||||
// Skip the iteration of current directory pointed by iterator
|
||||
#ifdef USING_BOOST
|
||||
// Boost Fileystsem API to skip current directory iteration
|
||||
iter.no_push();
|
||||
#else
|
||||
// c++17 Filesystem API to skip current directory iteration
|
||||
iter.disable_recursion_pending();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -57,7 +52,7 @@ std::vector< std::string > getAllFilesInDir( const std::string& dirPath,
|
|||
listOfFiles.push_back( iter->path().string() );
|
||||
}
|
||||
|
||||
std::error_code ec;
|
||||
std::error_code ec;
|
||||
// Increment the iterator to point to next entry in recursive iteration
|
||||
iter.increment( ec );
|
||||
if( ec )
|
||||
|
@ -176,13 +171,19 @@ int main( int32_t argc, char* argv[] )
|
|||
return 0;
|
||||
}
|
||||
|
||||
if( !dbm.selectSchema() )
|
||||
if( !dbm.performAction() )
|
||||
{
|
||||
g_log.fatal( "Could not set schema!" );
|
||||
g_log.fatal( "Could not perform action!" );
|
||||
g_log.fatal( dbm.getLastError() );
|
||||
return 0;
|
||||
}
|
||||
|
||||
//if( !dbm.selectSchema() )
|
||||
//{
|
||||
// g_log.fatal( "Could not set schema!" );
|
||||
// g_log.fatal( dbm.getLastError() );
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue