Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[assembly: System.CLSCompliant(false)]
[assembly: System.CLSCompliant(false)]
[assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/DbUp/dbup-sqlserver.git")]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Runtime.InteropServices.Guid("8190b40b-ac5b-414f-8a00-9b6a2c12b010")]
Expand All @@ -10,10 +10,12 @@ public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSe
public static class SqlServerExtensions
{
public static DbUp.Builder.UpgradeEngineBuilder JournalToSqlTable(this DbUp.Builder.UpgradeEngineBuilder builder, string schema, string table) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, Microsoft.Data.SqlClient.SqlConnection connection) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema = null) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, Microsoft.Data.SqlClient.SqlConnection connection, string schema) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, int commandTimeout) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
Expand Down Expand Up @@ -46,6 +48,7 @@ public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCo
}
public class SqlConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager
{
public SqlConnectionManager(Microsoft.Data.SqlClient.SqlConnection connection) { }
public SqlConnectionManager(string connectionString) { }
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { }
}
Expand Down
22 changes: 14 additions & 8 deletions src/dbup-sqlserver/SqlConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using DbUp.Engine.Transactions;
using DbUp.Support;
Expand All @@ -15,15 +15,21 @@ public class SqlConnectionManager : DatabaseConnectionManager
/// </summary>
/// <param name="connectionString"></param>
public SqlConnectionManager(string connectionString)
: base(new DelegateConnectionFactory((log, dbManager) =>
{
var conn = new SqlConnection(connectionString);
: this(new SqlConnection(connectionString))
{ }

if (dbManager.IsScriptOutputLogged)
conn.InfoMessage += (sender, e) => log.LogInformation($"{{0}}", e.Message);
/// <summary>
/// Manages Sql Database Connections using an existing connection.
/// </summary>
/// <param name="connection">The existing SQL connection to use.</param>
public SqlConnectionManager(SqlConnection connection)
: base(new DelegateConnectionFactory((log, dbManager) =>
{
if (dbManager.IsScriptOutputLogged)
connection.InfoMessage += (sender, e) => log.LogInformation($"{{0}}", e.Message);

return conn;
}))
return connection;
}))
{ }

/// <inheritdoc/>
Expand Down
27 changes: 27 additions & 0 deletions src/dbup-sqlserver/SqlServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public static UpgradeEngineBuilder SqlDatabase(this SupportedDatabases supported
return SqlDatabase(supported, connectionString, null);
}

/// <summary>
/// Creates an upgrader for SQL Server databases.
/// </summary>
/// <param name="supported">Fluent helper type.</param>
/// <param name="connection">The sql connection.</param>
/// <returns>
/// A builder for a database upgrader designed for SQL Server databases.
/// </returns>
public static UpgradeEngineBuilder SqlDatabase(this SupportedDatabases supported, SqlConnection connection)
{
return SqlDatabase(supported, connection, null);
}

/// <summary>
/// Creates an upgrader for SQL Server databases.
/// </summary>
Expand Down Expand Up @@ -62,6 +75,20 @@ public static UpgradeEngineBuilder SqlDatabase(this SupportedDatabases supported
return supported.SqlDatabase(new SqlConnectionManager(connectionString), schema);
}

/// <summary>
/// Creates an upgrader for SQL Server databases.
/// </summary>
/// <param name="supported">Fluent helper type.</param>
/// <param name="connection">The sql connection.</param>
/// <param name="schema">The SQL schema name to use. Defaults to 'dbo'.</param>
/// <returns>
/// A builder for a database upgrader designed for SQL Server databases.
/// </returns>
public static UpgradeEngineBuilder SqlDatabase(this SupportedDatabases supported, SqlConnection connection, string schema)
{
return SqlDatabase(new SqlConnectionManager(connection), schema);
}

/// <summary>
/// Creates an upgrader for SQL Server databases.
/// </summary>
Expand Down