|
1 | 1 | using System.Collections.Generic; |
2 | 2 | using System.IO; |
3 | 3 | using System.Text; |
4 | | -using Datalust.Piggy.Database; |
5 | 4 | using Datalust.Piggy.Filesystem; |
6 | 5 | using Datalust.Piggy.History; |
7 | 6 | using Datalust.Piggy.Status; |
|
11 | 10 |
|
12 | 11 | namespace Datalust.Piggy.Update |
13 | 12 | { |
14 | | - static class UpdateSession |
| 13 | + /// <summary> |
| 14 | + /// Applies updates to a target database. |
| 15 | + /// </summary> |
| 16 | + public static class UpdateSession |
15 | 17 | { |
16 | | - public static void ApplyChangeScripts(string host, string database, string username, string password, |
17 | | - bool createIfMissing, string scriptRoot, IReadOnlyDictionary<string, string> variables) |
| 18 | + /// <summary> |
| 19 | + /// Apply change scripts from a folder hierarchy. |
| 20 | + /// </summary> |
| 21 | + /// <param name="connection">The database connection to use.</param> |
| 22 | + /// <param name="scriptRoot">A root filesystem folder under which change scripts are stored.</param> |
| 23 | + /// <param name="variables">A set of variables to replace within change scripts.</param> |
| 24 | + public static void ApplyChangeScripts(NpgsqlConnection connection, string scriptRoot, IReadOnlyDictionary<string, string> variables) |
18 | 25 | { |
19 | | - using (var connection = DatabaseConnector.Connect(host, database, username, password, createIfMissing)) |
20 | | - { |
21 | | - var scripts = DatabaseStatus.GetPendingScripts(connection, scriptRoot); |
22 | | - |
23 | | - Log.Information("Found {Count} new script files to apply", scripts.Length); |
| 26 | + var scripts = DatabaseStatus.GetPendingScripts(connection, scriptRoot); |
24 | 27 |
|
25 | | - if (scripts.Length != 0) |
26 | | - { |
27 | | - Log.Information("Ensuring the change log table exists"); |
28 | | - using (var command = new NpgsqlCommand(AppliedChangeScriptLog.ChangesTableCreateScript, connection)) |
29 | | - command.ExecuteNonQuery(); |
30 | | - } |
| 28 | + Log.Information("Found {Count} new script files to apply", scripts.Length); |
31 | 29 |
|
32 | | - foreach (var script in scripts) |
33 | | - { |
34 | | - Log.Information("Applying {FullPath} as {ScriptFile}", script.FullPath, script.RelativeName); |
35 | | - ApplyChangeScript(connection, script, variables); |
36 | | - } |
| 30 | + if (scripts.Length != 0) |
| 31 | + { |
| 32 | + Log.Information("Ensuring the change log table exists"); |
| 33 | + using (var command = new NpgsqlCommand(AppliedChangeScriptLog.ChangesTableCreateScript, connection)) |
| 34 | + command.ExecuteNonQuery(); |
| 35 | + } |
37 | 36 |
|
38 | | - Log.Information("Done"); |
| 37 | + foreach (var script in scripts) |
| 38 | + { |
| 39 | + Log.Information("Applying {FullPath} as {ScriptFile}", script.FullPath, script.RelativeName); |
| 40 | + ApplyChangeScript(connection, script, variables); |
39 | 41 | } |
| 42 | + |
| 43 | + Log.Information("Done"); |
40 | 44 | } |
41 | 45 |
|
42 | 46 | static void ApplyChangeScript(NpgsqlConnection connection, ChangeScriptFile script, IReadOnlyDictionary<string, string> variables) |
|
0 commit comments