8000 Add support for PostgreSQL by danbarua · Pull Request #2 · SQLStreamStore/SQLStreamStore · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
647bf80
First stab at Postgres implementation
danbarua Jun 19, 2015
a9208b4
Add SharedAssemblyInfo.cs
danbarua Jun 19, 2015
a8e7b44
Compact json stub data
danbarua Jun 19, 2015
c80de7a
Fix syntax for delete with expected version
danbarua Jun 19, 2015
7c2686f
Move logic to sprocs, where possible - read_all_forwards/backwards se…
danbarua Jun 19, 2015
aca368f
Fix release build
danbarua Jun 19, 2015
fdef276
Merge remote-tracking branch 'origin/append-other-scenarios' into pgsql
danbarua Jun 22, 2015
5fd46f6
Fix build errors after merge
danbarua Jun 22, 2015
625e586
Use correct ordering when getting stream head
danbarua Jun 22, 2015
6235b70
Fix merge
danbarua Jun 22, 2015
1fe4a47
Use json compatible stub data
danbarua Jun 22, 2015
d6d344d
Make new pgsql tests pass
danbarua Jun 22, 2015
8305a18
add .ncrunchproject files
danbarua Jun 22, 2015
b0e587a
Add nuget.config to see if we can pull in npgsql from myget
danbarua Jun 22, 2015
15cc2bb
Change PostgresEventStore ctor to take a connection string or connect…
danbarua Jul 16, 2015
3af1d81
Correct ordering for GetStream.sql
danbarua Jul 17, 2015
6550a81
Include ordinal in ix_events_stream_id_internal_revision
danbarua Jul 17, 2015
747973d
Optimization: When expected version passed in, filter for events > ex…
danbarua Jul 17, 2015
c491bc3
Optimize get_stream, subquery uses index more efficiently than join +…
danbarua Jul 20, 2015
be47314
Test coverage for non-existent stream read scenarios
danbarua Jul 21, 2015
9c3df31
Add failing test and implemenation in Postgres for end-of-stream chec…
danbarua Jul 28, 2015
2e4a5dc
Fixup test for reading past end of stream - GES may hand back an empt…
danbarua Jul 28, 2015
6d41c4e
Add counter to short circuit run-away implementations
danbarua Jul 28, 2015
7166738
Merge master
danbarua Jul 28, 2015
99f17d4
Make data + metadata proper JSON for postgres
danbarua Jul 28, 2015
872d37f
Merge remote-tracking branch 'upstream/master' into pgsql
danbarua Jul 28, 2015
241f238
Handle serializable transaction rollbacks as WrongExpectedVersionExce…
danbarua Aug 3, 2015
3c77b39
Create stream where not exists with ExpectedVersion.Any
danbarua Sep 4, 2015
35bc4db
Move tx.Commit() inside try block as exceptions are thrown at this point
danbarua Sep 8, 2015
9f271e6
Add support for buckets/schemas
danbarua Sep 14, 2015
1f81789
Fixup tx serialization error handling - tx cannot be rolled back as i…
danbarua Oct 8, 2015
374162f
Add concurrent load test
danbarua Oct 8, 2015
2854035
Remove errant writer.close()
danbarua Oct 8, 2015
f1a958a
Move tx.commit() outside using() binaryImport block
danbarua Oct 8, 2015
176fb9f
Add try/catch for concurrency when creating a stream
danbarua Nov 9, 2015
c1f9e65
include concurrency tests
danbarua Nov 9, 2015
e4649cc
Fix #3 Use Npgsql 3.0.3 stable
danbarua Nov 9, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions default.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ task RunTests -depends Compile {
Run-Tests "Cedar.EventStore.GetEventStore.Tests"
Run-Tests "Cedar.EventStore.MsSql2008.Tests"
Run-Tests "Cedar.EventStore.Sqlite.Tests"
Run-Tests "Cedar.EventStore.Postgres.Tests"
}

task ILMerge -depends Compile {
Expand All @@ -69,6 +70,12 @@ task ILMerge -depends Compile {
$inputDlls = "$dllDir\$mainDllName.dll"
@( "EnsureThat" ) |% { $inputDlls = "$inputDlls $dllDir\$_.dll" }
Invoke-Expression "$ilmergePath /targetplatform:v4 /internalize /allowDup /target:library /log /out:$mergedDir\$mainDllName.dll $inputDlls"

$mainDllName = "Cedar.EventStore.Postgres"
$dllDir = "$srcDir\$mainDllName\bin\Release"
$inputDlls = "$dllDir\$mainDllName.dll"
@( "EnsureThat", "Npgsql" ) |% { $inputDlls = "$inputDlls $dllDir\$_.dll" }
Invoke-Expression "$ilmergePath /targetplatform:v4 /internalize /allowDup /target:library /log /out:$mergedDir\$mainDllName.dll $inputDlls"
}

task CreateNuGetPackages -depends ILMerge {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{453FB5DB-99DC-42D3-9DFE-F81EDF98F5E3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cedar.EventStore.Postgres.Tests</RootNamespace>
<AssemblyName>Cedar.EventStore.Postgres.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=3.3.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.3.3.0\lib\net45\FluentAssertions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentAssertions.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.3.3.0\lib\net45\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Npgsql, Version=3.1.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\Npgsql.3.1.0-unstable0000\lib\net45\Npgsql.dll</HintPath>
<Private>True</Private>
</R 38D3 eference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ConcurrentLoadTests.cs" />
<Compile Include="PostgresEventStoreFixture.cs" />
<Compile Include="SecondarySchemaTests.cs" />
<Compile Include="PostgresEventStoreTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TaskExtensions.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cedar.EventStore.Postgres\Cedar.EventStore.Postgres.csproj">
<Project>{148C90E9-0EA1-482E-94A9-F178294EFAC2}</Project>
<Name>Cedar.EventStore.Postgres</Name>
</ProjectReference>
<ProjectReference Include="..\Cedar.EventStore.Tests\Cedar.EventStore.Tests.csproj">
<Project>{F3FB96CF-4A3D-448D-A25E-6BC66E370BF6}</Project>
<Name>Cedar.EventStore.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Cedar.EventStore\Cedar.EventStore.csproj">
<Project>{3553E8E7-2C2A-45D5-BCB1-9AC7E5A209B2}</Project>
<Name>Cedar.EventStore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Binary file not shown.
38 changes: 38 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/ConcurrentLoadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Cedar.EventStore.Postgres.Tests
{
using Exceptions;
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

public class ConcurrentLoadTests
{
public ConcurrentLoadTests(ITestOutputHelper testOutputHelper)
{ }

[Fact]
public async Task conccurrent_appends_might_throw_WrongExpectedVersionException_and_thats_ok()
{
var eventStore = new PostgresEventStore(@"Server=127.0.0.1;Port=5432;Database=cedar_tests;User Id=postgres;Password=postgres;");

await eventStore.DropAll(ignoreErrors: true);
await eventStore.InitializeStore();

using (eventStore)
{
for (var i = 0; i < 3; i++)
{
Parallel.For(0, 4, async (iteration) =>
{
var streamId = string.Concat("stream-", iteration);
38D3 await eventStore
.AppendToStream(streamId, ExpectedVersion.Any, new NewStreamEvent(Guid.NewGuid(), "type", "\"data\"", "\"metadata\""))
.MightThrow<WrongExpectedVersionException>("Append failed due to WrongExpectedVersion. Stream: {0}, Expected version: -2".FormatWith(streamId));
});

}
}
}
}
}
28 changes: 28 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/PostgresEventStoreFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Cedar.EventStore.Postgres.Tests
{
using System.Threading.Tasks;

public class PostgresEventStoreFixture : EventStoreAcceptanceTestFixture
{
private readonly string _schema;
public PostgresEventStoreFixture(string schema = "public")
{
_schema = schema;
}

public override Task<IEventStore> GetEventStore()
{
return GetEventStore(_schema);
}

private async Task<IEventStore> GetEventStore(string schema)
{
var eventStore = new PostgresEventStore(@"Server=127.0.0.1;Port=5432;Database=cedar_tests;User Id=postgres;Password=postgres;", schema);

await eventStore.DropAll(ignoreErrors: true);
await eventStore.InitializeStore();

return eventStore;
}
}
}
18 changes: 18 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/PostgresEventStoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Cedar.EventStore.Postgres.Tests
{
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

public class PostgresEventStoreTests : EventStoreAcceptanceTests
{
public PostgresEventStoreTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{}

protected override EventStoreAcceptanceTestFixture GetFixture()
{
return new PostgresEventStoreFixture();
}
}
}
36 changes: 36 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribut 38D3 e values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cedar.EventStore.Postgres.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cedar.EventStore.Postgres.Tests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("dcf6bdff-8e51-46ae-9bcd-94a6ab78b26a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
30 changes: 30 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/SecondarySchemaTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Cedar.EventStore.Postgres.Tests
{
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

public class SecondarySchemaTests : EventStoreAcceptanceTests
{
public SecondarySchemaTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{}

protected override EventStoreAcceptanceTestFixture GetFixture()
{
return new PostgresEventStoreFixture("secondary_schema");
}

[Fact]
public async Task can_store_events_in_different_schemas()
{
using (var defaultStore = await GetFixture().GetEventStore())
using (var secondaryStore = await new PostgresEventStoreFixture("saga_events").GetEventStore())
{
const string streamId = "stream-1";
await defaultStore.AppendToStream(streamId, ExpectedVersion.NoStream, CreateNewStreamEvents(1, 2, 3));
await secondaryStore.AppendToStream(streamId, ExpectedVersion.NoStream, CreateNewStreamEvents(1, 2, 3));
}
}
}
}
26 changes: 26 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/TaskExtensions.cs
< 38D3 /tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Cedar.EventStore.Postgres.Tests
{
using FluentAssertions;
using System;
using System.Threading.Tasks;

internal static class TaskExtensions
{
internal static async Task MightThrow<T>(this Task task, string message)
{
try
{
await task;
}
catch (Exception ex)
{
ex.Should().BeOfType<T>();
ex.Message.Should().Be(message);

return;
}

//it didn't throw an exception, that's ok too
}
}
}
8 changes: 8 additions & 0 deletions src/Cedar.EventStore.Postgres.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FluentAssertions" version="3.3.0" targetFramework="net451" />
<package id="Npgsql" version="3.1.0-unstable0000" targetFramework="net451" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net451" />
<package id="xunit.core" version="2.0.0" targetFramework="net451" />
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net451" />
</packages>
Loading
0