mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-24 05:37:45 +00:00
Allow force mode in dbm
This commit is contained in:
parent
4a920de104
commit
e69d112d5f
4 changed files with 26 additions and 14 deletions
|
@ -1,3 +1,3 @@
|
|||
#!/bin/bash
|
||||
bin/sapphire_dbm --mode initialize --user root --database sapphire --sfile bin/sql/schema/schema.sql --ifile bin/sql/schema/inserts.sql
|
||||
bin/sapphire_dbm --mode liquidate --user root --database sapphire
|
||||
bin/sapphire_dbm --mode liquidate --user root --database sapphire --force
|
||||
|
|
|
@ -12,7 +12,8 @@ DbManager::DbManager( const std::string& host, const std::string& database, cons
|
|||
m_password( pw ),
|
||||
m_port( port ),
|
||||
m_sFile( "sql/schema/schema.sql" ),
|
||||
m_iFile( "sql/schema/inserts.sql" )
|
||||
m_iFile( "sql/schema/inserts.sql" ),
|
||||
m_force( false )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -36,6 +37,11 @@ bool DbManager::execute( const std::string& sql )
|
|||
}
|
||||
}
|
||||
|
||||
void DbManager::setForceMode( bool mode )
|
||||
{
|
||||
m_force = mode;
|
||||
}
|
||||
|
||||
bool DbManager::connect()
|
||||
{
|
||||
std::shared_ptr< Mysql::MySqlBase > base( new Mysql::MySqlBase() );
|
||||
|
@ -250,14 +256,14 @@ bool DbManager::modeLiquidate()
|
|||
return false;
|
||||
|
||||
char type = '\0';
|
||||
|
||||
while( promptForChar( "This action will drop all tables in the database. Are you sure? [y/n]", type ) )
|
||||
{
|
||||
if( type == 'y' )
|
||||
break;
|
||||
if( type == 'n' )
|
||||
return true;
|
||||
}
|
||||
if( !m_force )
|
||||
while( promptForChar( "This action will drop all tables in the database. Are you sure? [y/n]", type ) )
|
||||
{
|
||||
if( type == 'y' )
|
||||
break;
|
||||
if( type == 'n' )
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string query = "SELECT TABLE_NAME "
|
||||
"FROM information_schema.tables "
|
||||
|
|
|
@ -47,6 +47,8 @@ class DbManager
|
|||
void setSchemaFile( const std::string& schemaFile );
|
||||
void setInsertFile( const std::string& insertFile );
|
||||
|
||||
void setForceMode( bool );
|
||||
|
||||
private:
|
||||
std::string m_host;
|
||||
std::string m_database;
|
||||
|
@ -58,6 +60,7 @@ class DbManager
|
|||
Mode m_mode;
|
||||
std::string m_iFile;
|
||||
std::string m_sFile;
|
||||
bool m_force;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -90,8 +90,7 @@ void printUsage()
|
|||
g_log.info( "\t --port <mysqlPort> ( default 3306 )" );
|
||||
g_log.info( "\t --database <mysqlDatabase>" );
|
||||
g_log.info( "\t --sfile <path/to/schemafile> ( default sql/schema/schema.sql )" );
|
||||
g_log.info( "\t --ifile <path/to/insertsfile> ( default sql/schema/inserts.sql )" );
|
||||
|
||||
g_log.info( "\t --force ( skips user input / auto Yes )" );
|
||||
}
|
||||
|
||||
int main( int32_t argc, char* argv[] )
|
||||
|
@ -110,6 +109,8 @@ int main( int32_t argc, char* argv[] )
|
|||
std::string sFile;
|
||||
std::string iFile;
|
||||
|
||||
bool force = false;
|
||||
|
||||
std::vector< std::string > args( argv + 1, argv + argc );
|
||||
for( uint32_t i = 0; i + 1 < args.size(); i += 2 )
|
||||
{
|
||||
|
@ -132,7 +133,8 @@ int main( int32_t argc, char* argv[] )
|
|||
sFile = val;
|
||||
else if( arg == "ifile" )
|
||||
iFile = val;
|
||||
|
||||
else if( arg == "force" )
|
||||
force = true;
|
||||
}
|
||||
|
||||
if( host.empty() )
|
||||
|
@ -150,8 +152,9 @@ int main( int32_t argc, char* argv[] )
|
|||
{
|
||||
dbm.setInsertFile( iFile );
|
||||
dbm.setSchemaFile( sFile );
|
||||
|
||||
}
|
||||
if( force )
|
||||
dbm.setForceMode( true );
|
||||
//initialize|check|update|clearchars|liquidate
|
||||
if( mode.find( "initialize" ) != std::string::npos )
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue