diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index f1a6bc8..26798d9 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -2,84 +2,12 @@ name: CI
on:
push:
+ branches:
+ - '**' # Ignores pushes of tags
pull_request:
workflow_dispatch:
jobs:
build:
- runs-on: windows-latest # Use Ubuntu in v5.0
-
- env:
- DOTNET_NOLOGO: true
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Avoid pre-populating the NuGet package cache
-
- steps:
- - uses: actions/checkout@v3
- with:
- fetch-depth: 0 # all
-
- - name: Setup .NET 2.0 # Remove in v5.0
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: 2.0.x
-
- - name: Setup .NET 8.0
- uses: actions/setup-dotnet@v1
- with:
- dotnet-version: 8.0.x
-
- - name: Install NuGet
- uses: NuGet/setup-nuget@v1.2.0
-
- - name: Install GitVersion
- uses: gittools/actions/gitversion/setup@v0
- with:
- versionSpec: '5.x'
-
- - name: Run GitVersion
- id: gitversion
- uses: gittools/actions/gitversion/execute@v0
-
- - name: Display SemVer
- run: |
- echo "SemVer: $env:GitVersion_SemVer"
-
- - name: Add DbUp NuGet Source
- run: dotnet nuget add source --name DbUp --username DbUp --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text https://nuget.pkg.github.com/DbUp/index.json
-
- - name: Restore
- run: dotnet restore
- working-directory: src
-
- - name: Build
- run: dotnet build -c Release --no-restore /p:Version=$env:GitVersion_SemVer
- working-directory: src
-
- - name: Test
- run: dotnet test --no-build -c Release --logger trx --logger "console;verbosity=detailed" --results-directory ../artifacts
- working-directory: src
-
- - name: Pack
- run: dotnet pack --no-build -c Release -o ../artifacts /p:Version=$env:GitVersion_SemVer
- working-directory: src
-
- - name: Pack placeholder dbup package
- run: nuget pack ./dbup/dbup.nuspec -OutputDirectory ../artifacts -Version $env:GitVersion_SemVer
- working-directory: src
-
- - name: Push NuGet packages to GitHub Packages ⬆️
- working-directory: artifacts
- run: dotnet nuget push *.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/DbUp/index.json"
-
- - name: Push NuGet packages to NuGet ⬆️
- if: ${{ steps.gitversion.outputs.preReleaseLabel == '' }}
- working-directory: artifacts
- run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json
-
- - name: Test Report 🧪
- uses: dorny/test-reporter@v1
- if: ${{ always() }}
- with:
- name: Tests
- path: artifacts/*.trx
- reporter: dotnet-trx
+ name: Build
+ uses: DbUp/Universe/.github/workflows/build.yml@main
diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml
new file mode 100644
index 0000000..eb5e03f
--- /dev/null
+++ b/.github/workflows/publish-release.yml
@@ -0,0 +1,12 @@
+name: Publish DbUp Packages to NuGet
+
+on:
+ release:
+ types: [ published ]
+ workflow_dispatch:
+
+jobs:
+ publish:
+ name: Publish Package
+ uses: DbUp/Universe/.github/workflows/publish-release.yml@main
+ secrets: inherit
diff --git a/GitVersion.yml b/GitVersion.yml
index c311488..9c1685d 100644
--- a/GitVersion.yml
+++ b/GitVersion.yml
@@ -1 +1,2 @@
-mode: Mainline
\ No newline at end of file
+mode: Mainline
+next-version: 6.0.0
\ No newline at end of file
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index 196f572..71548cd 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -11,17 +11,4 @@
true
-
-
-
- true
-
-
- true
-
-
- embedded
-
-
-
diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt
similarity index 90%
rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt
rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt
index 6192175..4df7abb 100644
--- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt
+++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt
@@ -1,11 +1,11 @@
-DB Operation: Open connection
+DB Operation: Open connection
Info: Beginning database upgrade
-Info: Checking whether journal table exists..
+Info: Checking whether journal table exists
DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'SchemaVersions'
DB Operation: Dispose command
Info: Journal table does not exist
Info: Executing Database Server script 'Script0001.sql'
-Info: Checking whether journal table exists..
+Info: Checking whether journal table exists
DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'SchemaVersions'
DB Operation: Dispose command
Info: Creating the [SchemaVersions] table
diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt
similarity index 91%
rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt
rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt
index 9ca0e23..1f52d9c 100644
--- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt
+++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt
@@ -1,11 +1,11 @@
-DB Operation: Open connection
+DB Operation: Open connection
Info: Beginning database upgrade
-Info: Checking whether journal table exists..
+Info: Checking whether journal table exists
DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TestSchemaVersions' and TABLE_SCHEMA = 'test'
DB Operation: Dispose command
Info: Journal table does not exist
Info: Executing Database Server script 'Script0001.sql'
-Info: Checking whether journal table exists..
+Info: Checking whether journal table exists
DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TestSchemaVersions' and TABLE_SCHEMA = 'test'
DB Operation: Dispose command
Info: Creating the [test].[TestSchemaVersions] table
diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt
similarity index 90%
rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt
rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt
index 9c20bfc..c3fa619 100644
--- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt
+++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt
@@ -1,11 +1,11 @@
-DB Operation: Open connection
+DB Operation: Open connection
Info: Beginning database upgrade
-Info: Checking whether journal table exists..
+Info: Checking whether journal table exists
DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'SchemaVersions'
DB Operation: Dispose command
Info: Journal table does not exist
Info: Executing Database Server script 'Script0001.sql'
-Info: Checking whether journal table exists..
+Info: Checking whether journal table exists
DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'SchemaVersions'
DB Operation: Dispose command
Info: Creating the [SchemaVersions] table
diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs
deleted file mode 100644
index 288c72f..0000000
--- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-[assembly: System.CLSCompliantAttribute(true)]
-[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
-[assembly: System.Runtime.InteropServices.GuidAttribute("8190b40b-ac5b-414f-8a00-9b6a2c12b010")]
-
-public static class AzureSqlServerExtensions
-{
- public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
- public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, string resource) { }
- public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, string resource, string tenantId, string azureAdInstance = "https://login.microsoftonline.com/") { }
-}
-public static class SqlServerExtensions
-{
- public static DbUp.Builder.UpgradeEngineBuilder JournalToSqlTable(this DbUp.Builder.UpgradeEngineBuilder builder, string schema, string table) { }
- public static DbUp.Builder.UpgradeEngineBuilder LogToSqlContext(this DbUp.Builder.UpgradeEngineBuilder builder) { }
- public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
- public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
- public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema = null) { }
- [System.ObsoleteAttribute("Use "AzureSqlDatabaseWithIntegratedSecurity(this SupportedDatabases, string, string)" if passing "true" to "useAzureSqlIntegratedSecurity".")]
- public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, bool useAzureSqlIntegratedSecurity) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, string collation) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, int commandTimeout) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null) { }
-}
-namespace DbUp.SqlServer
-{
- public enum AzureDatabaseEdition : int
- {
- None = 0
- Basic = 1
- Standard = 2
- Premium = 3
- }
- public class AzureSqlConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
- {
- public AzureSqlConnectionManager(string connectionString) { }
- public AzureSqlConnectionManager(string connectionString, string resource) { }
- public AzureSqlConnectionManager(string connectionString, string resource, string tenantId, string azureAdInstance = "https://login.microsoftonline.com/") { }
- public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { }
- }
- public class SqlConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
- {
- public SqlConnectionManager(string connectionString) { }
- public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { }
- }
- public class SqlScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor
- {
- public SqlScriptExecutor(System.Func connectionManagerFactory, System.Func log, string schema, System.Func variablesEnabled, System.Collections.Generic.IEnumerable scriptPreprocessors, System.Func journalFactory) { }
- protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { }
- protected override string GetVerifySchemaSql(string schema) { }
- }
- public class SqlServerObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser
- {
- public SqlServerObjectParser() { }
- public override string QuoteIdentifier(string objectName, DbUp.Support.ObjectNameOptions objectNameOptions) { }
- }
- public class SqlTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal
- {
- public SqlTableJournal(System.Func connectionManager, System.Func logger, string schema, string table) { }
- protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { }
- protected override string GetInsertJournalEntrySql(string scriptName, string applied) { }
- protected override string GetJournalEntriesSql() { }
- }
-}
-namespace DbUp.SqlServer.Helpers
-{
- public class TemporarySqlDatabase : System.IDisposable
- {
- public TemporarySqlDatabase(string name) { }
- public TemporarySqlDatabase(System.Data.SqlClient.SqlConnectionStringBuilder connectionStringBuilder) { }
- public TemporarySqlDatabase(string name, string instanceName) { }
- public DbUp.Helpers.AdHocSqlRunner AdHoc { get; }
- public string ConnectionString { get; }
- public void Create() { }
- public void Dispose() { }
- public static DbUp.SqlServer.Helpers.TemporarySqlDatabase FromConnectionString(string connectionString) { }
- }
-}
diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs
similarity index 80%
rename from src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs
rename to src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs
index 98376b6..c0b0bcb 100644
--- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs
+++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs
@@ -1,33 +1,32 @@
-[assembly: System.CLSCompliantAttribute(true)]
+[assembly: System.CLSCompliantAttribute(false)]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
[assembly: System.Runtime.InteropServices.GuidAttribute("8190b40b-ac5b-414f-8a00-9b6a2c12b010")]
public static class AzureSqlServerExtensions
{
- public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
- public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, string resource) { }
- public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, string resource, string tenantId, string azureAdInstance = "https://login.microsoftonline.com/") { }
+ public static DbUp.Builder.UpgradeEngineBuilder AzureSqlDatabaseWithIntegratedSecurity(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema = null, Azure.Core.TokenCredential tokenCredential = null, string resource = "https://database.windows.net/", string tenantId = null) { }
}
public static class SqlServerExtensions
{
public static DbUp.Builder.UpgradeEngineBuilder JournalToSqlTable(this DbUp.Builder.UpgradeEngineBuilder builder, string schema, string table) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, string collation) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null, System.Func> createDbSqlCommandsFactory = null, bool checkOnly = false) { }
+ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null, System.Func> createDbSqlCommandsFactory = null, bool checkOnly = false) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema = null) { }
[System.ObsoleteAttribute("Use "AzureSqlDatabaseWithIntegratedSecurity(this SupportedDatabases, string, string)" if passing "true" to "useAzureSqlIntegratedSecurity".")]
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, bool useAzureSqlIntegratedSecurity) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString) { }
public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, string collation) { }
public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, int commandTimeout) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
public static void SqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
- public static void SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null) { }
}
namespace DbUp.SqlServer
{
@@ -40,9 +39,7 @@ public enum AzureDatabaseEdition : int
}
public class AzureSqlConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
{
- public AzureSqlConnectionManager(string connectionString) { }
- public AzureSqlConnectionManager(string connectionString, string resource) { }
- public AzureSqlConnectionManager(string connectionString, string resource, string tenantId, string azureAdInstance = "https://login.microsoftonline.com/") { }
+ public AzureSqlConnectionManager(string connectionString, Azure.Core.TokenCredential tokenCredential, string resource = "https://database.windows.net/", string tenantId = null) { }
public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { }
}
public class SqlConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
diff --git a/src/Tests/SqlScriptExecutorTests.cs b/src/Tests/SqlScriptExecutorTests.cs
index 9107103..21908e6 100644
--- a/src/Tests/SqlScriptExecutorTests.cs
+++ b/src/Tests/SqlScriptExecutorTests.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
+using System.Data;
using System.Data.Common;
using DbUp.Engine;
using DbUp.Engine.Output;
@@ -18,7 +16,8 @@ public class SqlScriptExecutorTests
[Fact]
public void verify_schema_should_not_check_when_schema_is_null()
{
- var executor = new SqlScriptExecutor(() => Substitute.For(), () => null, null, () => false, null, () => Substitute.For());
+ var executor = new SqlScriptExecutor(() => Substitute.For(), () => null, null,
+ () => false, null, () => Substitute.For());
executor.VerifySchema();
}
@@ -26,10 +25,8 @@ public void verify_schema_should_not_check_when_schema_is_null()
[Fact]
public void when_schema_is_null_schema_is_stripped_from_scripts()
{
- var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command);
executor.Execute(new SqlScript("Test", "create $schema$.Table"));
@@ -40,12 +37,11 @@ public void when_schema_is_null_schema_is_stripped_from_scripts()
[Fact]
public void uses_variable_substitute_preprocessor_when_running_scripts()
{
- var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command);
- executor.Execute(new SqlScript("Test", "create $foo$.Table"), new Dictionary { { "foo", "bar" } });
+ executor.Execute(new SqlScript("Test", "create $foo$.Table"),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe("create bar.Table");
@@ -58,12 +54,11 @@ public void uses_variable_subtitute_preprocessor_when_running_scripts_with_singl
create $foo$.Table";
var oneLineCommentResult = @"--from excel $A$6
create bar.Table";
- var dbConnection = Substitute.For();
- var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
- executor.Execute(new SqlScript("Test", oneLineComment), new Dictionary { { "foo", "bar" } });
+ var command = Substitute.For();
+ var executor = GetSqlScriptExecutor(command);
+ executor.Execute(new SqlScript("Test", oneLineComment),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe(oneLineCommentResult);
@@ -76,12 +71,14 @@ public void uses_variable_substitute_preprocessor_when_running_scripts_with_one_
create $foo$.Table";
var oneLineCommentResult = @"/* from excel $A$6 */
create bar.Table";
- var dbConnection = Substitute.For();
+
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command);
+ executor.Execute(new SqlScript("Test", oneLineComment),
+ new Dictionary { { "foo", "bar" } });
- executor.Execute(new SqlScript("Test", oneLineComment), new Dictionary { { "foo", "bar" } });
+ executor.Execute(new SqlScript("Test", oneLineComment),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe(oneLineCommentResult);
@@ -101,12 +98,13 @@ some comment
from excel $A$6
some comment
*/
- create bar.Table"; var dbConnection = Substitute.For();
+ create bar.Table";
+ var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command);
- executor.Execute(new SqlScript("Test", multiLineComment), new Dictionary { { "foo", "bar" } });
+ executor.Execute(new SqlScript("Test", multiLineComment),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe(multiLineCommentResult);
@@ -126,12 +124,13 @@ some comment
--from excel $A$6
some comment
*/
- create bar.Table"; var dbConnection = Substitute.For();
+ create bar.Table";
+ var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command);
- executor.Execute(new SqlScript("Test", multiLineComment), new Dictionary { { "foo", "bar" } });
+ executor.Execute(new SqlScript("Test", multiLineComment),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe(multiLineCommentResult);
@@ -151,12 +150,13 @@ some comment
/* from excel $A$6 */
some comment
*/
- create bar.Table"; var dbConnection = Substitute.For();
+ create bar.Table";
+ var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command);
- executor.Execute(new SqlScript("Test", multiLineComment), new Dictionary { { "foo", "bar" } });
+ executor.Execute(new SqlScript("Test", multiLineComment),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe(multiLineCommentResult);
@@ -165,24 +165,22 @@ some comment
[Fact]
public void does_not_use_variable_substitute_preprocessor_when_setting_false()
{
- var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), null, () => false, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command, variablesEnabled: false);
- executor.Execute(new SqlScript("Test", "create $foo$.Table"), new Dictionary { { "foo", "bar" } });
+ executor.Execute(new SqlScript("Test", "create $foo$.Table"),
+ new Dictionary { { "foo", "bar" } });
command.Received().ExecuteNonQuery();
command.CommandText.ShouldBe("create $foo$.Table");
}
+
[Fact]
public void uses_variable_subtitutes_schema()
{
- var dbConnection = Substitute.For();
var command = Substitute.For();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true), () => new ConsoleUpgradeLog(), "foo", () => true, null, () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command, schema: "foo");
executor.Execute(new SqlScript("Test", "create $schema$.Table"));
@@ -193,7 +191,6 @@ public void uses_variable_subtitutes_schema()
[Fact]
public void logs_output_when_configured_to()
{
- var dbConnection = Substitute.For();
var command = Substitute.For();
var reader = Substitute.For();
@@ -210,31 +207,22 @@ public void logs_output_when_configured_to()
command.ExecuteReader().Returns(reader);
var logger = new CaptureLogsLogger();
- dbConnection.CreateCommand().Returns(command);
- var executor = new SqlScriptExecutor(() => new TestConnectionManager(dbConnection, true) { IsScriptOutputLogged = true },
- () => logger,
- "foo",
- () => true,
- null,
- () => Substitute.For());
+ var executor = GetSqlScriptExecutor(command, log: logger, schema: "foo", isScriptOutputLogged: true);
executor.Execute(new SqlScript("Test", "SELECT * FROM $schema$.[Table]"));
- command.Received().ExecuteReader();
+ command.ReceivedWithAnyArgs().ExecuteReader();
command.DidNotReceive().ExecuteNonQuery();
command.CommandText.ShouldBe("SELECT * FROM [foo].[Table]");
logger.Log.Trim()
- .ShouldBe(string.Join(Environment.NewLine, new[]
- {
- "Info: Executing Database Server script 'Test'",
- "Info: -------------",
- "Info: | One | Two |",
- "Info: -------------",
- "Info: | A | B |",
- "Info: -------------",
- "Info:"
- }));
+ .ShouldBe(string.Join(Environment.NewLine,
+ new[]
+ {
+ "Info: Executing Database Server script 'Test'", "Info: -------------",
+ "Info: | One | Two |", "Info: -------------", "Info: | A | B |",
+ "Info: -------------", "Info:"
+ }));
}
[Fact]
@@ -250,14 +238,34 @@ public void logs_when_dbexception()
});
dbConnection.CreateCommand().Returns(command);
var logger = Substitute.For();
- logger.WhenForAnyArgs(x => x.WriteError(null, null)).Do(x => Console.WriteLine(x.Arg(), x.Arg