-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrateScriptCommand.cs
More file actions
53 lines (45 loc) · 1.73 KB
/
MigrateScriptCommand.cs
File metadata and controls
53 lines (45 loc) · 1.73 KB
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
using DbUp.ScriptProviders;
namespace Migratonator;
internal class MigrateScriptCommand : BaseCommand
{
// TODO: provide ability to apply a single script
// TODO: make well-known directories configurable
// the paths to scripts, relative to the base script path
private static readonly string[] ScriptPaths =
{
"Assemblies",
"Functions",
"Procedures",
"Stored Procedures", // deprecate this path (spaces in paths can be problematic)
"Views",
"Jobs"
};
public MigrateScriptCommand(Options configuration, bool dryRun) :
base(configuration)
{
DryRun = dryRun;
}
private bool DryRun { get; }
public override void Perform()
{
var builder = CreateUnJournaledMigrator()
// disable a single transaction since scripts can contain multiple GO statements
// which implicitly commit the transaction, and cases such as ALTER DATABASE statements
// don't support nested transactions
// if specific transactions are required, they will need to be included in the scripts
.WithoutTransaction();
// only add paths which exist
foreach (var path in ScriptPaths)
{
var qualifiedPath = Path.Combine(Options.ScriptsPath, path);
if (Directory.Exists(qualifiedPath))
builder.WithScripts(new FileSystemScriptProvider(
qualifiedPath,
new FileSystemScriptOptions { IncludeSubDirectories = true }
));
else if (Options.Verbose)
Console.WriteLine($"WARNING: {path} path not found. Ignoring.");
}
Apply(builder.Build(), DryRun, Options.Confirm);
}
}