1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-07 11:17:46 +00:00

force migration run order

This commit is contained in:
NotAdam 2019-06-16 15:33:01 +10:00
parent bb60cf73c4
commit 77611fb038

View file

@ -394,6 +394,7 @@ bool DbManager::modeMigrate()
return false;
}
std::vector< std::string > migrations;
for( auto& entry : fs::directory_iterator( "sql/migrations" ) )
{
auto& path = entry.path();
@ -402,6 +403,15 @@ bool DbManager::modeMigrate()
if( path.extension() != ".sql" )
continue;
migrations.emplace_back( path.string() );
}
std::sort( migrations.begin(), migrations.end() );
for( auto& entry : migrations )
{
auto path = fs::path( entry );
if( std::find( appliedMigrations.begin(), appliedMigrations.end(), path.filename().string() ) == appliedMigrations.end() )
{
Logger::info( "Applying migration: {}", path.filename().string() );
@ -432,6 +442,8 @@ bool DbManager::modeMigrate()
}
}
return true;
}
@ -452,6 +464,12 @@ bool DbManager::modeAddMigration()
auto path = fmt::format( "sql/migrations/{}", filename );
if( fs::exists( path ) )
{
Logger::error( "Migration '{}' already exists.", filename );
return false;
}
std::ofstream mFile( path );
mFile << fmt::format( "-- Migration generated at {}", Util::fmtUtcTime( "%Y/%m/%d %H:%M:%S" ) ) << std::endl;