Skip to content

Commit

Permalink
Merge branch 'release/9.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
AGiorgetti committed Dec 2, 2021
2 parents 53e6dd4 + fae5208 commit 6ac7e77
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 45 deletions.
10 changes: 8 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# NEventStore.Persistence.Sql

## 9.0.0

- Updated NEventStore core library to 9.0.0.
- Added support for net6.0.
- Added a new PostgreSQL dialect (`PostgreNpgsql6Dialect`) to deal with Npgsql version 6 timestamp breaking changes. If you update the driver you might need to update the table schema manually [#34](https://github.com/NEventStore/NEventStore.Persistence.SQL/issues/34).

## 8.0.0

- Updated NEventStore core library to 8.0.0
- Updated NEventStore core library to 8.0.0.
- Supports net5.0, net4.6.1.
- Schema initialization does not work with case insensitive database collations [#27](https://github.com/NEventStore/NEventStore.Persistence.SQL/issues/27)
- Use 32bit integer for the items column on the Commits table [#15](https://github.com/NEventStore/NEventStore.Persistence.SQL/pull/15)
- SqlPersistenceEngine, commit stamps are only saving with datetime precision, even though DB field is datetime2 [#1](https://github.com/NEventStore/NEventStore.Persistence.SQL/issues/1), [#399](https://github.com/NEventStore/NEventStore/issues/399)
- SqlPersistenceEngine, commit stamps are only saved with datetime precision, even though DB field is datetime2 [#1](https://github.com/NEventStore/NEventStore.Persistence.SQL/issues/1), [#399](https://github.com/NEventStore/NEventStore/issues/399)
- Added docker files to have test environments up and running in minutes.

### Breaking Changes
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NEventStore.Persistence.Sql currently supports:
- .net framework 4.6.1
- .net standard 2.0
- .net 5.0
- .net 6.0
- MsSql
- SqlLite
- MySql
Expand All @@ -22,6 +23,19 @@ Branches:
- master [![Build status](https://ci.appveyor.com/api/projects/status/5difan7hap8vwhwe/branch/master?svg=true)](https://ci.appveyor.com/project/AGiorgetti/neventstore-persistence-sql/branch/master)
- develop [![Build status](https://ci.appveyor.com/api/projects/status/5difan7hap8vwhwe/branch/develop?svg=true)](https://ci.appveyor.com/project/AGiorgetti/neventstore-persistence-sql/branch/develop)

## PostgreSQL Warning

If you upgrade Npgsql to version 6.0 and up you must take into account the breaking changes
made about the timezones handling [Timestamp rationalization and improvements](https://www.npgsql.org/efcore/release-notes/6.0.html#timestamp-rationalization-and-improvements).

Possible solutions:
- manually migrate the Table schema and update the "CommitStamp" column type from "timestamp" to "timestamptz".
- disable the new behavior by calling:
```
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
```
- use the new `PostgreNpgsql6Dialect`.

## How to Build (locally)

- Clone the repository with:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 1.0.{build}
image: Visual Studio 2019 Preview
image: Visual Studio 2022
configuration: Release
init:
- cmd: ''
Expand Down
2 changes: 1 addition & 1 deletion dependencies/NEventStore
Submodule NEventStore updated 47 files
+6 −0 Changelog.md
+2 −2 appveyor.yml
+2 −1 readme.markdown
+0 −27 src/NEventStore.Benchmark/Benchmarks/Md5VsSha256.cs
+6 −5 src/NEventStore.Benchmark/Benchmarks/PersistenceBenchmarks.cs
+2 −2 src/NEventStore.Benchmark/NEventStore.Benchmark.csproj
+4 −4 src/NEventStore.Example/NEventStore.Example.csproj
+5 −5 src/NEventStore.Persistence.AcceptanceTests/ExtensionMethods.cs
+4 −4 src/NEventStore.Persistence.AcceptanceTests/NEventStore.Persistence.AcceptanceTests.Core.csproj
+9 −14 src/NEventStore.Persistence.AcceptanceTests/PersistenceTests.cs
+1 −1 src/NEventStore.PollingClient/NEventStore.PollingClient.csproj
+4 −4 src/NEventStore.PollingClientExample/NEventStore.PollingClientExample.csproj
+6 −6 src/NEventStore.Serialization.Binary.Tests/NEventStore.Serialization.Binary.Core.Tests.csproj
+4 −2 src/NEventStore.Serialization.Binary.Tests/SerializerFixture.cs
+6 −6 src/NEventStore.Serialization.Bson.Tests/NEventStore.Serialization.Bson.Core.Tests.csproj
+1 −1 src/NEventStore.Serialization.Bson/NEventStore.Serialization.Bson.Core.csproj
+6 −6 src/NEventStore.Serialization.Gzip.Tests/NEventStore.Serialization.GZip.Core.Tests.csproj
+2 −0 src/NEventStore.Serialization.Gzip.Tests/SerializerFixture.cs
+6 −6 src/NEventStore.Serialization.Json.Tests/NEventStore.Serialization.Json.Core.Tests.csproj
+1 −1 src/NEventStore.Serialization.Json.Tests/SerializerFixture.cs
+19 −3 src/NEventStore.Serialization.Json/JsonSerializationWireupExtension.cs
+28 −14 src/NEventStore.Serialization.Json/JsonSerializer.cs
+1 −1 src/NEventStore.Serialization.Json/NEventStore.Serialization.Json.Core.csproj
+6 −6 src/NEventStore.Serialization.Rijndael.Tests/NEventStore.Serialization.Rijndael.Core.Tests.csproj
+4 −2 src/NEventStore.Serialization.Rijndael.Tests/SerializerFixture.cs
+10 −10 src/NEventStore.Tests/NEventStore.Core.Tests.csproj
+1 −1 src/NEventStore.Tests/OptimisticEventStoreTests.cs
+1 −1 src/NEventStore.Tests/OptimisticEventStreamTests.cs
+1 −1 src/NEventStore.Tests/OptimisticPipelineHookTests.cs
+7 −7 src/NEventStore.Tests/Persistence/InMemory/InMemoryPersistenceTests.cs
+1 −1 src/NEventStore.Tests/PipelineHooksAwarePersistanceDecoratorTests.cs
+126 −128 src/NEventStore/CommitAttempt.cs
+0 −22 src/NEventStore/CommitAttemptExtensions.cs
+1 −1 src/NEventStore/Conversion/EventUpconverterPipelineHook.cs
+1 −9 src/NEventStore/Helpers/DisposableAction.cs
+1 −1 src/NEventStore/ICommit.cs
+1 −1 src/NEventStore/IEventStream.cs
+2 −2 src/NEventStore/NEventStore.Core.csproj
+1 −1 src/NEventStore/OptimisticEventStore.cs
+2 −2 src/NEventStore/OptimisticEventStream.cs
+228 −228 src/NEventStore/OptimisticPipelineHook.cs
+55 −94 src/NEventStore/Persistence/Commit.cs
+2 −2 src/NEventStore/Persistence/IPersistStreams.cs
+1 −1 src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs
+75 −76 src/NEventStore/Persistence/StreamHead.cs
+5 −0 src/NEventStore/Serialization/BinarySerializer.cs
+2 −0 src/NEventStore/SerializationWireupExtensions.cs
12 changes: 6 additions & 6 deletions docker/DockerComposeDown.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ if ($platform -eq "linux") {
# workaround is to kill the containers manually

#Write-Host "LCOW stopping bug, hack: killing the containers (https://github.com/moby/moby/issues/37919)."
#docker kill -s 9 nesci_sqlexpress_1
#docker kill -s 9 nesci_mongo_1
#docker kill -s 9 nesci_mysql_1
#docker kill -s 9 nesci_postgres_1
#docker kill -s 9 nesci-sqlexpress-1
#docker kill -s 9 nesci-mongo-1
#docker kill -s 9 nesci-mysql-1
#docker kill -s 9 nesci-postgres-1
}
# -v "removes all the volumes, there's no need to do it manually"
docker-compose -f docker-compose.ci.$platform.db.yml -p nesci down -v

# remove unneeded volumes, so we start clear every time
#Write-Host "Removing volumes:"
#docker volume rm nesci_h8_sqldata_${platform}_ci
#docker volume rm nesci_h8_mongodata_${platform}_ci
#docker volume rm nesci-h8-sqldata-${platform}_ci
#docker volume rm nesci-h8_mongodata-${platform}_ci
4 changes: 2 additions & 2 deletions docker/DockerComposeUp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Write-Host "Creating Databases"
Start-Sleep -Seconds 20

if ($platform -eq "linux") {
docker exec nesci_sqlexpress_1 /opt/mssql-tools/bin/sqlcmd -l 60 -S localhost -U sa -P Password1 -Q "CREATE DATABASE NEventStore"
docker exec nesci-sqlexpress-1 /opt/mssql-tools/bin/sqlcmd -l 60 -S localhost -U sa -P Password1 -Q "CREATE DATABASE NEventStore"
}

if ($platform -eq "windows") {
docker exec nesci_sqlexpress_1 sqlcmd -l 60 -S localhost -U sa -P Password1 -Q "CREATE DATABASE NEventStore"
docker exec nesci-sqlexpress-1 sqlcmd -l 60 -S localhost -U sa -P Password1 -Q "CREATE DATABASE NEventStore"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net461;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>NEventStore.Persistence.MsSql.Tests</AssemblyName>
Expand All @@ -14,16 +14,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net461;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>NEventStore.Persistence.MySql.Tests</AssemblyName>
Expand All @@ -14,17 +14,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MySql.Data" Version="8.0.22" />
<PackageReference Include="MySql.Data" Version="8.0.27" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Data" />
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NEventStore.Persistence.MySql.Tests/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.27.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net461;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>NEventStore.Persistence.PostgreSql.Tests</AssemblyName>
Expand All @@ -17,11 +17,11 @@
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="4.1.6" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Npgsql" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ namespace NEventStore.Persistence.AcceptanceTests
using NEventStore.Persistence.Sql;
using NEventStore.Persistence.Sql.SqlDialects;
using NEventStore.Serialization;
using System;

public partial class PersistenceEngineFixture
{
public PersistenceEngineFixture()
{
// It will be done when creating the PostgreNpgsql6Dialect dialect
// AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

#if NET461
_createPersistence = pageSize =>
new SqlPersistenceFactory(
new EnviromentConnectionFactory("PostgreSql", "Npgsql"),
new BinarySerializer(),
new PostgreSqlDialect(),
new PostgreNpgsql6Dialect(npgsql6timestamp: true),
pageSize: pageSize).Build();
#else
_createPersistence = pageSize =>
new SqlPersistenceFactory(
new EnviromentConnectionFactory("PostgreSql", Npgsql.NpgsqlFactory.Instance),
new BinarySerializer(),
new PostgreSqlDialect(),
new PostgreNpgsql6Dialect(npgsql6timestamp: true),
pageSize: pageSize).Build();
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.0;net461</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>NEventStore.Persistence.Sql.Tests</AssemblyName>
<RootNamespace>NEventStore.Persistence.Sql.Tests</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netstandard2.0;net461</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>NEventStore.Persistence.Sql</RootNamespace>
<AssemblyName>NEventStore.Persistence.Sql</AssemblyName>
Expand All @@ -26,8 +26,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Configuration" />
Expand Down
58 changes: 58 additions & 0 deletions src/NEventStore.Persistence.Sql/SqlDialects/PostgreSqlDialect.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NEventStore.Persistence.Sql.SqlDialects
{
using System;
using System.Data;

public class PostgreSqlDialect : CommonSqlDialect
{
Expand All @@ -20,4 +21,61 @@ public override bool IsDuplicate(Exception exception)
return message.Contains("23505") || message.Contains("IX_COMMITS_COMMITSEQUENCE");
}
}

public class PostgreNpgsql6Dialect : CommonSqlDialect
{
private readonly bool _npgsql6Timestamp;

/// <summary>
/// Create an instance of the PostgreSQL dialect
/// </summary>
/// <param name="npgsql6timestamp">
/// There's a breaking change in Npgsql Version 6.x that changes the way timestamps should be persisted.
/// - false: to disable the new behavior for the whole application (see the driver release notes) this should be done before using the database.
/// - true: enable the new behavior, you might need to migrate the data manually (see Npgsql release notes).
/// </param>
public PostgreNpgsql6Dialect(
bool npgsql6timestamp = true
)
{
_npgsql6Timestamp = npgsql6timestamp;
if (!_npgsql6Timestamp)
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
}
}

public override string InitializeStorage
{
get
{
var initStorage = PostgreSqlStatements.InitializeStorage;
if (_npgsql6Timestamp)
{
initStorage = initStorage.Replace("timestamp", "timestamptz");
}
return initStorage;
}
}

public override string PersistCommit
{
get { return PostgreSqlStatements.PersistCommits; }
}

public override bool IsDuplicate(Exception exception)
{
string message = exception.Message.ToUpperInvariant();
return message.Contains("23505") || message.Contains("IX_COMMITS_COMMITSEQUENCE");
}

public override DbType GetDateTimeDbType()
{
if (_npgsql6Timestamp)
{
return DbType.DateTimeOffset;
}
return base.GetDateTimeDbType();
}
}
}
2 changes: 1 addition & 1 deletion src/NEventStore.Persistence.Sql/SqlPersistenceEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace NEventStore.Persistence.Sql
public class SqlPersistenceEngine : IPersistStreams
{
private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(SqlPersistenceEngine));
private static readonly DateTime EpochTime = new DateTime(1970, 1, 1);
private static readonly DateTime EpochTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private readonly IConnectionFactory _connectionFactory;
private readonly ISqlDialect _dialect;
private readonly int _pageSize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net461;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyName>NEventStore.Persistence.Sqlite.Tests</AssemblyName>
Expand All @@ -19,17 +19,17 @@
</ItemGroup>
-->
<ItemGroup>
<PackageReference Include="System.Data.SQLite" Version="1.0.113.6" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
<PackageReference Include="System.Data.SQLite" Version="1.0.115.5" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Transactions" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 6ac7e77

Please sign in to comment.