Skip to content

Commit

Permalink
Sql Transport tables need to be part of stateful resource model. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Aug 10, 2023
1 parent 62c3b13 commit f2c56c5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Persistence/Wolverine.RDBMS/MigrationLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Wolverine.RDBMS;

internal class MigrationLogger : IMigrationLogger
public class MigrationLogger : IMigrationLogger
{
private readonly ILogger _logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using JasperFx.Core;
using JasperFx.Core.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Weasel.Core.Migrations;
using Wolverine.Configuration;
using Wolverine.SqlServer.Transport;

Expand Down Expand Up @@ -74,6 +76,8 @@ public static SqlServerPersistenceExpression UseSqlServerPersistenceAndTransport

}

options.Services.AddTransient<IDatabase, SqlServerTransportDatabase>();

extension.Settings.ScheduledJobLockId = $"{schema}:scheduled-jobs".GetDeterministicHashCode();
options.Include(extension);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Weasel.Core;
using Weasel.Core.Migrations;
using Weasel.SqlServer;
using Wolverine.RDBMS;
using Wolverine.Runtime;

namespace Wolverine.SqlServer.Transport;

public class SqlServerTransportDatabase : DatabaseBase<SqlConnection>
{
private readonly SqlServerTransport _transport;
private readonly IWolverineRuntime _runtime;

internal static SqlConnection BuildConnection(IWolverineRuntime runtime)
{
var transport = runtime.Options.SqlServerTransport();
return new SqlConnection(transport.Settings.ConnectionString);
}

public SqlServerTransportDatabase(IWolverineRuntime runtime) : base(new MigrationLogger(runtime.LoggerFactory.CreateLogger<SqlServerTransportDatabase>()), AutoCreate.CreateOrUpdate, new SqlServerMigrator(), "Sql Server Messaging Transport", () => BuildConnection(runtime))
{
_transport = runtime.Options.SqlServerTransport();
_runtime = runtime;
}

public override IFeatureSchema[] BuildFeatureSchemas()
{
return _transport.Queues.Select(queue => (IFeatureSchema)new SqlServerQueueFeatureSchema(queue, Migrator)).ToArray();
}
}

internal class SqlServerQueueFeatureSchema : FeatureSchemaBase
{
public SqlServerQueue Queue { get; }

public SqlServerQueueFeatureSchema(SqlServerQueue queue, Migrator migrator) : base($"SqlServerQueue_{queue.Name}", migrator)
{
Queue = queue;
}

protected override IEnumerable<ISchemaObject> schemaObjects()
{
yield return Queue.QueueTable;
yield return Queue.ScheduledTable;
}
}

0 comments on commit f2c56c5

Please sign in to comment.