mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-08 03:37:45 +00:00
force migration run order
This commit is contained in:
parent
bb60cf73c4
commit
77611fb038
1 changed files with 18 additions and 0 deletions
|
@ -394,6 +394,7 @@ bool DbManager::modeMigrate()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector< std::string > migrations;
|
||||||
for( auto& entry : fs::directory_iterator( "sql/migrations" ) )
|
for( auto& entry : fs::directory_iterator( "sql/migrations" ) )
|
||||||
{
|
{
|
||||||
auto& path = entry.path();
|
auto& path = entry.path();
|
||||||
|
@ -402,6 +403,15 @@ bool DbManager::modeMigrate()
|
||||||
if( path.extension() != ".sql" )
|
if( path.extension() != ".sql" )
|
||||||
continue;
|
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() )
|
if( std::find( appliedMigrations.begin(), appliedMigrations.end(), path.filename().string() ) == appliedMigrations.end() )
|
||||||
{
|
{
|
||||||
Logger::info( "Applying migration: {}", path.filename().string() );
|
Logger::info( "Applying migration: {}", path.filename().string() );
|
||||||
|
@ -432,6 +442,8 @@ bool DbManager::modeMigrate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,6 +464,12 @@ bool DbManager::modeAddMigration()
|
||||||
|
|
||||||
auto path = fmt::format( "sql/migrations/{}", filename );
|
auto path = fmt::format( "sql/migrations/{}", filename );
|
||||||
|
|
||||||
|
if( fs::exists( path ) )
|
||||||
|
{
|
||||||
|
Logger::error( "Migration '{}' already exists.", filename );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::ofstream mFile( path );
|
std::ofstream mFile( path );
|
||||||
|
|
||||||
mFile << fmt::format( "-- Migration generated at {}", Util::fmtUtcTime( "%Y/%m/%d %H:%M:%S" ) ) << std::endl;
|
mFile << fmt::format( "-- Migration generated at {}", Util::fmtUtcTime( "%Y/%m/%d %H:%M:%S" ) ) << std::endl;
|
||||||
|
|
Loading…
Add table
Reference in a new issue