-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sql Transport tables need to be part of stateful resource model. Closes
- Loading branch information
1 parent
62c3b13
commit f2c56c5
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Persistence/Wolverine.SqlServer/Transport/SqlServerTransportDatabase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |