Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make YesSqlOptions configurable from configuration provider #16079

Merged
merged 10 commits into from
May 18, 2024
10 changes: 6 additions & 4 deletions .github/workflows/mac_unit_test_ci.yml
Piedone marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ jobs:
name: Unit Tests
steps:
- uses: actions/checkout@v4
- name: Build and test
run: |
dotnet build -c Release -warnaserror /p:TreatWarningsAsErrors=true /p:RunAnalyzers=true
dotnet test -c Release --no-restore --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
- name: Build
run: dotnet build -c Release -warnaserror /p:TreatWarningsAsErrors=true /p:RunAnalyzers=true
- name: Run Test
run: dotnet test -c Release --no-restore --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
env:
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
Piedone marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
- name: Unit Tests
run: |
dotnet test -c Release --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
env:
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
- name: Functional Tests
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
- name: Unit Tests
run: |
dotnet test -c Release --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
env:
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
- name: Functional Tests
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/preview_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
if: steps.check-publish.outputs.should-publish == 'true'
run: |
dotnet test -c Release --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
env:
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
- name: Functional Tests
if: steps.check-publish.outputs.should-publish == 'true'
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
- name: Unit Tests
run: |
dotnet test -c Release --no-build ./test/OrchardCore.Tests/OrchardCore.Tests.csproj
env:
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
- name: Functional Tests
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down
6 changes: 6 additions & 0 deletions src/OrchardCore.Cms.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
// "DefaultTableNameSeparator": "_", // Table name separator, one or multiple '_', "NULL" means no separator, defaults to '_'.
// "DefaultIdentityColumnSize": "Int64" // Identity column size, 'Int32' or 'Int64', defaults to 'Int64'.
//},
// See https://docs.orchardcore.net/en/latest/reference/core/Data/#database-table to configure database table presets used before a given tenant is setup.
//"OrchardCore_YesSql": {
// "CommandsPageSize": 500,
// "QueryGatingEnabled": true,
// "EnableThreadSafetyChecks": false
Piedone marked this conversation as resolved.
Show resolved Hide resolved
//},
// See https://docs.orchardcore.net/en/latest/reference/modules/DataProtection.Azure/#configuration to configure data protection key storage in Azure Blob Storage.
//"OrchardCore_DataProtection_Azure": {
// "ConnectionString": "", // Set to your Azure Storage account connection string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using OrchardCore.Data.Migration;
using OrchardCore.Data.YesSql;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Configuration;
using OrchardCore.Environment.Shell.Removing;
using OrchardCore.Environment.Shell.Scope;
using OrchardCore.Json;
Expand Down Expand Up @@ -37,8 +38,11 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder)
{
builder.ApplicationServices.AddSingleton<IShellRemovingHandler, ShellDbTablesRemovingHandler>();

builder.ConfigureServices(services =>
builder.ConfigureServices((services, serviceProvider) =>
{
var configuration = serviceProvider.GetService<IShellConfiguration>();

services.Configure<YesSqlOptions>(configuration.GetSection("OrchardCore_YesSql"));
services.AddScoped<IDbConnectionValidator, DbConnectionValidator>();
services.AddScoped<IDataMigrationManager, DataMigrationManager>();
services.AddScoped<IModularTenantEvents, AutomaticDataMigrations>();
Expand Down
14 changes: 12 additions & 2 deletions src/docs/reference/core/Data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ OrchardCore uses the `YesSql` library to interact with the configured database p
| `IdentifierAccessorFactory` | You can provide your own value accessor factory. |
| `VersionAccessorFactory` | You can provide your own version accessor factory. |
| `ContentSerializer` | You can provide your own content serializer. |
| `EnableThreadSafetyChecks` | Gets or sets the `EnableThreadSafetyChecks` option in YesSql, which aids in diagnosing concurrency or race condition issues. |

For example, you can change the default command-page-size from `500` to `1000` by adding the following code to your startup code.

Expand All @@ -46,6 +47,15 @@ services.Configure<YesSqlOptions>(options =>
});
```

You may configure `CommandsPageSize`, `QueryGatingEnabled`, and `EnableThreadSafetyChecks` options using a configuration provider like `appsettings.json` using the following

```json
"OrchardCore_YesSql": {
"CommandsPageSize": 500,
"QueryGatingEnabled": true,
"EnableThreadSafetyChecks": false
},

## Database table

The following database table settings, only used as presets before a given tenant is setup, can be provided from any configuration source.
Expand All @@ -56,10 +66,10 @@ The following database table settings, only used as presets before a given tenan
| `DefaultTableNameSeparator` | Table name separator, one or multiple '_', "NULL" means no separator, defaults to '_'. |
| `DefaultIdentityColumnSize` | Identity column size, 'Int32' or 'Int64', defaults to 'Int64'. |

##### `appsettings.json`
#### Configuration Source (ex., `appsettings.json`)

```json
"OrchardCore_Data_TableOptions": {
"OrchardCore_Data_TableOptions": {
"DefaultDocumentTable": "Document",
"DefaultTableNameSeparator": "_",
"DefaultIdentityColumnSize": "Int64"
Expand Down