Skip to content

Commit

Permalink
add projection implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
pgallik committed Jan 10, 2024
1 parent 5ed169a commit a26346b
Show file tree
Hide file tree
Showing 20 changed files with 1,041 additions and 195 deletions.
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nuget Destructurama.JsonNet 2.0.0

nuget Microsoft.EntityFrameworkCore.Design 6.0.3

nuget Npgsql 6.0.3
nuget Npgsql.EntityFrameworkCore.PostgreSQL 6.0.3
nuget Npgsql.EntityFrameworkCore.PostgreSQL.Design 2.0.0-preview1

Expand Down
19 changes: 16 additions & 3 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ NUGET
System.IO.Pipelines (>= 6.0.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.Bcl.AsyncInterfaces (7.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (== net472) (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1))
Microsoft.Bcl.HashCode (1.1.1) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
Microsoft.Build (17.1)
Microsoft.Build.Framework (>= 17.1)
Microsoft.IO.Redist (>= 6.0) - restriction: || (== net472) (&& (== net6.0) (>= net472))
Expand Down Expand Up @@ -1060,9 +1061,17 @@ NUGET
NodaTime.Serialization.JsonNet (3.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Newtonsoft.Json (>= 12.0.1)
NodaTime (>= 3.0 < 4.0)
Npgsql (7.0.6)
Microsoft.Extensions.Logging.Abstractions (>= 6.0)
Npgsql (6.0.3)
Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
Microsoft.Bcl.HashCode (>= 1.1.1) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
System.Collections.Immutable (>= 6.0) - restriction: || (== net472) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0) (< netstandard2.1))
System.Diagnostics.DiagnosticSource (>= 6.0) - restriction: || (== net472) (&& (== net6.0) (< net5.0)) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0) (< netstandard2.1))
System.Memory (>= 4.5.4) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Text.Json (>= 6.0) - restriction: || (== net472) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0) (< netstandard2.1))
System.Threading.Channels (>= 6.0) - restriction: || (== net472) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0) (< netstandard2.1))
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
System.ValueTuple (>= 4.5) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
Npgsql.EntityFrameworkCore.PostgreSQL (6.0.3)
Microsoft.EntityFrameworkCore (>= 6.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.EntityFrameworkCore.Abstractions (>= 6.0.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Expand Down Expand Up @@ -1200,6 +1209,7 @@ NUGET
Microsoft.NETCore.Targets (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Collections.Immutable (6.0)
System.Memory (>= 4.5.4) - restriction: || (== net472) (&& (== net6.0) (>= net461))
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Collections.NonGeneric (4.3) - restriction: || (&& (== net472) (< net35)) (== net6.0)
System.Diagnostics.Debug (>= 4.3) - restriction: || (&& (== net472) (< net46)) (== net6.0)
Expand Down Expand Up @@ -1260,6 +1270,7 @@ NUGET
Microsoft.NETCore.Targets (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Diagnostics.DiagnosticSource (6.0)
System.Memory (>= 4.5.4) - restriction: || (== net472) (&& (== net6.0) (>= net461)) (&& (== net6.0) (< net5.0))
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Diagnostics.EventLog (7.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
System.Diagnostics.TraceSource (4.3) - restriction: || (&& (== net472) (< net35)) (== net6.0)
Expand Down Expand Up @@ -1466,14 +1477,16 @@ NUGET
System.Threading (4.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Threading.Tasks (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Threading.Channels (8.0) - restriction: || (== net472) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0) (< netstandard2.1))
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (== net472) (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1))
System.Threading.Tasks (4.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
Microsoft.NETCore.Targets (>= 1.1) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net472) (< net45)) (== net6.0)
System.Threading.Tasks.Dataflow (6.0)
System.Threading.Tasks.Extensions (4.5.4)
System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (== net472) (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netcoreapp2.1)) (&& (== net6.0) (< netstandard1.0)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= wp8))
System.ValueTuple (4.5) - restriction: || (== net472) (&& (== net6.0) (>= net461))
System.ValueTuple (4.5) - restriction: || (== net472) (&& (== net6.0) (< netstandard2.1))
System.Windows.Extensions (7.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
System.Drawing.Common (>= 7.0) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
System.Xml.ReaderWriter (4.3.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Expand Down
4 changes: 2 additions & 2 deletions src/StreetNameRegistry.Infrastructure/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class Schema
public const string BackOfficeProjections = "StreetNameRegistryBackOfficeProjections";
public const string Producer = "StreetNameRegistryProducer";
public const string ProducerSnapshotOslo = "StreetNameRegistryProducerSnapshotOslo";
public const string Integration = "integration";
public const string Integration = "integration_streetname";
}

public static class MigrationTables
Expand All @@ -37,6 +37,6 @@ public static class MigrationTables
public const string BackOfficeProjections = "__EFMigrationsHistoryBackOfficeProjections";
public const string Producer = "__EFMigrationsHistoryProducer";
public const string ProducerSnapshotOslo = "__EFMigrationsHistoryProducerSnapshotOslo";
public const string Integration = "__EFMigrationsHistoryIntegrationStreetName";
public const string Integration = "__EFMigrationsHistory";
}
}
7 changes: 7 additions & 0 deletions src/StreetNameRegistry.Projections.Integration/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace StreetNameRegistry.Projections.Integration
{
public class Extensions
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace StreetNameRegistry.Projections.Integration.Infrastructure
{
public class ConnectionStringOptions
{
public string Events { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ namespace StreetNameRegistry.Projections.Integration.Infrastructure
{
using System;
using Autofac;
using Be.Vlaanderen.Basisregisters.DataDog.Tracing.Sql.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using StreetNameRegistry.Infrastructure;
using Npgsql;

public class IntegrationModule : Module
{
Expand All @@ -22,7 +20,7 @@ public IntegrationModule(

var hasConnectionString = !string.IsNullOrWhiteSpace(connectionString);
if (hasConnectionString)
RunOnNpgSqlServer(configuration, services, loggerFactory, connectionString);
RunOnNpgSqlServer(services, connectionString);
else
RunInMemoryDb(services, loggerFactory, logger);

Expand All @@ -36,23 +34,15 @@ public IntegrationModule(
}

private static void RunOnNpgSqlServer(
IConfiguration configuration,
IServiceCollection services,
ILoggerFactory loggerFactory,
string backofficeProjectionsConnectionString)
string connectionString)
{
services
.AddNpgsql<IntegrationContext>(backofficeProjectionsConnectionString)
.AddScoped(_ => new TraceDbConnection<IntegrationContext>(
new NpgsqlConnection(backofficeProjectionsConnectionString),
configuration["DataDog:ServiceName"]))
.AddDbContext<IntegrationContext>((provider, options) => options
.UseLoggerFactory(loggerFactory)
.UseNpgsql(provider.GetRequiredService<TraceDbConnection<IntegrationContext>>(), sqlServerOptions =>
{
sqlServerOptions.EnableRetryOnFailure();
sqlServerOptions.MigrationsHistoryTable(MigrationTables.Integration, Schema.Integration);
}));
.AddNpgsql<IntegrationContext>(connectionString, sqlServerOptions =>
{
sqlServerOptions.EnableRetryOnFailure();
sqlServerOptions.MigrationsHistoryTable(MigrationTables.Integration, Schema.Integration);
});
}

private static void RunInMemoryDb(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
namespace StreetNameRegistry.Projections.Integration
{
using System;
using System.IO;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using StreetNameRegistry.Infrastructure;

public class IntegrationContext : RunnerDbContext<IntegrationContext>
Expand All @@ -22,39 +18,4 @@ public IntegrationContext() { }
public IntegrationContext(DbContextOptions<IntegrationContext> options)
: base(options) { }
}

public class ConfigBasedIntegrationContextFactory : IDesignTimeDbContextFactory<IntegrationContext>
{
public IntegrationContext CreateDbContext(string[] args)
{
var migrationConnectionStringName = "IntegrationProjectionsAdmin";

var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.MachineName}.json", true)
.AddJsonFile($"appsettings.development.json", true)
.AddEnvironmentVariables()
.Build();

var builder = new DbContextOptionsBuilder<IntegrationContext>();

var connectionString = configuration
.GetConnectionString(migrationConnectionStringName)
?? throw new InvalidOperationException($"Could not find a connection string with name '{migrationConnectionStringName}'");
Console.WriteLine(connectionString);
builder
.UseNpgsql(connectionString, npgSqlOptions =>
{
npgSqlOptions.EnableRetryOnFailure();
npgSqlOptions.MigrationsHistoryTable(
MigrationTables.Integration,
Schema.Integration);
//npgSqlOptions.UseNetTopologySuite();
npgSqlOptions.CommandTimeout(260);
});

return new IntegrationContext(builder.Options);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace StreetNameRegistry.Projections.Integration
public class IntegrationContextMigrationFactory : NpgsqlRunnerDbContextMigrationFactory<IntegrationContext>
{
public IntegrationContextMigrationFactory()
: base("IntegrationProjectionsAdmin", HistoryConfiguration) { }
: base("IntegrationProjectionsAdmin", HistoryConfiguration)
{ }

private static MigrationHistoryConfiguration HistoryConfiguration =>
new MigrationHistoryConfiguration
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a26346b

Please sign in to comment.