From 70154171c1c9c5db4c064a4fff12ab7a5d301275 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 23 Jan 2024 14:05:55 -0800 Subject: [PATCH 1/4] Keep yessql.db as the fallback name for sqllite for backward compatability Fix #15154 --- .../Workflows/Activities/SetupTenantTask.cs | 1 - .../OrchardCore.Abstractions/Setup/SetupConstants.cs | 1 + .../OrchardCore.Data.YesSql/Options/SqliteOptions.cs | 9 +++++++-- .../OrchardCoreBuilderExtensions.cs | 11 +++++++++++ .../OrchardCore.Setup.Core/SetupService.cs | 8 +++++++- src/docs/reference/core/Data/README.md | 5 ----- src/docs/releases/1.9.0.md | 8 ++++---- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Workflows/Activities/SetupTenantTask.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Workflows/Activities/SetupTenantTask.cs index 50f5bcd13b4..2856346634b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Workflows/Activities/SetupTenantTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Workflows/Activities/SetupTenantTask.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/src/OrchardCore/OrchardCore.Abstractions/Setup/SetupConstants.cs b/src/OrchardCore/OrchardCore.Abstractions/Setup/SetupConstants.cs index c00c9a80f69..3b84dfda5ec 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Setup/SetupConstants.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Setup/SetupConstants.cs @@ -10,6 +10,7 @@ public static class SetupConstants public const string DatabaseProvider = "DatabaseProvider"; public const string DatabaseConnectionString = "DatabaseConnectionString"; public const string DatabaseTablePrefix = "DatabaseTablePrefix"; + public const string DatabaseName = "DatabaseName"; public const string DatabaseSchema = "DatabaseSchema"; public const string SiteTimeZone = "SiteTimeZone"; public const string FeatureProfile = "FeatureProfile"; diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs index 82e1bb8c843..d48eae72697 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs @@ -17,8 +17,13 @@ public class SqliteOptions public bool UseConnectionPooling { get; set; } = true; /// - /// Gets or sets the database name. Defaults to OrchardCore.db. + /// Gets the database name. /// - public string DatabaseName { get; set; } = "OrchardCore.db"; + public string DatabaseName { get; private set; } + + public void SetDatabaseName(string databaseName) + { + DatabaseName = databaseName; + } } } diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs index d00bb6d8585..9a7f921310a 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs @@ -79,6 +79,17 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder) var databaseFolder = SqliteHelper.GetDatabaseFolder(shellOptions, shellSettings.Name); Directory.CreateDirectory(databaseFolder); + // For backward compatibility, we assume that the database name is 'yessql.db'. + // If shellSettings["DatabaseName"] has a value, we use the name provided in the shell settings. + var databaseName = "yessql.db"; + + if (!string.IsNullOrWhiteSpace(shellSettings["DatabaseName"])) + { + databaseName = shellSettings["DatabaseName"]; + } + + sqliteOptions.SetDatabaseName(databaseName); + var connectionString = SqliteHelper.GetConnectionString(sqliteOptions, databaseFolder); storeConfiguration .UseSqLite(connectionString, IsolationLevel.ReadUncommitted) diff --git a/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs b/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs index 8146b395d25..9f0e7212867 100644 --- a/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs +++ b/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs @@ -155,10 +155,16 @@ private async Task SetupInternalAsync(SetupContext context) var shellSettings = new ShellSettings(context.ShellSettings).ConfigureDatabaseTableOptions(); if (string.IsNullOrWhiteSpace(shellSettings["DatabaseProvider"])) { - shellSettings["DatabaseProvider"] = context.Properties.TryGetValue(SetupConstants.DatabaseProvider, out var databaseProvider) ? databaseProvider?.ToString() : string.Empty; + var providerName = context.Properties.TryGetValue(SetupConstants.DatabaseProvider, out var databaseProvider) ? databaseProvider?.ToString() : string.Empty; + shellSettings["DatabaseProvider"] = providerName; shellSettings["ConnectionString"] = context.Properties.TryGetValue(SetupConstants.DatabaseConnectionString, out var databaseConnectionString) ? databaseConnectionString?.ToString() : string.Empty; shellSettings["TablePrefix"] = context.Properties.TryGetValue(SetupConstants.DatabaseTablePrefix, out var databaseTablePrefix) ? databaseTablePrefix?.ToString() : string.Empty; shellSettings["Schema"] = context.Properties.TryGetValue(SetupConstants.DatabaseSchema, out var schema) ? schema?.ToString() : null; + + if (providerName == DatabaseProviderValue.Sqlite) + { + shellSettings["DatabaseName"] = context.Properties.TryGetValue(SetupConstants.DatabaseName, out var dbName) ? dbName?.ToString() : "orchardcore.db"; + } } var validationContext = new DbConnectionValidatorContext(shellSettings); diff --git a/src/docs/reference/core/Data/README.md b/src/docs/reference/core/Data/README.md index 377c5969907..c57f6ab46df 100644 --- a/src/docs/reference/core/Data/README.md +++ b/src/docs/reference/core/Data/README.md @@ -6,10 +6,6 @@ Most database configuration is handled automatically, but there are limited opti ### Sqlite -#### `DatabaseName` (string) - -By default, "OrchardCore.db" is used as the name for the SQLite database. This property allows you to use a database name of your choice. For backward compatibility with Orchard Core 1.8 and earlier, configure `"yessql.db"`. - #### `UseConnectionPooling` (boolean) By default in `.NET 6`, `Microsoft.Data.Sqlite` pools connections to the database. It achieves this by putting locking the database file and leaving connections open to be reused. If the lock is preventing tasks like backups, this functionality can be disabled. @@ -23,7 +19,6 @@ See the [`Microsoft.Data.Sqlite` documentation](https://docs.microsoft.com/en-us ```json { "OrchardCore_Data_Sqlite": { - "DatabaseName": "yessql.db", "UseConnectionPooling": false } } diff --git a/src/docs/releases/1.9.0.md b/src/docs/releases/1.9.0.md index 2d846722b0e..7d3008dbafb 100644 --- a/src/docs/releases/1.9.0.md +++ b/src/docs/releases/1.9.0.md @@ -12,10 +12,6 @@ Additionally, if you needed to enable indexing for text file with `.txt`, `.md` If you needed to enable indexing for other extensions like (`.docx`, or `.pptx`), you'll needed `OrchardCore.Media.Indexing.OpenXML` feature. -### Data Access - -Previously, the `yessql.db` file was used as a default SQLite database for newly created tenants. Now `OrchardCore.db` is used instead, but you can configure the database name using `SqliteOptions.Database`. - !!! warning For backward compatibility, you should use `yessql.db` as the database name in the `OrchardCore_Data_Sqlite` configuration. For more info read the [Data (`OrchardCore.Data`) documentation](../reference/core/Data/README.md). @@ -38,3 +34,7 @@ Added new extensions to make registering custom deployment step easier - services.AddDeployment(); - services.AddDeployment(); - services.AddDeploymentWithoutSource(); + +### Data Access + +Prior this release, the default SQLite database for newly created tenants was `yessql.db`. Now, the `orchardcore.db` file is utilized instead. However, you have the flexibility to configure the database name beforehand in the ShellSettings of the tenants by including the `DatabaseName` property. From 4a4adee7910a7af8a1e5d11394995f2b5eabb2ec Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 23 Jan 2024 14:54:33 -0800 Subject: [PATCH 2/4] Fix tests --- .../OrchardCoreBuilderExtensions.cs | 8 +------- .../OrchardCore.Data.YesSql/SqliteHelper.cs | 18 ++++++++++++++---- .../OrchardCore.Setup.Core/SetupService.cs | 11 +++++------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs index 9a7f921310a..af694f03eaf 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs @@ -79,17 +79,11 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder) var databaseFolder = SqliteHelper.GetDatabaseFolder(shellOptions, shellSettings.Name); Directory.CreateDirectory(databaseFolder); - // For backward compatibility, we assume that the database name is 'yessql.db'. - // If shellSettings["DatabaseName"] has a value, we use the name provided in the shell settings. - var databaseName = "yessql.db"; - if (!string.IsNullOrWhiteSpace(shellSettings["DatabaseName"])) { - databaseName = shellSettings["DatabaseName"]; + sqliteOptions.SetDatabaseName(shellSettings["DatabaseName"]); } - sqliteOptions.SetDatabaseName(databaseName); - var connectionString = SqliteHelper.GetConnectionString(sqliteOptions, databaseFolder); storeConfiguration .UseSqLite(connectionString, IsolationLevel.ReadUncommitted) diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs b/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs index 3036270c147..561a7ad4533 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs @@ -9,15 +9,25 @@ public static class SqliteHelper public static string GetConnectionString(SqliteOptions sqliteOptions, ShellOptions shellOptions, string shellName) => GetConnectionString(sqliteOptions, GetDatabaseFolder(shellOptions, shellName)); - public static string GetConnectionString(SqliteOptions sqliteOptions, string databaseFolder) => - new SqliteConnectionStringBuilder + public static string GetConnectionString(SqliteOptions sqliteOptions, string databaseFolder) + { + // For backward compatibility, we assume that the database name is 'yessql.db'. + // If shellSettings["DatabaseName"] has a value, we use the name provided in the shell settings. + if (string.IsNullOrEmpty(sqliteOptions.DatabaseName)) { - DataSource = Path.Combine(databaseFolder, sqliteOptions.DatabaseName), + sqliteOptions.SetDatabaseName("yessql.db"); + } + + return new SqliteConnectionStringBuilder + { + DataSource = string.IsNullOrEmpty(databaseFolder) + ? sqliteOptions.DatabaseName + : Path.Combine(databaseFolder, sqliteOptions.DatabaseName), Cache = SqliteCacheMode.Shared, Pooling = sqliteOptions.UseConnectionPooling } .ToString(); - + } public static string GetDatabaseFolder(ShellOptions shellOptions, string shellName) => Path.Combine(shellOptions.ShellsApplicationDataPath, shellOptions.ShellsContainerName, shellName); } diff --git a/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs b/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs index 9f0e7212867..2a55d612c44 100644 --- a/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs +++ b/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs @@ -155,16 +155,15 @@ private async Task SetupInternalAsync(SetupContext context) var shellSettings = new ShellSettings(context.ShellSettings).ConfigureDatabaseTableOptions(); if (string.IsNullOrWhiteSpace(shellSettings["DatabaseProvider"])) { - var providerName = context.Properties.TryGetValue(SetupConstants.DatabaseProvider, out var databaseProvider) ? databaseProvider?.ToString() : string.Empty; - shellSettings["DatabaseProvider"] = providerName; + shellSettings["DatabaseProvider"] = context.Properties.TryGetValue(SetupConstants.DatabaseProvider, out var databaseProvider) ? databaseProvider?.ToString() : string.Empty; shellSettings["ConnectionString"] = context.Properties.TryGetValue(SetupConstants.DatabaseConnectionString, out var databaseConnectionString) ? databaseConnectionString?.ToString() : string.Empty; shellSettings["TablePrefix"] = context.Properties.TryGetValue(SetupConstants.DatabaseTablePrefix, out var databaseTablePrefix) ? databaseTablePrefix?.ToString() : string.Empty; shellSettings["Schema"] = context.Properties.TryGetValue(SetupConstants.DatabaseSchema, out var schema) ? schema?.ToString() : null; + } - if (providerName == DatabaseProviderValue.Sqlite) - { - shellSettings["DatabaseName"] = context.Properties.TryGetValue(SetupConstants.DatabaseName, out var dbName) ? dbName?.ToString() : "orchardcore.db"; - } + if (shellSettings["DatabaseProvider"] == DatabaseProviderValue.Sqlite && string.IsNullOrEmpty(shellSettings["DatabaseName"])) + { + shellSettings["DatabaseName"] = context.Properties.TryGetValue(SetupConstants.DatabaseName, out var dbName) ? dbName?.ToString() : "orchardcore.db"; } var validationContext = new DbConnectionValidatorContext(shellSettings); From b1592ccc001371dde1750b2e652638f267edcf6c Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 30 Jan 2024 13:32:06 -0800 Subject: [PATCH 3/4] address feedback --- .../Options/SqliteOptions.cs | 10 ---------- .../OrchardCoreBuilderExtensions.cs | 7 +------ .../OrchardCore.Data.YesSql/SqliteHelper.cs | 17 ++++++++--------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs index d48eae72697..cd73cba34ef 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/Options/SqliteOptions.cs @@ -15,15 +15,5 @@ public class SqliteOptions /// /// public bool UseConnectionPooling { get; set; } = true; - - /// - /// Gets the database name. - /// - public string DatabaseName { get; private set; } - - public void SetDatabaseName(string databaseName) - { - DatabaseName = databaseName; - } } } diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs index af694f03eaf..29f043c1a58 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/OrchardCoreBuilderExtensions.cs @@ -79,12 +79,7 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder) var databaseFolder = SqliteHelper.GetDatabaseFolder(shellOptions, shellSettings.Name); Directory.CreateDirectory(databaseFolder); - if (!string.IsNullOrWhiteSpace(shellSettings["DatabaseName"])) - { - sqliteOptions.SetDatabaseName(shellSettings["DatabaseName"]); - } - - var connectionString = SqliteHelper.GetConnectionString(sqliteOptions, databaseFolder); + var connectionString = SqliteHelper.GetConnectionString(sqliteOptions, databaseFolder, shellSettings["DatabaseName"]); storeConfiguration .UseSqLite(connectionString, IsolationLevel.ReadUncommitted) .UseDefaultIdGenerator(); diff --git a/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs b/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs index 561a7ad4533..999a4cc5a1e 100644 --- a/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs +++ b/src/OrchardCore/OrchardCore.Data.YesSql/SqliteHelper.cs @@ -6,23 +6,22 @@ namespace OrchardCore.Data; public static class SqliteHelper { - public static string GetConnectionString(SqliteOptions sqliteOptions, ShellOptions shellOptions, string shellName) => - GetConnectionString(sqliteOptions, GetDatabaseFolder(shellOptions, shellName)); + public static string GetConnectionString(SqliteOptions sqliteOptions, ShellOptions shellOptions, string shellName, string databaseName = "") + => GetConnectionString(sqliteOptions, GetDatabaseFolder(shellOptions, shellName), databaseName); - public static string GetConnectionString(SqliteOptions sqliteOptions, string databaseFolder) + public static string GetConnectionString(SqliteOptions sqliteOptions, string databaseFolder, string databaseName = "") { - // For backward compatibility, we assume that the database name is 'yessql.db'. - // If shellSettings["DatabaseName"] has a value, we use the name provided in the shell settings. - if (string.IsNullOrEmpty(sqliteOptions.DatabaseName)) + if (string.IsNullOrEmpty(databaseName)) { - sqliteOptions.SetDatabaseName("yessql.db"); + // For backward compatibility, we assume that the database name is 'yessql.db'. + databaseName = "yessql.db"; } return new SqliteConnectionStringBuilder { DataSource = string.IsNullOrEmpty(databaseFolder) - ? sqliteOptions.DatabaseName - : Path.Combine(databaseFolder, sqliteOptions.DatabaseName), + ? databaseName + : Path.Combine(databaseFolder, databaseName), Cache = SqliteCacheMode.Shared, Pooling = sqliteOptions.UseConnectionPooling } From b9d6547157f6ffa8e4ddf4c89e2257daa8ad46e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Thu, 1 Feb 2024 11:23:11 -0800 Subject: [PATCH 4/4] Update src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs b/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs index 7f954056ea7..e299c9f5eb4 100644 --- a/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs +++ b/src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs @@ -163,7 +163,7 @@ private async Task SetupInternalAsync(SetupContext context) if (shellSettings["DatabaseProvider"] == DatabaseProviderValue.Sqlite && string.IsNullOrEmpty(shellSettings["DatabaseName"])) { - shellSettings["DatabaseName"] = context.Properties.TryGetValue(SetupConstants.DatabaseName, out var dbName) ? dbName?.ToString() : "orchardcore.db"; + shellSettings["DatabaseName"] = context.Properties.TryGetValue(SetupConstants.DatabaseName, out var dbName) ? dbName?.ToString() : "OrchardCore.db"; } var validationContext = new DbConnectionValidatorContext(shellSettings);