Skip to content

Commit

Permalink
Merge pull request #55 from max-ieremenko/release/4.2.2
Browse files Browse the repository at this point in the history
release 4.2.2
  • Loading branch information
max-ieremenko committed Jun 13, 2024
2 parents 62ae3e3 + 89000db commit 49e4e05
Show file tree
Hide file tree
Showing 26 changed files with 145 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build.ps1 is designed to run on windows
- PowerShell Desktop 5.1
- PowerShell [7.3.0](https://github.com/PowerShell/PowerShell/releases/tag/v7.3.0) for .net 7.0 and 8.0 tests
- PowerShell [7.2.1](https://github.com/PowerShell/PowerShell/releases/tag/v7.2.1) for .net 6.0 tests
- Install-Module -Name [InvokeBuild](https://www.powershellgallery.com/packages/InvokeBuild/5.11.0) -RequiredVersion 5.11.0
- Install-Module -Name [InvokeBuild](https://www.powershellgallery.com/packages/InvokeBuild/5.11.1) -RequiredVersion 5.11.1
- Install-Module -Name [ThirdPartyLibraries](https://www.powershellgallery.com/packages/ThirdPartyLibraries/3.5.1) -RequiredVersion 3.5.1
- .net framework 4.7.2+ sdk
- .net 8.0 sdk
Expand Down
2 changes: 1 addition & 1 deletion Build/build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Requires -Version "7.0"
#Requires -Modules @{ ModuleName="InvokeBuild"; ModuleVersion="5.11.0" }
#Requires -Modules @{ ModuleName="InvokeBuild"; ModuleVersion="5.11.1" }
#Requires -Modules @{ ModuleName="ThirdPartyLibraries"; ModuleVersion="3.5.1" }

[CmdletBinding()]
Expand Down
4 changes: 2 additions & 2 deletions Build/scripts/Start-Pgsql.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function Start-Pgsql {
param ()

$npgsqldll = Join-Path $env:USERPROFILE ".nuget\packages\npgsql\4.0.11\lib\netstandard2.0\Npgsql.dll"
$npgsqldll = Join-Path $env:USERPROFILE ".nuget\packages\npgsql\4.0.16\lib\netstandard2.0\Npgsql.dll"
Add-Type -Path $npgsqldll

$container = Start-Container -Image sqldatabase/postgres:13.3 -ContainerPort 5432

$builder = New-Object -TypeName Npgsql.NpgsqlConnectionStringBuilder
$builder["Database"] = "sqldatabasetest"
$builder["Username"] = "postgres"
$builder["Username"] = "adminuser"
$builder["Password"] = "qwerty"
$builder["Timeout"] = 5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Npgsql</id>
<version>4.0.11</version>
<version>4.0.16</version>
<authors>Shay Rojansky,Yoh Deadfall,Austin Drenski,Emil Lenngren,Francisco Figueiredo Jr.,Kenji Uno</authors>
<owners>Shay Rojansky,Yoh Deadfall,Austin Drenski,Emil Lenngren,Francisco Figueiredo Jr.,Kenji Uno</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">PostgreSQL</license>
<licenseUrl>https://licenses.nuget.org/PostgreSQL</licenseUrl>
<projectUrl>http://www.npgsql.org/</projectUrl>
<description>Npgsql is the open source .NET data provider for PostgreSQL.</description>
<copyright>Copyright 2019 © The Npgsql Development Team</copyright>
<tags>npgsql postgresql postgres ado ado.net database sql</tags>
<repository type="git" url="git://github.com/npgsql/npgsql" />
<repository type="git" url="git://github.com/npgsql/npgsql" commit="86e9a120e7503ef9163a6e44cf51255ef8912633" />
<dependencies>
<group targetFramework=".NETFramework4.5">
<dependency id="System.Memory" version="4.5.3" exclude="Build,Analyzers" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Npgsql [4.0.11](https://www.nuget.org/packages/Npgsql/4.0.11)
Npgsql [4.0.16](https://www.nuget.org/packages/Npgsql/4.0.16)
--------------------

Used by: SqlDatabase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2002-2023, Npgsql
Copyright (c) 2002-2024, Npgsql

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose, without fee, and without a written agreement
Expand Down
2 changes: 1 addition & 1 deletion Build/third-party-libraries/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Packages 47
|[NETStandard.Library](packages/nuget.org/netstandard.library/2.0.3)|2.0.3|[nuget.org](https://www.nuget.org/packages/NETStandard.Library/2.0.3)|[MIT](licenses/mit)|SqlDatabase|
|[Newtonsoft.Json](packages/nuget.org/newtonsoft.json/13.0.1)|13.0.1|[nuget.org](https://www.nuget.org/packages/Newtonsoft.Json/13.0.1)|[MIT](licenses/mit)|SqlDatabase internal|
|[Newtonsoft.Json](packages/nuget.org/newtonsoft.json/13.0.3)|13.0.3|[nuget.org](https://www.nuget.org/packages/Newtonsoft.Json/13.0.3)|[MIT](licenses/mit)|SqlDatabase internal|
|[Npgsql](packages/nuget.org/npgsql/4.0.11)|4.0.11|[nuget.org](https://www.nuget.org/packages/Npgsql/4.0.11)|[PostgreSQL](licenses/postgresql)|SqlDatabase|
|[Npgsql](packages/nuget.org/npgsql/4.0.16)|4.0.16|[nuget.org](https://www.nuget.org/packages/Npgsql/4.0.16)|[PostgreSQL](licenses/postgresql)|SqlDatabase|
|[NUnit](packages/nuget.org/nunit/4.1.0)|4.1.0|[nuget.org](https://www.nuget.org/packages/NUnit/4.1.0)|[MIT](licenses/mit)|SqlDatabase internal|
|[NUnit3TestAdapter](packages/nuget.org/nunit3testadapter/4.5.0)|4.5.0|[nuget.org](https://www.nuget.org/packages/NUnit3TestAdapter/4.5.0)|[MIT](licenses/mit)|SqlDatabase internal|
|[PowerShellStandard.Library](packages/nuget.org/powershellstandard.library/5.1.1)|5.1.1|[nuget.org](https://www.nuget.org/packages/PowerShellStandard.Library/5.1.1)|[MIT](licenses/mit)|SqlDatabase|
Expand Down
2 changes: 1 addition & 1 deletion Examples/ExecuteScriptsFolder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Predefined variables
Opening a connection
========================

Before starting any step SqlDatabase checks if a database, provided in the connection string, exists. If database does not exists the connection will be targeted to `master` for MSSQL and `postgres` for PostgreSQL.
If the database specified in the connection string does not exist, execution will be terminated with the appropriate error.

MSSQL Server script example
=============================
Expand Down
2 changes: 1 addition & 1 deletion Examples/MigrationStepsFolder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Predefined variables
Opening a connection
========================
Before starting any step SqlDatabase checks if a database, provided in the connection string, exists. If database does not exists the connection will be targeted to `master` for MSSQL and `postgres` for PostgreSQL.
If the database specified in the connection string does not exist, execution will be terminated with the appropriate error.
Migration MSSQL Server .sql step example
=============================
Expand Down
2 changes: 1 addition & 1 deletion Sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<PropertyGroup>
<SqlDatabaseVersion>4.2.1</SqlDatabaseVersion>
<SqlDatabaseVersion>4.2.2</SqlDatabaseVersion>
<Version>$(SqlDatabaseVersion)</Version>
<AssemblyVersion>$(SqlDatabaseVersion).0</AssemblyVersion>
<FileVersion>$(SqlDatabaseVersion).0</FileVersion>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageVersion Include="MySqlConnector" Version="1.3.10" />
<PackageVersion Include="Npgsql" Version="4.0.11" />
<PackageVersion Include="Npgsql" Version="4.0.16" />

<PackageVersion Include="System.Data.SqlClient" Version="4.8.6" />
<PackageVersion Include="System.Runtime.Loader" Version="4.3.0" />
Expand Down
23 changes: 21 additions & 2 deletions Sources/Docker/pgsql.create-database.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
CREATE DATABASE sqldatabasetest;
CREATE ROLE adminuser WITH
LOGIN
NOSUPERUSER
INHERIT
CREATEDB
CREATEROLE
NOREPLICATION
PASSWORD 'qwerty';

SET ROLE adminuser;

CREATE DATABASE sqldatabasetest;

\connect sqldatabasetest;

SET ROLE adminuser;

CREATE EXTENSION citext;

CREATE TABLE public.version
Expand All @@ -10,6 +23,12 @@ CREATE TABLE public.version
,version varchar(20) NOT NULL
);

CREATE TABLE public.version2
(
module_name public.citext NOT NULL
,version varchar(20) NOT NULL
);

ALTER TABLE public.version
ADD CONSTRAINT pk_version PRIMARY KEY (module_name);

Expand All @@ -24,4 +43,4 @@ CREATE TYPE public.inventory_item AS (
name text,
supplier_id integer,
price numeric
);
);
2 changes: 1 addition & 1 deletion Sources/SqlDatabase.Adapter.PgSql.Test/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<configuration>
<connectionStrings>
<add name="pgsql"
connectionString="Host=localhost;Username=postgres;Password=qwerty;Database=sqldatabasetest;" />
connectionString="Host=localhost;Username=adminuser;Password=qwerty;Database=sqldatabasetest;" />
</connectionStrings>
</configuration>
6 changes: 3 additions & 3 deletions Sources/SqlDatabase.Adapter.PgSql/PgSqlDatabaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ internal sealed class PgSqlDatabaseAdapter : IDatabaseAdapter
Pooling = false
};

DatabaseName = builder.Database;
DatabaseName = builder.Database!;
_connectionString = builder.ToString();

builder.Database = null;
builder.Database = "postgres"; // The master will always be set to postgres database
_connectionStringMaster = builder.ToString();

_onConnectionNotice = OnConnectionNotice;
Expand Down Expand Up @@ -72,4 +72,4 @@ private void OnConnectionNotice(object sender, NpgsqlNoticeEventArgs e)
{
_log.Info($"{e.Notice.Severity}: {e.Notice.MessageText}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void BeforeEachTest()

_database = new Mock<IDatabase>(MockBehavior.Strict);
_database.SetupGet(d => d.Adapter).Returns(adapter.Object);
_database.Setup(d => d.GetServerVersion()).Returns("sql server 1.0");
_database.Setup(d => d.GetServerVersion(true)).Returns("sql server 1.0");

_scriptSequence = new Mock<ICreateScriptSequence>(MockBehavior.Strict);

Expand Down Expand Up @@ -80,8 +80,8 @@ public void ExecuteSequence()
.Setup(f => f.InitializeEnvironment(_log.Object, sequence));

_database
.Setup(d => d.Execute(step1.Object))
.Callback(() => _database.Setup(d => d.Execute(step2.Object)));
.Setup(d => d.ExecuteWithDatabaseCheck(step1.Object))
.Callback(() => _database.Setup(d => d.ExecuteWithDatabaseCheck(step2.Object)));

_scriptSequence
.Setup(s => s.BuildSequence())
Expand Down Expand Up @@ -109,7 +109,7 @@ public void StopExecutionOnError()
.Setup(f => f.InitializeEnvironment(_log.Object, sequence));

_database
.Setup(d => d.Execute(step1.Object))
.Setup(d => d.ExecuteWithDatabaseCheck(step1.Object))
.Throws<InvalidOperationException>();

_scriptSequence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void BeforeEachTest()

_database = new Mock<IDatabase>(MockBehavior.Strict);
_database.SetupGet(d => d.Adapter).Returns(adapter.Object);
_database.Setup(d => d.GetServerVersion()).Returns("sql server 1.0");
_database.Setup(d => d.GetServerVersion(false)).Returns("sql server 1.0");

_scriptSequence = new Mock<ICreateScriptSequence>(MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void BeforeEachTest()

_database = new Mock<IDatabase>(MockBehavior.Strict);
_database.SetupGet(d => d.Adapter).Returns(adapter.Object);
_database.Setup(d => d.GetServerVersion()).Returns("sql server 1.0");
_database.Setup(d => d.GetServerVersion(false)).Returns("sql server 1.0");

_scriptSequence = new Mock<ICreateScriptSequence>(MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void BeforeEachTest()

_database = new Mock<IDatabase>(MockBehavior.Strict);
_database.SetupGet(d => d.Adapter).Returns(adapter.Object);
_database.Setup(d => d.GetServerVersion()).Returns("sql server 1.0");
_database.Setup(d => d.GetServerVersion(false)).Returns("sql server 1.0");

_scriptSequence = new Mock<IUpgradeScriptSequence>(MockBehavior.Strict);

Expand Down
63 changes: 58 additions & 5 deletions Sources/SqlDatabase.Test/Scripts/DatabaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ public void GetCurrentVersionModuleNameInvalidVersion()
}

[Test]
public void GetServerVersion()
[TestCase(true)]
[TestCase(false)]
public void GetServerVersion(bool useMasterDatabase)
{
_adapter
.Setup(a => a.GetServerVersionSelectScript())
.Returns("select server version");
_adapter
.Setup(a => a.CreateConnection(true))
.Setup(a => a.CreateConnection(useMasterDatabase))
.Returns(_connection.Object);

_command
Expand All @@ -208,7 +210,7 @@ public void GetServerVersion()
})
.Returns("server version");

var actual = _sut.GetServerVersion();
var actual = _sut.GetServerVersion(useMasterDatabase);

actual.ShouldBe("server version");
}
Expand Down Expand Up @@ -315,6 +317,57 @@ public void Execute(TransactionMode transaction)
{
_sut.Transaction = transaction;

_command
.SetupProperty(c => c.CommandTimeout, 30);
_command
.SetupProperty(c => c.Transaction);

_connection
.Setup(c => c.BeginTransaction(IsolationLevel.ReadCommitted))
.Returns(_transaction.Object);

_adapter
.SetupGet(a => a.DatabaseName)
.Returns("database-name");
_adapter
.Setup(a => a.CreateConnection(false))
.Returns(_connection.Object);

var script = new Mock<IScript>(MockBehavior.Strict);
script
.Setup(s => s.Execute(_command.Object, It.IsNotNull<IVariables>(), It.IsNotNull<ILogger>()))
.Callback<IDbCommand, IVariables, ILogger>((cmd, variables, s) =>
{
cmd.CommandTimeout.ShouldBe(0);
if (transaction == TransactionMode.PerStep)
{
cmd.Transaction.ShouldBe(_transaction.Object);
}
else
{
cmd.Transaction.ShouldBeNull();
}
variables.GetValue("DatabaseName").ShouldBe("database-name");
variables.GetValue("CurrentVersion").ShouldBeNullOrEmpty();
variables.GetValue("TargetVersion").ShouldBeNullOrEmpty();
variables.GetValue("ModuleName").ShouldBeNullOrEmpty();
});

_sut.Execute(script.Object);

script.VerifyAll();
_command.VerifyAll();
}

[Test]
[TestCase(TransactionMode.None)]
[TestCase(TransactionMode.PerStep)]
public void ExecuteWithDatabaseCheck(TransactionMode transaction)
{
_sut.Transaction = transaction;

_command
.SetupProperty(c => c.CommandTimeout, 30);
_command
Expand Down Expand Up @@ -364,7 +417,7 @@ public void Execute(TransactionMode transaction)
variables.GetValue("ModuleName").ShouldBeNullOrEmpty();
});

_sut.Execute(script.Object);
_sut.ExecuteWithDatabaseCheck(script.Object);

script.VerifyAll();
_command.VerifyAll();
Expand Down Expand Up @@ -402,7 +455,7 @@ public void ExecuteDatabaseNotFound()
cmd.Transaction.ShouldBeNull();
});

_sut.Execute(script.Object);
_sut.ExecuteWithDatabaseCheck(script.Object);

script.VerifyAll();
_command.VerifyAll();
Expand Down
4 changes: 3 additions & 1 deletion Sources/SqlDatabase/Commands/DatabaseCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ protected DatabaseCommandBase(IDatabase database, ILogger log)
public void Execute()
{
Greet(Database.Adapter.GetUserFriendlyConnectionString());
Log.Info(Database.GetServerVersion());
Log.Info(GetServerVersion());

ExecuteCore();
}

protected abstract void Greet(string databaseLocation);

protected abstract void ExecuteCore();

protected virtual string GetServerVersion() => Database.GetServerVersion(false);
}
4 changes: 3 additions & 1 deletion Sources/SqlDatabase/Commands/DatabaseCreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protected override void Greet(string databaseLocation)
Log.Info($"Create {databaseLocation}");
}

protected override string GetServerVersion() => Database.GetServerVersion(true);

protected override void ExecuteCore()
{
var sequences = ScriptSequence.BuildSequence();
Expand All @@ -44,7 +46,7 @@ protected override void ExecuteCore()

using (Log.Indent())
{
Database.Execute(script);
Database.ExecuteWithDatabaseCheck(script);
}

Log.Info($"done in {timer.Elapsed}");
Expand Down
Loading

0 comments on commit 49e4e05

Please sign in to comment.