forked from kgrzybek/modular-monolith-with-ddd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
68 lines (51 loc) · 1.83 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using DbUp;
using DbUp.ScriptProviders;
using Serilog;
using Serilog.Formatting.Compact;
namespace DatabaseMigrator
{
public class Program
{
public static int Main(string[] args)
{
var logsPath = "logs\\migration-logs";
ILogger logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File(new CompactJsonFormatter(), logsPath)
.CreateLogger();
logger.Information("Logger configured. Starting migration...");
if (args.Length != 2)
{
logger.Error("Invalid arguments. Execution: DatabaseMigrator [connectionString] [pathToScripts].");
logger.Information("Migration stopped");
return -1;
}
var connectionString = args[0];
var scriptsPath = args[1];
if (!Directory.Exists(scriptsPath))
{
logger.Information($"Directory {scriptsPath} does not exist");
return -1;
}
var serilogUpgradeLog = new SerilogUpgradeLog(logger);
var upgrader =
DeployChanges.To
.SqlDatabase(connectionString)
.WithScriptsFromFileSystem(scriptsPath, new FileSystemScriptOptions
{
IncludeSubDirectories = true
})
.LogTo(serilogUpgradeLog)
.JournalToSqlTable("app", "MigrationsJournal")
.Build();
var result = upgrader.PerformUpgrade();
if (!result.Successful)
{
logger.Information("Migration failed");
return -1;
}
logger.Information("Migration successful");
return 0;
}
}
}