datenbank nur auf testserver automatisch updaten
This commit is contained in:
@@ -44,34 +44,38 @@ namespace ReallifeGamemode.Server
|
|||||||
[ServerEvent(Event.ResourceStart)]
|
[ServerEvent(Event.ResourceStart)]
|
||||||
public void OnResourceStart()
|
public void OnResourceStart()
|
||||||
{
|
{
|
||||||
using var dbContext = new DatabaseContext(true);
|
|
||||||
|
|
||||||
var pendingMigrations = dbContext.Database.GetPendingMigrations();
|
if (System.Environment.GetEnvironmentVariable("RAGEMP_UPDATE_DATABASE_ON_STARTUP", System.EnvironmentVariableTarget.User) == "true")
|
||||||
|
|
||||||
if (!pendingMigrations.Any())
|
|
||||||
{
|
{
|
||||||
System.Console.WriteLine("No migrations to apply");
|
using var dbContext = new DatabaseContext(true);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
System.Console.WriteLine("Applying {0} migrations", pendingMigrations.Count());
|
|
||||||
foreach (var migration in pendingMigrations)
|
|
||||||
{
|
|
||||||
System.Console.WriteLine("\t{0}", migration);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
var pendingMigrations = dbContext.Database.GetPendingMigrations();
|
||||||
{
|
|
||||||
dbContext.Database.Migrate();
|
|
||||||
}
|
|
||||||
catch (System.Exception e)
|
|
||||||
{
|
|
||||||
System.Console.WriteLine("Error while updating database: {0}", e.ToString());
|
|
||||||
System.Console.ReadLine();
|
|
||||||
System.Environment.Exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Console.WriteLine("Migrations successfull");
|
if (!pendingMigrations.Any())
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("No migrations to apply");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("Applying {0} migrations", pendingMigrations.Count());
|
||||||
|
foreach (var migration in pendingMigrations)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("\t{0}", migration);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dbContext.Database.Migrate();
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
System.Console.WriteLine("Error while updating database: {0}", e.ToString());
|
||||||
|
System.Console.ReadLine();
|
||||||
|
System.Environment.Exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Console.WriteLine("Migrations successfull");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var methods = Assembly.GetExecutingAssembly()
|
var methods = Assembly.GetExecutingAssembly()
|
||||||
|
|||||||
Reference in New Issue
Block a user