Skip to content

Commit

Permalink
Merge pull request #24 from drwatson1/net6
Browse files Browse the repository at this point in the history
Support of .Net 6
  • Loading branch information
drwatson1 authored May 10, 2022
2 parents 0f43942 + e34f718 commit 29b2a75
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The tool has almost all the features the DbUp has, but without a single line of

|Date|Version|Description|
|-|-|-|
|2022-05-10|1.6.6|Add support of .Net 6
|2022-02-14|1.6.5|Support of DisableVars
|2022-02-06|1.6.4|Support of drop and ensure for Azure SQL
|2022-02-02|1.6.3|Support of AzureSQL integrated sequrity
Expand Down
7 changes: 3 additions & 4 deletions src/dbup-cli.integration-tests/PostgreSqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public PostgreSqlTests()
Env = new CliEnvironment();
Logger = new CaptureLogsLogger();

Environment.SetEnvironmentVariable("CONNSTR", "Host=127.0.0.1;Database=dbup;Username=postgres;Password=PostgresPwd2019;Port=5432");
Environment.SetEnvironmentVariable("CONNSTR", "Host=127.0.0.1;Database=dbup;Username=postgres;Password=PostgresPwd2019;Port=5432;Timeout=60;CommandTimeout=60");
}

string GetBasePath(string subPath = "EmptyScript") =>
Path.Combine(Assembly.GetExecutingAssembly().Location, $@"..\Scripts\PostgreSql\{subPath}");

string GetConfigPath(string name = "dbup.yml", string subPath = "EmptyScript") => new DirectoryInfo(Path.Combine(GetBasePath(subPath), name)).FullName;

Func<DbConnection> CreateConnection = () => new NpgsqlConnection("Host=127.0.0.1;Database=postgres;Username=postgres;Password=PostgresPwd2019;Port=5432");
Func<DbConnection> CreateConnection = () => new NpgsqlConnection("Host=127.0.0.1;Database=postgres;Username=postgres;Password=PostgresPwd2019;Port=5432;Timeout=60;CommandTimeout=60");

[TestInitialize]
public Task TestInitialize()
Expand Down Expand Up @@ -115,7 +115,6 @@ public void UpgradeCommand_ShouldUseConnectionTimeoutForLongrunningQueries()
r.Should().Be(1);
}


[TestMethod]
public void UpgradeCommand_ShouldUseASpecifiedJournal()
{
Expand All @@ -125,7 +124,7 @@ public void UpgradeCommand_ShouldUseASpecifiedJournal()
result.Should().Be(0);

using (var connection = new NpgsqlConnection(Environment.GetEnvironmentVariable("CONNSTR")))
using (var command = new NpgsqlCommand("select count(*) from public.\"testTable\" where scriptname = '001.sql'", connection))
using (var command = new NpgsqlCommand("select count(*) from public.journal where scriptname = '001.sql'", connection))
{
connection.Open();
var count = command.ExecuteScalar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dbUp:
version: 1 # should be 1
provider: postgresql # DB provider: sqlserver
connectionString: $CONNSTR$ # Connection string to DB. For example, "Data Source=(localdb)\dbup;Initial Catalog=MyDb;Integrated Security=True" for sqlserver
connectionTimeoutSec: 60
journalTo:
schema: "public"
table: "testTable"
schema: public
table: journal
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT pg_sleep(60);
SELECT pg_sleep(60);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ dbUp:
version: 1 # should be 1
provider: postgresql # DB provider: sqlserver
connectionString: $CONNSTR$ # Connection string to DB. For example, "Data Source=(localdb)\dbup;Initial Catalog=MyDb;Integrated Security=True" for sqlserver
connectionTimeoutSec: 10 # Connection timeout in seconds
connectionTimeoutSec: 10 # Connection timeout in seconds
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>DbUp.Cli.IntegrationTests</RootNamespace>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<RootNamespace>DbUp.Cli.IntegrationTests</RootNamespace>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/dbup-cli.tests.core/dbup-cli.tests.core.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>DbUp.Cli.Tests</RootNamespace>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<RootNamespace>DbUp.Cli.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/dbup-cli.tests/dbup-cli.tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>DbUp.Cli.Tests</RootNamespace>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<RootNamespace>DbUp.Cli.Tests</RootNamespace>

<IsPackable>false</IsPackable>

Expand Down
4 changes: 2 additions & 2 deletions src/dbup-cli/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Option<bool, Error> EnsureDb(IUpgradeLog logger, Provider provider
}
catch (Exception ex)
{
return Option.None<bool, Error>(Error.Create(ex.Message));
return Option.None<bool, Error>(Error.Create("EnsureDb failed: {0}", ex.Message));
}

return Option.None<bool, Error>(Error.Create(Constants.ConsoleMessages.UnsupportedProvider, provider.ToString()));
Expand Down Expand Up @@ -110,7 +110,7 @@ public static Option<bool, Error> DropDb(IUpgradeLog logger, Provider provider,
}
catch (Exception ex)
{
return Option.None<bool, Error>(Error.Create(ex.Message));
return Option.None<bool, Error>(Error.Create("DropDb failed: {0}", ex.Message));
}

return Option.None<bool, Error>(Error.Create(Constants.ConsoleMessages.UnsupportedProvider, provider.ToString()));
Expand Down
41 changes: 41 additions & 0 deletions src/dbup-cli/ResultBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Optional;
using System;

namespace DbUp.Cli
{
internal class ResultBuilder
{
public Option<int, Error> FromUpgradeResult(Engine.DatabaseUpgradeResult result)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}

if (result.Successful)
{
return Option.Some<int, Error>(0);
}

var msg = "Failed to perform upgrade: ";
if (result.Error == null)
{
msg += "Undefined error";
}
else
{
msg += result.Error.Message;
if (result.Error.InnerException != null)
{
msg += $"{Environment.NewLine} Details: {result.Error.InnerException.Message}";
}
}
if (result.ErrorScript != null)
{
msg += $"{Environment.NewLine} Script: {result.ErrorScript.Name}";
}

return Option.None<int, Error>(Error.Create(msg));
}
}
}
12 changes: 1 addition & 11 deletions src/dbup-cli/ToolEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,9 @@ private Option<int, Error> RunUpgradeCommand(UpgradeOptions opts) =>
}
}

if (!engine.TryConnect(out var message))
{
return Option.None<int, Error>(Error.Create(message));
}

var result = engine.PerformUpgrade();

if (result.Successful)
{
return Option.Some<int, Error>(0);
}

return Option.None<int, Error>(Error.Create(result.Error.Message));
return new ResultBuilder().FromUpgradeResult(result);
},
none: error => Option.None<int, Error>(error)),
none: error => Option.None<int, Error>(error)),
Expand Down
11 changes: 8 additions & 3 deletions src/dbup-cli/dbup-cli.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Condition="'$(GlobalTool)' != false">
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
</PropertyGroup>

Expand All @@ -18,7 +18,7 @@
<LangVersion>latest</LangVersion>
<Product>DbUp Command Line Interface</Product>
<Authors>Sergey Tregub</Authors>
<Version>1.6.5</Version>
<Version>1.6.6</Version>
<RepositoryUrl>https://github.com/drwatson1/dbup-cli</RepositoryUrl>
<Company />
<Copyright>Copyright (c) 2022 Sergey Tregub</Copyright>
Expand All @@ -28,11 +28,12 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>dbup</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageReleaseNotes>Support of DisableVars</PackageReleaseNotes>
<PackageReleaseNotes>Add support of .Net 6</PackageReleaseNotes>
<Title>DbUp Command Line Interface</Title>
<Description>Command line tool, that can be installed as a .Net global tool, that helps you to deploy changes to databases. It tracks which SQL scripts have been run already, and runs the change scripts that are needed to get your database up to date.</Description>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -45,6 +46,10 @@
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Include="..\..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 29b2a75

Please sign in to comment.