Skip to content

Commit a453183

Browse files
committed
Merge pull request DbUp#37 from JakeGinnivan/ReleasePrep
Release prep
2 parents 435a21e + 12fef4a commit a453183

File tree

10 files changed

+38
-28
lines changed

10 files changed

+38
-28
lines changed

lib/nuget/NuGet.exe

1.25 MB
Binary file not shown.

src/DbUp.SqlCe/SqlCeExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static UpgradeEngineBuilder SqlCeDatabase(IConnectionManager connectionM
4646
{
4747
var builder = new UpgradeEngineBuilder();
4848
builder.Configure(c => c.ConnectionManager = connectionManager);
49-
builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, null, () => c.VariablesEnabled, () => c.IsScriptOutputLogged, c.ScriptPreprocessors));
49+
builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, null, () => c.VariablesEnabled, c.ScriptPreprocessors));
5050
builder.Configure(c => c.Journal = new SqlTableJournal(()=>connectionManager, ()=>c.Log, null, "SchemaVersions"));
5151
builder.WithPreprocessor(new SqlCePreprocessor());
5252
return builder;

src/DbUp.Sqlite/SqliteExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static UpgradeEngineBuilder SQLiteDatabase(this SupportedDatabases suppor
2929
builder.Configure(c => c.ConnectionManager = new SQLiteConnectionManager(connectionString));
3030
builder.Configure(c => c.Journal = new SQLiteTableJournal(() => c.ConnectionManager, () => c.Log, "SchemaVersions"));
3131
builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, null,
32-
() => c.VariablesEnabled, () => c.IsScriptOutputLogged, c.ScriptPreprocessors));
32+
() => c.VariablesEnabled, c.ScriptPreprocessors));
3333
builder.WithPreprocessor(new SQLitePreprocessor());
3434
return builder;
3535
}
@@ -48,7 +48,7 @@ public static UpgradeEngineBuilder SQLiteDatabase(this SupportedDatabases suppor
4848
builder.Configure(c => c.ConnectionManager = new SQLiteConnectionManager(sharedConnection));
4949
builder.Configure(c => c.Journal = new SQLiteTableJournal(() => c.ConnectionManager, () => c.Log, "SchemaVersions"));
5050
builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, null,
51-
() => c.VariablesEnabled, () => c.IsScriptOutputLogged, c.ScriptPreprocessors));
51+
() => c.VariablesEnabled, c.ScriptPreprocessors));
5252
builder.WithPreprocessor(new SQLitePreprocessor());
5353
return builder;
5454
}

src/DbUp.Tests/Engine/UpgradeEngineTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override UpgradeEngine Given()
3030
dbCommand = Substitute.For<IDbCommand>();
3131
dbConnection.CreateCommand().Returns(dbCommand);
3232
var connectionManager = new TestConnectionManager(dbConnection);
33-
scriptExecutor = new SqlScriptExecutor(() => connectionManager, () => new TraceUpgradeLog(), null, () => true, () => false, null);
33+
scriptExecutor = new SqlScriptExecutor(() => connectionManager, () => new TraceUpgradeLog(), null, () => true, null);
3434

3535
var builder = new UpgradeEngineBuilder()
3636
.WithScript(new SqlScript("1234", "create table $var$ (Id int)"))

src/DbUp.Tests/Support/SqlServer/SqlScriptExecutorTests.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SqlScriptExecutorTests
1616
[Test]
1717
public void verify_schema_should_not_check_when_schema_is_null()
1818
{
19-
var executor = new SqlScriptExecutor(() => Substitute.For<IConnectionManager>(), () => null, null, () => false, () => false, null);
19+
var executor = new SqlScriptExecutor(() => Substitute.For<IConnectionManager>(), () => null, null, () => false, null);
2020

2121
executor.VerifySchema();
2222
}
@@ -27,7 +27,7 @@ public void when_schema_is_null_schema_is_stripped_from_scripts()
2727
var dbConnection = Substitute.For<IDbConnection>();
2828
var command = Substitute.For<IDbCommand>();
2929
dbConnection.CreateCommand().Returns(command);
30-
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, () => false, null);
30+
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null);
3131

3232
executor.Execute(new SqlScript("Test", "create $schema$.Table"));
3333

@@ -41,7 +41,7 @@ public void uses_variable_subtitute_preprocessor_when_running_scripts()
4141
var dbConnection = Substitute.For<IDbConnection>();
4242
var command = Substitute.For<IDbCommand>();
4343
dbConnection.CreateCommand().Returns(command);
44-
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, () => false, null);
44+
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null);
4545

4646
executor.Execute(new SqlScript("Test", "create $foo$.Table"), new Dictionary<string, string>{{"foo", "bar"}});
4747

@@ -55,7 +55,7 @@ public void does_not_use_variable_subtitute_preprocessor_when_setting_false()
5555
var dbConnection = Substitute.For<IDbConnection>();
5656
var command = Substitute.For<IDbCommand>();
5757
dbConnection.CreateCommand().Returns(command);
58-
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => false, () => false, null);
58+
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => false, null);
5959

6060
executor.Execute(new SqlScript("Test", "create $foo$.Table"), new Dictionary<string, string> { { "foo", "bar" } });
6161

@@ -69,12 +69,30 @@ public void uses_variable_subtitutes_schema()
6969
var dbConnection = Substitute.For<IDbConnection>();
7070
var command = Substitute.For<IDbCommand>();
7171
dbConnection.CreateCommand().Returns(command);
72-
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), "foo", () => true, () => false, null);
72+
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), "foo", () => true, null);
7373

7474
executor.Execute(new SqlScript("Test", "create $schema$.Table"));
7575

7676
command.Received().ExecuteNonQuery();
7777
Assert.AreEqual("create [foo].Table", command.CommandText);
7878
}
79+
80+
[Test]
81+
public void logs_output_when_configured_to()
82+
{
83+
var dbConnection = Substitute.For<IDbConnection>();
84+
var command = Substitute.For<IDbCommand>();
85+
dbConnection.CreateCommand().Returns(command);
86+
var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true)
87+
{
88+
IsScriptOutputLogged = true
89+
}, () => new ConsoleUpgradeLog(), "foo", () => true, null);
90+
91+
executor.Execute(new SqlScript("Test", "create $schema$.Table"));
92+
93+
command.Received().ExecuteReader();
94+
command.DidNotReceive().ExecuteNonQuery();
95+
Assert.AreEqual("create [foo].Table", command.CommandText);
96+
}
7997
}
8098
}

src/DbUp/Builder/StandardExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static UpgradeEngineBuilder LogToConsole(this UpgradeEngineBuilder builde
5252
/// </returns>
5353
public static UpgradeEngineBuilder LogScriptOutput(this UpgradeEngineBuilder builder)
5454
{
55-
builder.Configure(c => c.IsScriptOutputLogged = true);
55+
builder.Configure(c => c.ConnectionManager.IsScriptOutputLogged = true);
5656
return builder;
5757
}
5858

src/DbUp/Builder/UpgradeConfiguration.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ public UpgradeConfiguration()
3434
/// </summary>
3535
public IUpgradeLog Log { get; set; }
3636

37-
/// <summary>
38-
/// Gets or sets a log which captures details about the upgrade.
39-
/// </summary>
40-
public bool IsScriptOutputLogged { get; set; }
41-
4237
/// <summary>
4338
/// Gets a mutable list of script providers.
4439
/// </summary>

src/DbUp/Engine/UpgradeEngine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class UpgradeEngine
1919
public UpgradeEngine(UpgradeConfiguration configuration)
2020
{
2121
this.configuration = configuration;
22-
this.configuration.ConnectionManager.IsScriptOutputLogged = this.configuration.IsScriptOutputLogged;
2322
}
2423

2524
/// <summary>

src/DbUp/Support/SqlServer/SqlScriptExecutor.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ namespace DbUp.Support.SqlServer
1818
/// </summary>
1919
public sealed class SqlScriptExecutor : IScriptExecutor
2020
{
21-
private readonly Func<IConnectionManager> connectionManager;
21+
private readonly Func<IConnectionManager> connectionManagerFactory;
2222
private readonly Func<IUpgradeLog> log;
2323
private readonly IEnumerable<IScriptPreprocessor> scriptPreprocessors;
2424
private readonly Func<bool> variablesEnabled;
25-
private readonly Func<bool> scriptOutputLogged;
2625

2726
/// <summary>
2827
/// SQLCommand Timeout in seconds. If not set, the default SQLCommand timeout is not changed.
@@ -32,21 +31,19 @@ public sealed class SqlScriptExecutor : IScriptExecutor
3231
/// <summary>
3332
/// Initializes an instance of the <see cref="SqlScriptExecutor"/> class.
3433
/// </summary>
35-
/// <param name="connectionManager"></param>
34+
/// <param name="connectionManagerFactory"></param>
3635
/// <param name="log">The logging mechanism.</param>
3736
/// <param name="schema">The schema that contains the table.</param>
3837
/// <param name="variablesEnabled">Function that returns <c>true</c> if variables should be replaced, <c>false</c> otherwise.</param>
39-
/// <param name="scriptOutputLogged">Function that returns <c>true</c> if the db script output should be logged, <c>false</c> otherwise.</param>
4038
/// <param name="scriptPreprocessors">Script Preprocessors in addition to variable substitution</param>
41-
public SqlScriptExecutor(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> log, string schema, Func<bool> variablesEnabled, Func<bool> scriptOutputLogged,
39+
public SqlScriptExecutor(Func<IConnectionManager> connectionManagerFactory, Func<IUpgradeLog> log, string schema, Func<bool> variablesEnabled,
4240
IEnumerable<IScriptPreprocessor> scriptPreprocessors)
4341
{
4442
Schema = schema;
4543
this.log = log;
4644
this.variablesEnabled = variablesEnabled;
47-
this.scriptOutputLogged = scriptOutputLogged;
4845
this.scriptPreprocessors = scriptPreprocessors;
49-
this.connectionManager = connectionManager;
46+
this.connectionManagerFactory = connectionManagerFactory;
5047
}
5148

5249
/// <summary>
@@ -70,7 +67,7 @@ public void VerifySchema()
7067
{
7168
if (string.IsNullOrEmpty(Schema)) return;
7269

73-
connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
70+
connectionManagerFactory().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
7471
{
7572
var sqlRunner = new AdHocSqlRunner(dbCommandFactory, Schema, () => true);
7673

@@ -101,11 +98,12 @@ public void Execute(SqlScript script, IDictionary<string, string> variables)
10198
contents = (scriptPreprocessors??new IScriptPreprocessor[0])
10299
.Aggregate(contents, (current, additionalScriptPreprocessor) => additionalScriptPreprocessor.Process(current));
103100

104-
var scriptStatements = connectionManager().SplitScriptIntoCommands(contents);
101+
var connectionManager = connectionManagerFactory();
102+
var scriptStatements = connectionManager.SplitScriptIntoCommands(contents);
105103
var index = -1;
106104
try
107105
{
108-
connectionManager().ExecuteCommandsWithManagedConnection(dbCommandFactory =>
106+
connectionManager.ExecuteCommandsWithManagedConnection(dbCommandFactory =>
109107
{
110108
foreach (var statement in scriptStatements)
111109
{
@@ -115,7 +113,7 @@ public void Execute(SqlScript script, IDictionary<string, string> variables)
115113
command.CommandText = statement;
116114
if (ExecutionTimeoutSeconds != null)
117115
command.CommandTimeout = ExecutionTimeoutSeconds.Value;
118-
if (scriptOutputLogged())
116+
if (connectionManager.IsScriptOutputLogged)
119117
{
120118
using (var reader = command.ExecuteReader())
121119
{

src/DbUp/Support/SqlServer/SqlServerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static UpgradeEngineBuilder SqlDatabase(IConnectionManager connectionMan
8080
{
8181
var builder = new UpgradeEngineBuilder();
8282
builder.Configure(c => c.ConnectionManager = connectionManager);
83-
builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, schema, () => c.VariablesEnabled, () => c.IsScriptOutputLogged, c.ScriptPreprocessors));
83+
builder.Configure(c => c.ScriptExecutor = new SqlScriptExecutor(() => c.ConnectionManager, () => c.Log, schema, () => c.VariablesEnabled, c.ScriptPreprocessors));
8484
builder.Configure(c => c.Journal = new SqlTableJournal(()=>c.ConnectionManager, ()=>c.Log, schema, "SchemaVersions"));
8585
return builder;
8686
}

0 commit comments

Comments
 (0)