57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using System.Reflection;
|
|
using DbUp;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace EnotaryoPH.DbMigration
|
|
{
|
|
internal class Program
|
|
{
|
|
private static int Main(string[] args)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
|
|
var config = new ConfigurationBuilder()
|
|
.AddJsonFile("appsettings.json")
|
|
.Build();
|
|
var connectionString =
|
|
args.FirstOrDefault()
|
|
?? config.GetConnectionString("DbUpConnection");
|
|
|
|
var upgrader =
|
|
DeployChanges.To
|
|
.PostgresqlDatabase(connectionString)
|
|
.WithVariablesDisabled()
|
|
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
|
|
.LogToConsole()
|
|
.Build();
|
|
|
|
if (upgrader.TryConnect(out var err))
|
|
{
|
|
var result = upgrader.PerformUpgrade();
|
|
|
|
if (!result.Successful)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine(result.Error);
|
|
Console.ResetColor();
|
|
#if DEBUG
|
|
Console.ReadLine();
|
|
#endif
|
|
return -1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine($"Cannot Connect: '{err}'");
|
|
Console.ResetColor();
|
|
return -1;
|
|
}
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
Console.WriteLine("Success!");
|
|
Console.ResetColor();
|
|
return 0;
|
|
}
|
|
}
|
|
} |