Skip to content

Commit 287a820

Browse files
committed
Update template to support sidecar (only).
1 parent c56741d commit 287a820

File tree

21 files changed

+186
-275
lines changed

21 files changed

+186
-275
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Represents the **NuGet** versions.
44

55
## v3.0.0
66
- *Enhancement:* Major **"Sidecar"** feature added based on feedback from the community.
7-
- The existing implementation required all generated supporting database capabilities to be within the "main" database itself; a new option has been added to generate a separate "sidecar" database to manage. This minimizes the impact on the "main" database.
8-
- The "main" database will still require the database CDC (change-data-capture) capabilities to be enabled.
7+
- The existing implementation required all generated supporting database capabilities to be within the "source" database itself; a new option has been added to generate a separate "sidecar" database to manage. This minimizes the impact on the "source" database.
8+
- The "source" database will still require the database CDC (change-data-capture) capabilities to be enabled.
99
- The new [`EntitySidecarOrchestratorBase`](./src/NTangle/Cdc/EntitySidecarOrchestratorBase.cs) will invoke a single statement to leverage the CDC capabilities and perform the resulting data selection; see the [`ContactExecuteBatch.sql`](./samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteBatch.sql).
1010
- The required `NTangle` (and optional `Outbox`) schema(s), table(s) and stored procedures will be generated within the "sidecar" database.
1111
- Note that there are _no_ cross database dependencies; as such, the "sidecar" database can be hosted separately, be on a difference versions, etc. as required. The .NET orchestrator logic will _require_ access to both databases to function.

NTangle.sln

+1-56
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Github Actions", "Github Ac
6565
.github\workflows\CI.yml = .github\workflows\CI.yml
6666
EndProjectSection
6767
EndProject
68-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ContactSync", "ContactSync", "{240EFA31-7366-47BD-8A56-B3312D06BB13}"
69-
ProjectSection(SolutionItems) = preProject
70-
samples\ContactSync\README.md = samples\ContactSync\README.md
71-
EndProjectSection
72-
EndProject
73-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OldApp", "OldApp", "{1FF28F16-F241-4EA0-9DD1-81E19C6A7EF5}"
74-
EndProject
75-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContactSync.OldApp.CodeGen", "samples\ContactSync\ContactSync.OldApp\ContactSync.OldApp.CodeGen\ContactSync.OldApp.CodeGen.csproj", "{9A1DDC23-4B62-43F6-8C4E-D5CB86E5D488}"
76-
EndProject
77-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContactSync.OldApp.Database", "samples\ContactSync\ContactSync.OldApp\ContactSync.OldApp.Database\ContactSync.OldApp.Database.csproj", "{4C20E9BE-2C69-419A-A775-75A11A707E63}"
78-
EndProject
79-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContactSync.OldApp.Publisher", "samples\ContactSync\ContactSync.OldApp\ContactSync.OldApp.Publisher\ContactSync.OldApp.Publisher.csproj", "{F48B08F9-57A5-405D-B40B-2D672A10CD5C}"
80-
EndProject
81-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NewApp", "NewApp", "{6855FFC2-39E7-48D4-AB5D-079D406390FC}"
82-
EndProject
83-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContactSync.NewApp.Database", "samples\ContactSync\ContactSync.NewApp\ContactSync.NewApp.Database\ContactSync.NewApp.Database.csproj", "{4BADE51C-EA1C-4A68-B591-8F148F5FF975}"
84-
EndProject
85-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContactSync.NewApp.Subscriber", "samples\ContactSync\ContactSync.NewApp\ContactSync.NewApp.Subscriber\ContactSync.NewApp.Subscriber.csproj", "{D6364CFB-DAAA-41E7-996F-8F1654EECF10}"
86-
EndProject
87-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{7596959A-8A5E-409D-BED5-006950299A4E}"
88-
ProjectSection(SolutionItems) = preProject
89-
samples\ContactSync\docs\old-app-code-gen.md = samples\ContactSync\docs\old-app-code-gen.md
90-
samples\ContactSync\docs\old-app-publish.md = samples\ContactSync\docs\old-app-publish.md
91-
samples\ContactSync\docs\old-app-setup.md = samples\ContactSync\docs\old-app-setup.md
92-
EndProjectSection
93-
EndProject
9468
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NTangle.CodeGen", "tools\NTangle.CodeGen\NTangle.CodeGen.csproj", "{BB87378A-0444-4BDC-8530-20F25D852C77}"
9569
EndProject
9670
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SqlServerSidecarDemo", "SqlServerSidecarDemo", "{12BF3E9B-E59B-45AC-B307-7B68BD8B6DFB}"
@@ -103,7 +77,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerSidecarDemo.Sideca
10377
EndProject
10478
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerSidecarDemo.Publisher", "samples\SqlServerSidecarDemo\SqlServerSidecarDemo.Publisher\SqlServerSidecarDemo.Publisher.csproj", "{0E8663F4-EDA1-42A9-BDF5-085D230A784A}"
10579
EndProject
106-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlServerSidecarDemo.Test", "samples\SqlServerSidecarDemo\SqlServerSidecarDemo.Test\SqlServerSidecarDemo.Test.csproj", "{3707977E-BC42-4CBA-9432-7F41F2BEE8F9}"
80+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerSidecarDemo.Test", "samples\SqlServerSidecarDemo\SqlServerSidecarDemo.Test\SqlServerSidecarDemo.Test.csproj", "{3707977E-BC42-4CBA-9432-7F41F2BEE8F9}"
10781
EndProject
10882
Global
10983
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -143,26 +117,6 @@ Global
143117
{467C4732-8A67-435C-9AB4-697CB89C4EE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
144118
{467C4732-8A67-435C-9AB4-697CB89C4EE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
145119
{467C4732-8A67-435C-9AB4-697CB89C4EE4}.Release|Any CPU.Build.0 = Release|Any CPU
146-
{9A1DDC23-4B62-43F6-8C4E-D5CB86E5D488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
147-
{9A1DDC23-4B62-43F6-8C4E-D5CB86E5D488}.Debug|Any CPU.Build.0 = Debug|Any CPU
148-
{9A1DDC23-4B62-43F6-8C4E-D5CB86E5D488}.Release|Any CPU.ActiveCfg = Release|Any CPU
149-
{9A1DDC23-4B62-43F6-8C4E-D5CB86E5D488}.Release|Any CPU.Build.0 = Release|Any CPU
150-
{4C20E9BE-2C69-419A-A775-75A11A707E63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
151-
{4C20E9BE-2C69-419A-A775-75A11A707E63}.Debug|Any CPU.Build.0 = Debug|Any CPU
152-
{4C20E9BE-2C69-419A-A775-75A11A707E63}.Release|Any CPU.ActiveCfg = Release|Any CPU
153-
{4C20E9BE-2C69-419A-A775-75A11A707E63}.Release|Any CPU.Build.0 = Release|Any CPU
154-
{F48B08F9-57A5-405D-B40B-2D672A10CD5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155-
{F48B08F9-57A5-405D-B40B-2D672A10CD5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
156-
{F48B08F9-57A5-405D-B40B-2D672A10CD5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
157-
{F48B08F9-57A5-405D-B40B-2D672A10CD5C}.Release|Any CPU.Build.0 = Release|Any CPU
158-
{4BADE51C-EA1C-4A68-B591-8F148F5FF975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
159-
{4BADE51C-EA1C-4A68-B591-8F148F5FF975}.Debug|Any CPU.Build.0 = Debug|Any CPU
160-
{4BADE51C-EA1C-4A68-B591-8F148F5FF975}.Release|Any CPU.ActiveCfg = Release|Any CPU
161-
{4BADE51C-EA1C-4A68-B591-8F148F5FF975}.Release|Any CPU.Build.0 = Release|Any CPU
162-
{D6364CFB-DAAA-41E7-996F-8F1654EECF10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
163-
{D6364CFB-DAAA-41E7-996F-8F1654EECF10}.Debug|Any CPU.Build.0 = Debug|Any CPU
164-
{D6364CFB-DAAA-41E7-996F-8F1654EECF10}.Release|Any CPU.ActiveCfg = Release|Any CPU
165-
{D6364CFB-DAAA-41E7-996F-8F1654EECF10}.Release|Any CPU.Build.0 = Release|Any CPU
166120
{BB87378A-0444-4BDC-8530-20F25D852C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167121
{BB87378A-0444-4BDC-8530-20F25D852C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
168122
{BB87378A-0444-4BDC-8530-20F25D852C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -201,15 +155,6 @@ Global
201155
{54D9318B-8D30-41FF-A5DD-554C13AC62F3} = {5B2FCA11-CC69-40D7-9FC3-DC7707C77D45}
202156
{AD6A38DA-9BB6-4650-A512-434EC19E8DDD} = {780B69CA-D467-45CF-B115-A3FEB0B88BD1}
203157
{467C4732-8A67-435C-9AB4-697CB89C4EE4} = {54E2D3C7-1AC1-4EA6-A8CA-42EC12A6E299}
204-
{240EFA31-7366-47BD-8A56-B3312D06BB13} = {3A0B49DA-7D84-4B96-A4F3-FAF77C3E2FB3}
205-
{1FF28F16-F241-4EA0-9DD1-81E19C6A7EF5} = {240EFA31-7366-47BD-8A56-B3312D06BB13}
206-
{9A1DDC23-4B62-43F6-8C4E-D5CB86E5D488} = {1FF28F16-F241-4EA0-9DD1-81E19C6A7EF5}
207-
{4C20E9BE-2C69-419A-A775-75A11A707E63} = {1FF28F16-F241-4EA0-9DD1-81E19C6A7EF5}
208-
{F48B08F9-57A5-405D-B40B-2D672A10CD5C} = {1FF28F16-F241-4EA0-9DD1-81E19C6A7EF5}
209-
{6855FFC2-39E7-48D4-AB5D-079D406390FC} = {240EFA31-7366-47BD-8A56-B3312D06BB13}
210-
{4BADE51C-EA1C-4A68-B591-8F148F5FF975} = {6855FFC2-39E7-48D4-AB5D-079D406390FC}
211-
{D6364CFB-DAAA-41E7-996F-8F1654EECF10} = {6855FFC2-39E7-48D4-AB5D-079D406390FC}
212-
{7596959A-8A5E-409D-BED5-006950299A4E} = {240EFA31-7366-47BD-8A56-B3312D06BB13}
213158
{BB87378A-0444-4BDC-8530-20F25D852C77} = {780B69CA-D467-45CF-B115-A3FEB0B88BD1}
214159
{12BF3E9B-E59B-45AC-B307-7B68BD8B6DFB} = {3A0B49DA-7D84-4B96-A4F3-FAF77C3E2FB3}
215160
{C51EA07D-D813-405D-B80E-D2F9817BCE5F} = {12BF3E9B-E59B-45AC-B307-7B68BD8B6DFB}

docs/SqlServer.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ This documents the _nTangle_ [architecture](#Architecture) and corresponding [co
66

77
## Overview
88

9-
At its core _nTangle_ is a database-driven code-generation solution, in that it leverages an existing database to infer its underlying schema (tables and columns). A YAML (or JSON) configuration file is required to define the CDC requirements, being the root and child tables, and their relationships, representing the entity (aggregate root). The _nTangle_ code-gen tool connects to the database, and using the YAML configuration generates the required database (main and sidecar), and .NET publishing runtime artefacts. This publishing runtime then uses the database's CDC capabilities to detect changes to the underlying tables and trigger the creation of the related entity events that are then published.
9+
At its core _nTangle_ is a database-driven code-generation solution, in that it leverages an existing source database to infer its underlying schema (tables and columns). A YAML (or JSON) configuration file is required to define the CDC requirements, being the root and child tables, and their relationships, representing the entity (aggregate root). The _nTangle_ code-gen tool connects to the database, and using the YAML configuration generates the required database (source and sidecar), and .NET publishing runtime artefacts. This publishing runtime then uses the database's CDC capabilities to detect changes to the underlying tables and trigger the creation of the related entity events that are then published.
1010

1111
![Overview](../images/Overview.png "Overview")
1212

1313
The core components are:
14-
- **Database** - the existing tables (main database), plus generated _nTangle_ runtime artefacts (including outbox) in separate sidecar database;
14+
- **Database** - the existing tables (source database), plus generated _nTangle_ runtime artefacts (including outbox) in separate sidecar database;
1515
- **Config** - the _nTangle_ code-gen configuration;
1616
- **Tooling** - the _nTangle_ code generator and resulting generated publisher .NET runtime;
1717
- **Events** - the resulting published entity event (depicted as a [CloudEvent](https://cloudevents.io/)).
@@ -44,9 +44,9 @@ Microsoft SQL Server provides two change tracking capabilities, namely CDC and [
4444

4545
## Sidecar database
4646

47-
As of version `3.0.0` the preferred (recommended and default) approach is to use a sidecar database to manage the _nTangle_ runtime artefacts. This is to ensure that the main database is not polluted with the _nTangle_ specific artefacts, and to ensure that the _nTangle_ runtime can be easily removed without impacting the main database as required.
47+
As of version `3.0.0` the preferred (recommended and default) approach is to use a sidecar database to manage the _nTangle_ runtime artefacts. This is to ensure that the source database is not polluted with the _nTangle_ specific artefacts, and to ensure that the _nTangle_ runtime can be easily removed without impacting the source database as required.
4848

49-
Primarily, usage of a sidecar database will also limit impact (load and data) on the main database by minimizing access to the CDC and related entity data selection only. Otherwise, the required orchestration will occur against the sidecar database.
49+
Primarily, usage of a sidecar database will also limit impact (load and data) on the source database by minimizing access to the CDC and related entity data selection only. Otherwise, the required orchestration will occur against the sidecar database.
5050

5151
Note that there are _no_ cross database dependencies; as such, the sidecar database can be hosted separately, be on a different version, etc. as required. The .NET orchestrator logic _will_ however require access to both databases to function.
5252

@@ -61,7 +61,7 @@ The following represents the high-level conceptual run-time architecture for a s
6161
</br>
6262

6363
The SQL Server databases are as follows:
64-
- **Main** - the existing database schema (tables and columns) that is being monitored for changes (CDC).
64+
- **Source** - the existing database schema (tables and columns) that is being monitored for changes (CDC).
6565
- **Sidecar** - the generated _nTangle_ runtime artefacts (tables and stored procedures) that are used to orchestrate the CDC and event publishing.
6666

6767
The key .NET components are as follows.
@@ -94,7 +94,7 @@ An orchestrator is generated per [entity](../src/NTangle/IEntity.cs) (the aggreg
9494

9595
A batch check is performed against the sidecar database using the [`spXxxBatchExecute`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.SidecarDb/Schema/NTangle/Stored%20Procedures/Generated/spContactBatchExecute.sql) stored procedure to determine if there is already an incomplete Batch and attempt to reprocess; otherwise, determine current CDC position from last complete Batch to continue. The batch tracking is persisted in the [`XxxBatchTracking`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.SidecarDb/Migrations/20241024-233018-03-create-ntangle-contactbatchtracking-table.sql) table.
9696

97-
The orchestrator will the select (detect) the changes as enabled by the SQL Server CDC capabilities in the main database. This is achieved by invoking the [`XxxExecuteBatch`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteBatch.sql) SQL statement and updating the corresponding result sets into the .NET entity equivalents. The following steps are performed.
97+
The orchestrator will the select (detect) the changes as enabled by the SQL Server CDC capabilities in the source database. This is achieved by invoking the [`XxxExecuteBatch`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteBatch.sql) SQL statement and updating the corresponding result sets into the .NET entity equivalents. The following steps are performed.
9898

9999
Step | Description
100100
-|-
@@ -215,15 +215,15 @@ The hosting of the `XxxOrchestrator` to enable explicit execution is the respons
215215

216216
## Code-generation
217217

218-
The [code-generator](../tools/NTangle.Template/content/AppName.CodeGen/Program.cs) will leverage the [ntangle.yaml](../tools/NTangle.Template/content/AppName.CodeGen/ntangle.yaml) configuration to generate the [Main database](#Main-database), [Sidecar database](#Sidecar-database), and [.NET](#net) artefacts.
218+
The [code-generator](../tools/NTangle.Template/content/AppName.CodeGen/Program.cs) will leverage the [ntangle.yaml](../tools/NTangle.Template/content/AppName.CodeGen/ntangle.yaml) configuration to generate the [source database](#Source-database), [Sidecar database](#Sidecar-database), and [.NET](#net) artefacts.
219219

220220
Where `Xxx` is referenced in the artefact name this is replaced with the name of the entity (root aggregate). Also, the artefact name represents the default, there are opportunities within the `ntangle.yaml` to change the behavior of these where applicable.
221221

222222
Finally, features such as _event outbox_ and _identity mapping_ are configurable; where not leveraged their respective artefacts will not be generated.
223223

224224
<br/>
225225

226-
### Main database
226+
### Source database
227227

228228
The `AppName.Database` project generated artefacts are as follows.
229229

@@ -267,6 +267,6 @@ Data | [`XxxOrchestrator`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.
267267
Data | [`EventOutboxDequeue`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Data/Generated/EventOutboxDequeue.cs) | Event outbox dequeue.
268268
Data | [`EventOutboxEnqueue`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Data/Generated/EventOutboxEnqueue.cs) | Event outbox enqueue.
269269
Entities | [`XxxCdc`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Entities/Generated/ContactCdc.cs) | Entity (aggregate root) representation of database table(s) and relationships (per entity).
270-
Resources | [`XxxExecuteBatch.sql`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteBatch.sql) | TSQL statement (main database) to execute the batch using CDC (per entity).
271-
Resources | [`XxxExecuteExplicit.sql`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteExplicit.sql) | TSQL statement (main database) to execute explicitly without Batch and CDC (per entity).
270+
Resources | [`XxxExecuteBatch.sql`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteBatch.sql) | TSQL statement (source database) to execute the batch using CDC (per entity).
271+
Resources | [`XxxExecuteExplicit.sql`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Resources/Generated/ContactExecuteExplicit.sql) | TSQL statement (source database) to execute explicitly without Batch and CDC (per entity).
272272
Services | [`XxxHostedService`](../samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Services/Generated/ContactHostedService.cs) | Timer-based host for the `XxxCdcOrchestrator`.

samples/SqlServerSidecarDemo/SqlServerSidecarDemo.Publisher/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal static void Main(string[] args) => Host.CreateDefaultBuilder(args)
1919
services.AddSettings<SqlServerSidecarDemoSettings>()
2020
.AddLogging(b => b.AddSimpleConsole())
2121
.AddDatabase(sp => new SqlServerDatabase(() => new SqlConnection(sp.GetRequiredService<SqlServerSidecarDemoSettings>().DatabaseConnectionString)))
22-
.AddScoped<ISidecarDatabase>(sp => new SqlServerSidecarDatabase(() => new SqlConnection(sp.GetRequiredService<SqlServerSidecarDemoSettings>().SidecarDatabaseConnectionString)))
22+
.AddSidecarDatabase(sp => new SqlServerSidecarDatabase(() => new SqlConnection(sp.GetRequiredService<SqlServerSidecarDemoSettings>().SidecarDatabaseConnectionString)))
2323
.AddStringIdentifierGenerator()
2424
.AddExecutionContext()
2525
.AddJsonSerializer();

0 commit comments

Comments
 (0)