From 81bb291fc3e6d8f4175b32e60ffe807ebf1a0d3b Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 15 Mar 2024 21:29:13 +1000 Subject: [PATCH 01/16] Only target netstandard 2.0 --- ...portTests.VerifyBasicSupport.approved.txt} | 6 +- ...JournalCreationIfNameChanged.approved.txt} | 6 +- ....VerifyVariableSubstitutions.approved.txt} | 6 +- .../NoPublicApiChanges.Run.Net.verified.cs | 58 ------------------- ....cs => NoPublicApiChanges.Run.approved.cs} | 2 +- src/Tests/DatabaseSupportTests.cs | 7 +-- src/Tests/MySqlConnectionManagerTests.cs | 4 +- ...portTests.CanHandleDelimiter.approved.txt} | 36 +++++++----- src/Tests/MySqlSupportTests.cs | 15 ++--- src/Tests/NoPublicApiChanges.cs | 6 +- src/Tests/Tests.csproj | 10 ++-- src/dbup-mysql/MySqlExtensions.cs | 4 +- src/dbup-mysql/MySqlScriptExecutor.cs | 10 +--- src/dbup-mysql/dbup-mysql.csproj | 23 +------- 14 files changed, 56 insertions(+), 137 deletions(-) rename src/Tests/ApprovalFiles/{DatabaseSupportTests.VerifyBasicSupport.verified.txt => DatabaseSupportTests.VerifyBasicSupport.approved.txt} (90%) rename src/Tests/ApprovalFiles/{DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt => DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt} (91%) rename src/Tests/ApprovalFiles/{DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt => DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt} (90%) delete mode 100644 src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs rename src/Tests/ApprovalFiles/{NoPublicApiChanges.Run.DotNet.verified.cs => NoPublicApiChanges.Run.approved.cs} (98%) rename src/Tests/{ApprovalFiles/MySqlSupportTests.CanHandleDelimiter.verified.txt => MySqlSupportTests.CanHandleDelimiter.approved.txt} (59%) 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 fe10484..3ea7dbe 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 780fceb..ba71ccf 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 af915cf..98d5fc4 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 b25c715..0000000 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs +++ /dev/null @@ -1,58 +0,0 @@ -[assembly: System.CLSCompliantAttribute(true)] -[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] -[assembly: System.Runtime.InteropServices.GuidAttribute("b6988607-c547-4cbd-8012-f8162a25092f")] - -public static class MySqlExtensions -{ - public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager) { } - public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } - public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager) { } - public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema) { } - public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { } - public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString) { } - public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout) { } - public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, string collation) { } - public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { } - public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, string collation = null) { } -} -namespace DbUp.MySql -{ - public class MySqlCommandReader : DbUp.Support.SqlCommandReader, System.IDisposable - { - public MySqlCommandReader(string sqlText) { } - protected override bool IsCustomStatement { get; } - protected override void ReadCustomStatement() { } - } - public class MySqlCommandSplitter - { - public MySqlCommandSplitter() { } - public System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { } - } - public class MySqlConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager - { - public MySqlConnectionManager(string connectionString) { } - public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { } - } - public class MySqlObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser - { - public MySqlObjectParser() { } - } - public class MySqlPreprocessor : DbUp.Engine.IScriptPreprocessor - { - public MySqlPreprocessor() { } - public string Process(string contents) { } - } - public class MySqlScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor - { - public MySqlScriptExecutor(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 MySqlTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal - { - public MySqlTableJournal(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() { } - } -} diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs similarity index 98% rename from src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs rename to src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs index b25c715..c129d52 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs @@ -1,4 +1,4 @@ -[assembly: System.CLSCompliantAttribute(true)] +[assembly: System.CLSCompliantAttribute(true)] [assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] [assembly: System.Runtime.InteropServices.GuidAttribute("b6988607-c547-4cbd-8012-f8162a25092f")] diff --git a/src/Tests/DatabaseSupportTests.cs b/src/Tests/DatabaseSupportTests.cs index f5e6232..cb8dca2 100644 --- a/src/Tests/DatabaseSupportTests.cs +++ b/src/Tests/DatabaseSupportTests.cs @@ -1,9 +1,7 @@ -#if !NETCORE -using DbUp.Builder; -using DbUp.MySql; +using DbUp.Builder; using DbUp.Tests.Common; -namespace DbUp.Tests.Providers.MySql; +namespace DbUp.MySql.Tests; public class DatabaseSupportTests : DatabaseSupportTestsBase { @@ -20,4 +18,3 @@ protected override UpgradeEngineBuilder AddCustomNamedJournalToBuilder(UpgradeEn => new MySqlTableJournal(connectionManagerFactory, logFactory, schema, tableName) ); } -#endif diff --git a/src/Tests/MySqlConnectionManagerTests.cs b/src/Tests/MySqlConnectionManagerTests.cs index dfd5c74..ed65fb0 100644 --- a/src/Tests/MySqlConnectionManagerTests.cs +++ b/src/Tests/MySqlConnectionManagerTests.cs @@ -1,12 +1,10 @@ using System; using System.Linq; using System.Text; -using System.Threading.Tasks; -using DbUp.MySql; using Shouldly; using Xunit; -namespace DbUp.Tests.Support.MySql +namespace DbUp.MySql.Tests { public class MySqlConnectionManagerTests { diff --git a/src/Tests/ApprovalFiles/MySqlSupportTests.CanHandleDelimiter.verified.txt b/src/Tests/MySqlSupportTests.CanHandleDelimiter.approved.txt similarity index 59% rename from src/Tests/ApprovalFiles/MySqlSupportTests.CanHandleDelimiter.verified.txt rename to src/Tests/MySqlSupportTests.CanHandleDelimiter.approved.txt index 7d49bda..d72d5f8 100644 --- a/src/Tests/ApprovalFiles/MySqlSupportTests.CanHandleDelimiter.verified.txt +++ b/src/Tests/MySqlSupportTests.CanHandleDelimiter.approved.txt @@ -1,22 +1,30 @@ -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: Fetching list of already executed scripts. -DB Operation: Execute reader command: select scriptname from `schemaversions` order by scriptname -DB Operation: Dispose command +Info: Journal table does not exist Info: Executing Database Server script 'Script0003' -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 -DB Operation: Execute non query command: USE `test` -DB Operation: Dispose command -DB Operation: Execute non query command: DROP procedure IF EXISTS `testSproc` -DB Operation: Dispose command -DB Operation: Execute non query command: USE `test` -DB Operation: Dispose command -DB Operation: Execute non query command: CREATE PROCEDURE `testSproc`( +Info: Creating the `schemaversions` table +DB Operation: Execute non query command: CREATE TABLE `schemaversions` +( + `schemaversionid` INT NOT NULL AUTO_INCREMENT, + `scriptname` VARCHAR(255) NOT NULL, + `applied` TIMESTAMP NOT NULL, + PRIMARY KEY (`schemaversionid`) +); +DB Operation: Dispose command +Info: The `schemaversions` table has been created +DB Operation: Execute non query command: USE `test`; +DROP procedure IF EXISTS `testSproc`; + +DELIMITER $$ + +USE `test`$$ +CREATE PROCEDURE `testSproc`( IN ssn VARCHAR(32) ) BEGIN @@ -25,7 +33,7 @@ BEGIN FROM customer as c WHERE c.ssn = ssn ; -END +END$$ DB Operation: Dispose command DB Operation: Create parameter Info: DB Operation: Add parameter to command: scriptName=Script0003 diff --git a/src/Tests/MySqlSupportTests.cs b/src/Tests/MySqlSupportTests.cs index 2c46e67..14d2e8c 100644 --- a/src/Tests/MySqlSupportTests.cs +++ b/src/Tests/MySqlSupportTests.cs @@ -1,24 +1,21 @@ using System.Threading.Tasks; +using Assent; using DbUp.Tests.Common; using DbUp.Tests.Common.RecordingDb; using Shouldly; -using VerifyXunit; using Xunit; -namespace DbUp.Tests.Support.MySql +namespace DbUp.MySql.Tests { - [UsesVerify] public class MySqlSupportTests { [Fact] - public Task CanHandleDelimiter() + public void CanHandleDelimiter() { var logger = new CaptureLogsLogger(); - var recordingDbConnection = new RecordingDbConnection(logger, "schemaversions"); - recordingDbConnection.SetupRunScripts(); + var recordingDbConnection = new RecordingDbConnection(logger); var upgrader = DeployChanges.To - .MySqlDatabase(string.Empty) - .OverrideConnectionFactory(recordingDbConnection) + .MySqlDatabase(new TestConnectionManager(recordingDbConnection)) .LogTo(logger) .WithScript("Script0003", @"USE `test`; DROP procedure IF EXISTS `testSproc`; @@ -40,7 +37,7 @@ FROM customer as c var result = upgrader.PerformUpgrade(); result.Successful.ShouldBe(true); - return Verifier.Verify(logger.Log, VerifyHelper.GetVerifySettings()); + this.Assent(logger.Log, new Configuration().UsingSanitiser(Scrubbers.ScrubDates)); } } } diff --git a/src/Tests/NoPublicApiChanges.cs b/src/Tests/NoPublicApiChanges.cs index 52d3a5e..9618037 100644 --- a/src/Tests/NoPublicApiChanges.cs +++ b/src/Tests/NoPublicApiChanges.cs @@ -1,7 +1,6 @@ -#if !NETCORE -using DbUp.Tests.Common; +using DbUp.Tests.Common; -namespace DbUp.Tests.Providers.MySql; +namespace DbUp.MySql.Tests; public class NoPublicApiChanges : NoPublicApiChangesBase { @@ -10,4 +9,3 @@ public NoPublicApiChanges() { } } -#endif diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index d76581b..555645c 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -1,7 +1,7 @@ - net462;net8 + net8 Tests DbUp.MySql.Tests @@ -10,10 +10,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/dbup-mysql/MySqlExtensions.cs b/src/dbup-mysql/MySqlExtensions.cs index 478c6e9..7f32379 100644 --- a/src/dbup-mysql/MySqlExtensions.cs +++ b/src/dbup-mysql/MySqlExtensions.cs @@ -164,7 +164,7 @@ public static void MySqlDatabase( } catch (Exception e) { - logger.WriteInformation(@"Database not found on server with connection string in settings: {0}", e.Message); + logger.LogInformation(@"Database not found on server with connection string in settings: {0}", e.Message); } using (var connection = new MySqlConnection(masterConnectionString)) @@ -195,7 +195,7 @@ public static void MySqlDatabase( command.ExecuteNonQuery(); } - logger.WriteInformation(@"Created database {0}", databaseName); + logger.LogInformation(@"Created database {0}", databaseName); } } diff --git a/src/dbup-mysql/MySqlScriptExecutor.cs b/src/dbup-mysql/MySqlScriptExecutor.cs index 5e221a6..70324de 100644 --- a/src/dbup-mysql/MySqlScriptExecutor.cs +++ b/src/dbup-mysql/MySqlScriptExecutor.cs @@ -41,14 +41,10 @@ protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScri } catch (MySqlException exception) { -#if MY_SQL_DATA_6_9_5 - var code = exception.ErrorCode; -#else var code = exception.Code; -#endif - Log().WriteInformation("MySql exception has occurred in script: '{0}'", script.Name); - Log().WriteError("Script block number: {0}; MySql error code: {1}; Number {2}; Message: {3}", index, code, exception.Number, exception.Message); - Log().WriteError(exception.ToString()); + Log().LogInformation("MySql exception has occurred in script: '{0}'", script.Name); + Log().LogError("Script block number: {0}; MySql error code: {1}; Number {2}; Message: {3}", index, code, exception.Number, exception.Message); + Log().LogError(exception.ToString()); throw; } } diff --git a/src/dbup-mysql/dbup-mysql.csproj b/src/dbup-mysql/dbup-mysql.csproj index 1e7d602..c3dd23c 100644 --- a/src/dbup-mysql/dbup-mysql.csproj +++ b/src/dbup-mysql/dbup-mysql.csproj @@ -6,7 +6,7 @@ DbUp Contributors DbUp Copyright © DbUp Contributors 2015 - netstandard1.3;netstandard2.0;net462 + netstandard2.0 dbup-mysql DbUp.MySql dbup-mysql @@ -16,27 +16,10 @@ dbup-icon.png - - $(DefineConstants);MY_SQL_DATA_6_9_5 - - - + - - - - - - - - - - - - - - + From daef96b9d6b74285a5a6e75467292ffa4d7292ba Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 18 Mar 2024 16:22:19 +1000 Subject: [PATCH 02/16] Removed install of net 2.0 --- .github/workflows/main.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18198a1..80acd6c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,17 +12,13 @@ jobs: env: DOTNET_NOLOGO: true DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Avoid pre-populating the NuGet package cache + ASSENTNONINTERACTIVE: true 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: From 6dd4d28a88df9196bcb1ecc447b27f53fdb5a9cc Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 18 Mar 2024 16:42:15 +1000 Subject: [PATCH 03/16] Moved CI optimisations into just the main project --- src/Directory.Build.props | 13 ------------- src/dbup-mysql.sln | 1 + src/dbup-mysql/dbup-mysql.csproj | 6 ++++++ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 1d2e110..b053fd8 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -11,17 +11,4 @@ true - - - - true - - - true - - - embedded - - - diff --git a/src/dbup-mysql.sln b/src/dbup-mysql.sln index f3deaf1..2e3b507 100644 --- a/src/dbup-mysql.sln +++ b/src/dbup-mysql.sln @@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{77157734-01D ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig dbup-mysql.sln.DotSettings = dbup-mysql.sln.DotSettings + Directory.Build.props = Directory.Build.props EndProjectSection EndProject Global diff --git a/src/dbup-mysql/dbup-mysql.csproj b/src/dbup-mysql/dbup-mysql.csproj index c3dd23c..ce3df24 100644 --- a/src/dbup-mysql/dbup-mysql.csproj +++ b/src/dbup-mysql/dbup-mysql.csproj @@ -16,6 +16,12 @@ dbup-icon.png + + true + true + embedded + + From ffe1cb7d4cec972044b907eec6a0f516d41674d6 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 19 Mar 2024 12:55:26 +1000 Subject: [PATCH 04/16] Fix Readme and template --- .github/pull_request_template.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 495ce36..161da36 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,5 +1,5 @@ # Checklist -- [ ] I have read the [Contributing Guide](https://github.com/DbUp/DbUp/blob/master/CONTRIBUTING.md) +- [ ] I have read the [Contributing Guide](https://github.com/DbUp/DbUp/blob/main/CONTRIBUTING.md) - [ ] I have checked to ensure this does not introduce an unintended breaking changes - [ ] I have considered appropriate testing for my change diff --git a/README.md b/README.md index a2abaf9..5a061e6 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,4 @@ Please only log issue related to MySql support in this repo. For cross cutting i # Contributing -See the [readme in our main repo](https://github.com/DbUp/DbUp/blob/master/README.md) for how to get started and contribute. \ No newline at end of file +See the [readme in our main repo](https://github.com/DbUp/DbUp/blob/main/README.md) for how to get started and contribute. \ No newline at end of file From d364c9fd7b58fa70689fc5a8312c251af982d71f Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 19 Mar 2024 13:43:36 +1000 Subject: [PATCH 05/16] Build on Ubuntu (#12) * Build on Ubuntu * Used bash variables --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 80acd6c..7d66207 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,7 +7,7 @@ on: jobs: build: - runs-on: windows-latest # Use Ubuntu in v5.0 + runs-on: ubuntu-latest env: DOTNET_NOLOGO: true @@ -35,7 +35,7 @@ jobs: - name: Display SemVer run: | - echo "SemVer: $env:GitVersion_SemVer" + echo "SemVer: $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 @@ -45,7 +45,7 @@ jobs: working-directory: src - name: Build - run: dotnet build -c Release --no-restore /p:Version=$env:GitVersion_SemVer + run: dotnet build -c Release --no-restore /p:Version=$GitVersion_SemVer working-directory: src - name: Test @@ -53,7 +53,7 @@ jobs: working-directory: src - name: Pack - run: dotnet pack --no-build -c Release -o ../artifacts /p:Version=$env:GitVersion_SemVer + run: dotnet pack --no-build -c Release -o ../artifacts /p:Version=$GitVersion_SemVer working-directory: src - name: Push NuGet packages to GitHub Packages ⬆️ From 27e3a96aa08e74227db86919cbbaea66a175ec91 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 20 Mar 2024 10:20:25 +1000 Subject: [PATCH 06/16] Use reusable workflow for build (#13) * Only target netstandard 2.0 * Removed install of net 2.0 * Moved CI optimisations into just the main project * Fix Readme and template * Build on Ubuntu (#12) * Build on Ubuntu * Used bash variables * Used re-usable workflow * Specified the branch * Used .github/workflow/ path for workflows * Fix name * Used root workflow folder * passed secret explicitly * fix * Not pass secret * Changed branch # Conflicts: # .github/workflows/main.yml --- .github/workflows/main.yml | 67 +-------------------------- .github/workflows/publish-release.yml | 11 +++++ .github/workflows/test-report.yml | 13 ++++++ src/dbup-mysql.sln | 2 + 4 files changed, 28 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/publish-release.yml create mode 100644 .github/workflows/test-report.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7d66207..3794b45 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,68 +7,5 @@ on: jobs: build: - runs-on: ubuntu-latest - - env: - DOTNET_NOLOGO: true - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Avoid pre-populating the NuGet package cache - ASSENTNONINTERACTIVE: true - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 # all - - - name: Setup .NET 8.0 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 8.0.x - - - 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: $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=$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=$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@reusable diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..1968a3f --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,11 @@ +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@reusable diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml new file mode 100644 index 0000000..f0881e5 --- /dev/null +++ b/.github/workflows/test-report.yml @@ -0,0 +1,13 @@ +name: Test Report +run-name: Generate Test Report for workflow ${{ github.event.workflow_run.name }} run ${{ github.event.workflow_run.run_number }} branch ${{ github.event.workflow_run.head_branch }} + +on: + workflow_run: + workflows: [ "CI" ] + types: + - completed + +jobs: + report: + name: Test Report 🧪 + uses: DbUp/Universe/.github/workflows/test-report.yml@reusable \ No newline at end of file diff --git a/src/dbup-mysql.sln b/src/dbup-mysql.sln index 2e3b507..12f2895 100644 --- a/src/dbup-mysql.sln +++ b/src/dbup-mysql.sln @@ -15,6 +15,8 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{62E5FE92-E288-4E09-964D-F92AF0E49131}" ProjectSection(SolutionItems) = preProject ..\.github\workflows\main.yml = ..\.github\workflows\main.yml + ..\.github\workflows\publish-release.yml = ..\.github\workflows\publish-release.yml + ..\.github\workflows\test-report.yml = ..\.github\workflows\test-report.yml EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{5DA19CA9-8039-46D6-B474-021943582785}" From a03d6d7e2df8e8e5499b8fb5c9b20db08b85a4de Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 20 Mar 2024 11:42:15 +1000 Subject: [PATCH 07/16] pass secrets to reusable workflow --- .github/workflows/test-report.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml index f0881e5..8919267 100644 --- a/.github/workflows/test-report.yml +++ b/.github/workflows/test-report.yml @@ -3,11 +3,11 @@ run-name: Generate Test Report for workflow ${{ github.event.workflow_run.name } on: workflow_run: - workflows: [ "CI" ] - types: - - completed + workflows: ["CI", "build"] + types: [completed] jobs: report: name: Test Report 🧪 - uses: DbUp/Universe/.github/workflows/test-report.yml@reusable \ No newline at end of file + uses: DbUp/Universe/.github/workflows/test-report.yml@reusable + secrets: inherit \ No newline at end of file From a373fb66b64046c885454dac766c03e0d644a62d Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 20 Mar 2024 11:49:05 +1000 Subject: [PATCH 08/16] put secrets: inherit on the right workflow --- .github/workflows/main.yml | 1 + .github/workflows/publish-release.yml | 1 + .github/workflows/test-report.yml | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3794b45..2d57497 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,6 +2,7 @@ name: CI on: push: + tags-ignore: * # Don't build when a tag is created pull_request: workflow_dispatch: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 1968a3f..96645fe 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,3 +9,4 @@ jobs: publish: name: Publish Package uses: DbUp/Universe/.github/workflows/publish-release.yml@reusable + secrets: inherit diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml index 8919267..9c395c2 100644 --- a/.github/workflows/test-report.yml +++ b/.github/workflows/test-report.yml @@ -9,5 +9,4 @@ on: jobs: report: name: Test Report 🧪 - uses: DbUp/Universe/.github/workflows/test-report.yml@reusable - secrets: inherit \ No newline at end of file + uses: DbUp/Universe/.github/workflows/test-report.yml@reusable \ No newline at end of file From d80cea826fb8c6546b5efd1879f41e7a5e933f83 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 20 Mar 2024 11:52:24 +1000 Subject: [PATCH 09/16] Update main.yml (#14) --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d57497..214ffd1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,8 @@ name: CI on: push: - tags-ignore: * # Don't build when a tag is created + branches: + - '**' # Ignores pushes of tags pull_request: workflow_dispatch: From d656742940f82d232fe1a21b0fe48f8ead1ce94b Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 20 Mar 2024 11:57:27 +1000 Subject: [PATCH 10/16] Used the workflows from main --- .github/workflows/main.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/test-report.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 214ffd1..26798d9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,4 +10,4 @@ on: jobs: build: name: Build - uses: DbUp/Universe/.github/workflows/build.yml@reusable + uses: DbUp/Universe/.github/workflows/build.yml@main diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 96645fe..eb5e03f 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -8,5 +8,5 @@ on: jobs: publish: name: Publish Package - uses: DbUp/Universe/.github/workflows/publish-release.yml@reusable + uses: DbUp/Universe/.github/workflows/publish-release.yml@main secrets: inherit diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml index 9c395c2..33fdc60 100644 --- a/.github/workflows/test-report.yml +++ b/.github/workflows/test-report.yml @@ -9,4 +9,4 @@ on: jobs: report: name: Test Report 🧪 - uses: DbUp/Universe/.github/workflows/test-report.yml@reusable \ No newline at end of file + uses: DbUp/Universe/.github/workflows/test-report.yml@main \ No newline at end of file From bd3577452f58a823021eb8a65c6fb7cdf0a7b61e Mon Sep 17 00:00:00 2001 From: Shawn Sesna Date: Fri, 19 Jul 2024 18:42:51 -0700 Subject: [PATCH 11/16] Use `MySqlConnector` instead of `System.Data.SqlClient` (#9) * Converting to mysqlconnector * Update dbup-mysql.csproj * Referenced MySqlConnector --------- Co-authored-by: Mark Harrison Co-authored-by: Robert Wagner Co-authored-by: Robert Wagner --- src/dbup-mysql/MySqlConnectionManager.cs | 3 ++- src/dbup-mysql/MySqlExtensions.cs | 2 +- src/dbup-mysql/MySqlScriptExecutor.cs | 4 ++-- src/dbup-mysql/dbup-mysql.csproj | 5 ++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dbup-mysql/MySqlConnectionManager.cs b/src/dbup-mysql/MySqlConnectionManager.cs index dde8b6d..5f25c63 100644 --- a/src/dbup-mysql/MySqlConnectionManager.cs +++ b/src/dbup-mysql/MySqlConnectionManager.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using DbUp.Engine.Transactions; -using MySql.Data.MySqlClient; +using MySqlConnector; + namespace DbUp.MySql { diff --git a/src/dbup-mysql/MySqlExtensions.cs b/src/dbup-mysql/MySqlExtensions.cs index 7f32379..bd4f887 100644 --- a/src/dbup-mysql/MySqlExtensions.cs +++ b/src/dbup-mysql/MySqlExtensions.cs @@ -6,7 +6,7 @@ using DbUp.Engine.Output; using DbUp.Engine.Transactions; using DbUp.MySql; -using MySql.Data.MySqlClient; +using MySqlConnector; /// /// Configuration extension methods for MySql. diff --git a/src/dbup-mysql/MySqlScriptExecutor.cs b/src/dbup-mysql/MySqlScriptExecutor.cs index 70324de..8fff2f5 100644 --- a/src/dbup-mysql/MySqlScriptExecutor.cs +++ b/src/dbup-mysql/MySqlScriptExecutor.cs @@ -4,7 +4,7 @@ using DbUp.Engine.Output; using DbUp.Engine.Transactions; using DbUp.Support; -using MySql.Data.MySqlClient; +using MySqlConnector; namespace DbUp.MySql { @@ -41,7 +41,7 @@ protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScri } catch (MySqlException exception) { - var code = exception.Code; + var code = exception.ErrorCode; Log().LogInformation("MySql exception has occurred in script: '{0}'", script.Name); Log().LogError("Script block number: {0}; MySql error code: {1}; Number {2}; Message: {3}", index, code, exception.Number, exception.Message); Log().LogError(exception.ToString()); diff --git a/src/dbup-mysql/dbup-mysql.csproj b/src/dbup-mysql/dbup-mysql.csproj index ce3df24..7815340 100644 --- a/src/dbup-mysql/dbup-mysql.csproj +++ b/src/dbup-mysql/dbup-mysql.csproj @@ -21,11 +21,10 @@ true embedded - + - - + From 49da633220927a68645dff411d80021f3bf50261 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Sat, 20 Jul 2024 11:46:06 +1000 Subject: [PATCH 12/16] Updated name of the test report workflow --- .github/workflows/test-report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml index 33fdc60..e8c9f8f 100644 --- a/.github/workflows/test-report.yml +++ b/.github/workflows/test-report.yml @@ -1,5 +1,5 @@ name: Test Report -run-name: Generate Test Report for workflow ${{ github.event.workflow_run.name }} run ${{ github.event.workflow_run.run_number }} branch ${{ github.event.workflow_run.head_branch }} +run-name: Generate Test Report for run `${{ github.event.workflow_run.run_number }}` branch `${{ github.event.workflow_run.head_branch }}` on: workflow_run: From 8f078caac39c468e2881a182c24a7cac96ca61db Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Wed, 24 Jul 2024 15:34:13 +1000 Subject: [PATCH 13/16] Implicit usings for tests. Replaced a string.format --- src/Tests/Tests.csproj | 2 +- src/dbup-mysql/MySqlExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 555645c..17f6477 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -4,7 +4,7 @@ net8 Tests DbUp.MySql.Tests - + enable enable diff --git a/src/dbup-mysql/MySqlExtensions.cs b/src/dbup-mysql/MySqlExtensions.cs index bd4f887..ea0cdda 100644 --- a/src/dbup-mysql/MySqlExtensions.cs +++ b/src/dbup-mysql/MySqlExtensions.cs @@ -173,7 +173,7 @@ public static void MySqlDatabase( if (DatabaseExists(connection, databaseName)) return; - var collationString = string.IsNullOrEmpty(collation) ? "" : string.Format(@" COLLATE {0}", collation); + var collationString = string.IsNullOrEmpty(collation) ? "" : $@" COLLATE {collation}"; var sqlCommandText = string.Format ( @"create database {0}{1};", From 00a608219447940cdb673fc2d8c34c74a3269b36 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 26 Jul 2024 09:22:19 +1000 Subject: [PATCH 14/16] Bump to the next beta of dbup-core --- src/Tests/Tests.csproj | 2 +- src/dbup-mysql/dbup-mysql.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 17f6477..daaa7d6 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/dbup-mysql/dbup-mysql.csproj b/src/dbup-mysql/dbup-mysql.csproj index 7815340..d5debee 100644 --- a/src/dbup-mysql/dbup-mysql.csproj +++ b/src/dbup-mysql/dbup-mysql.csproj @@ -23,7 +23,7 @@ - + From 1250c8cefb1e37ab54ab1cfd20b65ae557a7578f Mon Sep 17 00:00:00 2001 From: Paul Keller Date: Tue, 22 Oct 2024 13:50:45 +0200 Subject: [PATCH 15/16] Add support for DropDatabase (#17) --- .../NoPublicApiChanges.Run.approved.cs | 3 + src/dbup-mysql.sln.DotSettings | 3 + src/dbup-mysql/MySqlExtensions.cs | 63 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs index c129d52..7ff1159 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs @@ -10,9 +10,12 @@ public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(this DbUp.Builder. public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema) { } public static DbUp.Builder.UpgradeEngineBuilder MySqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { } public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString) { } + public static void MySqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString) { } public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout) { } public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, string collation) { } + public static void MySqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, int commandTimeout) { } public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { } + public static void MySqlDatabase(this DbUp.SupportedDatabasesForDropDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1) { } public static void MySqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, string collation = null) { } } namespace DbUp.MySql diff --git a/src/dbup-mysql.sln.DotSettings b/src/dbup-mysql.sln.DotSettings index 2c78c0a..d3334fb 100644 --- a/src/dbup-mysql.sln.DotSettings +++ b/src/dbup-mysql.sln.DotSettings @@ -5,5 +5,8 @@ SQ <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy><Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> + True <data><IncludeFilters /><ExcludeFilters /></data> <data /> \ No newline at end of file diff --git a/src/dbup-mysql/MySqlExtensions.cs b/src/dbup-mysql/MySqlExtensions.cs index ea0cdda..322980d 100644 --- a/src/dbup-mysql/MySqlExtensions.cs +++ b/src/dbup-mysql/MySqlExtensions.cs @@ -199,6 +199,69 @@ public static void MySqlDatabase( } } + /// + /// Drop the database specified in the connection string. + /// + /// Fluent helper type. + /// The connection string. + public static void MySqlDatabase( + this SupportedDatabasesForDropDatabase supported, + string connectionString) + { + MySqlDatabase(supported, connectionString, new ConsoleUpgradeLog()); + } + + /// + /// Drop the database specified in the connection string. + /// + /// Fluent helper type. + /// The connection string. + /// Use this to set the command time out for dropping a database in case you're encountering a time out in this operation. + public static void MySqlDatabase( + this SupportedDatabasesForDropDatabase supported, + string connectionString, + int commandTimeout) + { + MySqlDatabase(supported, connectionString, new ConsoleUpgradeLog(), commandTimeout); + } + + /// + /// Drop the database specified in the connection string. + /// + /// Fluent helper type. + /// The connection string. + /// The used to record actions. + /// Use this to set the command time out for dropping a database in case you're encountering a time out in this operation. + public static void MySqlDatabase( + this SupportedDatabasesForDropDatabase supported, + string connectionString, + IUpgradeLog logger, + int timeout = -1) + { + GetMysqlConnectionStringBuilder(connectionString, logger, out var masterConnectionString, out var databaseName); + using (var connection = new MySqlConnection(masterConnectionString)) + { + connection.Open(); + if (!DatabaseExists(connection, databaseName)) + return; + var dropDatabaseCommand = new MySqlCommand($"DROP DATABASE @databaseName;", connection) + { + CommandType = CommandType.Text + }; + dropDatabaseCommand.Parameters.AddWithValue("@databaseName", databaseName); + using (var command = dropDatabaseCommand) + { + if (timeout >= 0) + { + command.CommandTimeout = timeout; + } + + command.ExecuteNonQuery(); + } + logger.LogInformation("Dropped database {0}", databaseName); + } + } + static bool DatabaseExists(MySqlConnection connection, string databaseName) { var sqlCommandText = string.Format From d1ae14b3ada4361dab6ad60cf308f5c1a2adfc02 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 22 Oct 2024 21:53:25 +1000 Subject: [PATCH 16/16] Update to release version of dbup-core 6.0 --- src/dbup-mysql/dbup-mysql.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dbup-mysql/dbup-mysql.csproj b/src/dbup-mysql/dbup-mysql.csproj index d5debee..b01aa1e 100644 --- a/src/dbup-mysql/dbup-mysql.csproj +++ b/src/dbup-mysql/dbup-mysql.csproj @@ -23,7 +23,7 @@ - +