Skip to content

Commit

Permalink
Make YesSqlOptions configurable from configuration provider (#16079)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored May 18, 2024
1 parent 726e280 commit 7827810
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/functional_all_db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
runs-on: ubuntu-latest
container:
image: cypress/included:9.6.1
env:
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
steps:
- uses: actions/checkout@v4
# We need to install dotnet in the docker container.
Expand All @@ -69,7 +71,7 @@ jobs:
test/OrchardCore.Tests.Functional/cms-tests/cypress/screenshots
src/OrchardCore.Cms.Web/App_Data/logs
retention-days: 3

test_functional_cms_postgresql:
name: Functional Tests - CMS Postgres
runs-on: ubuntu-latest
Expand All @@ -91,6 +93,7 @@ jobs:
env:
OrchardCore__ConnectionString: "User ID=postgres;Password=admin;Host=postgres;Port=5432;Database=app;"
OrchardCore__DatabaseProvider: "Postgres"
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
steps:
- uses: actions/checkout@v4
# We need to install dotnet in the docker container.
Expand Down Expand Up @@ -128,6 +131,7 @@ jobs:
env:
OrchardCore__ConnectionString: "server=mysql;uid=root;pwd=test123;database=test"
OrchardCore__DatabaseProvider: "MySql"
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
steps:
- uses: actions/checkout@v4
# We need to install dotnet in the docker container.
Expand Down Expand Up @@ -164,6 +168,7 @@ jobs:
env:
OrchardCore__ConnectionString: "Server=mssql;Database=tempdb;User Id=sa;Password=Password12!;Encrypt=False"
OrchardCore__DatabaseProvider: "SqlConnection"
OrchardCore__OrchardCore_YesSql__EnableThreadSafetyChecks: true
steps:
- uses: actions/checkout@v4
# We need to install dotnet in the docker container.
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/#configuring-yessql to configure YesSql.
//"OrchardCore_YesSql": {
// "CommandsPageSize": 500,
// "QueryGatingEnabled": true,
// "EnableThreadSafetyChecks": false
//},
// 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 All @@ -64,6 +68,7 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder)
}
var yesSqlOptions = sp.GetService<IOptions<YesSqlOptions>>().Value;
var databaseTableOptions = shellSettings.GetDatabaseTableOptions();
var storeConfiguration = GetStoreConfiguration(sp, yesSqlOptions, databaseTableOptions);
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

0 comments on commit 7827810

Please sign in to comment.