Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Testing/SqlServerBaseTestDatabase.cs

126 lines
4.4 KiB
C#
Raw Normal View History

v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
using System.Data;
using System.Data.Common;
using System.Linq;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Moq;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Infrastructure.Migrations.Install;
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Tests.Common;
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
namespace Umbraco.Cms.Tests.Integration.Testing;
public abstract class SqlServerBaseTestDatabase : BaseTestDatabase
{
protected UmbracoDatabase.CommandInfo[] _cachedDatabaseInitCommands = new UmbracoDatabase.CommandInfo[0];
protected override void ResetTestDatabase(TestDbMeta meta)
{
using var connection = GetConnection(meta);
connection.Open();
using (var cmd = connection.CreateCommand())
{
// https://stackoverflow.com/questions/536350
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"
declare @n char(1);
set @n = char(10);
declare @stmt nvarchar(max);
-- check constraints
select @stmt = isnull( @stmt + @n, '' ) +
'alter table [' + schema_name(schema_id) + '].[' + object_name( parent_object_id ) + '] drop constraint [' + name + ']'
from sys.check_constraints;
-- foreign keys
select @stmt = isnull( @stmt + @n, '' ) +
'alter table [' + schema_name(schema_id) + '].[' + object_name( parent_object_id ) + '] drop constraint [' + name + ']'
from sys.foreign_keys;
-- tables
select @stmt = isnull( @stmt + @n, '' ) +
'drop table [' + schema_name(schema_id) + '].[' + name + ']'
from sys.tables;
exec sp_executesql @stmt;
";
// rudimentary retry policy since a db can still be in use when we try to drop
Retry(10, () => cmd.ExecuteNonQuery());
}
}
protected static void SetCommand(SqlCommand command, string sql, params object[] args)
{
command.CommandType = CommandType.Text;
command.CommandText = sql;
command.Parameters.Clear();
for (var i = 0; i < args.Length; i++)
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
{
command.Parameters.AddWithValue("@" + i, args[i]);
}
}
protected override DbConnection GetConnection(TestDbMeta meta) => new SqlConnection(meta.ConnectionString);
protected override void RebuildSchema(IDbCommand command, TestDbMeta meta)
{
lock (_cachedDatabaseInitCommands)
{
if (!_cachedDatabaseInitCommands.Any())
{
RebuildSchemaFirstTime(meta);
return;
}
}
foreach (var dbCommand in _cachedDatabaseInitCommands)
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
{
command.CommandText = dbCommand.Text;
command.Parameters.Clear();
foreach (var parameterInfo in dbCommand.Parameters)
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
{
AddParameter(command, parameterInfo);
}
command.ExecuteNonQuery();
}
}
private void RebuildSchemaFirstTime(TestDbMeta meta)
{
_databaseFactory.Configure(meta.ToStronglyTypedConnectionString());
using (var database = (UmbracoDatabase)_databaseFactory.CreateDatabase())
{
database.LogCommands = true;
using (var transaction = database.GetTransaction())
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
{
var options =
new TestOptionsMonitor<InstallDefaultDataSettings>(
new InstallDefaultDataSettings { InstallData = InstallDefaultDataOption.All });
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
var schemaCreator = new DatabaseSchemaCreator(
database,
_loggerFactory.CreateLogger<DatabaseSchemaCreator>(),
_loggerFactory,
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
new UmbracoVersion(),
Mock.Of<IEventAggregator>(),
options);
v10 SQLite support + distributed locking abstractions (#11922) * Created Persistence.SQLite project skeleton. * SQLite database initialization * Various changes and hacks to make things work. * WIP integration tests * Fix thread safety tests * Fix tests that relied on tie breaker sorting. Spent a fair amount of time looking for a less lazy fix but gave up. * Convert right join to left join ContentTypeRepository.PerformGetByQuery SQLite doesn't support right join * Fix test Can_Generate_Delete_SubQuery_Statement Worth noting that NPoco.DatabaseTypes.SQLiteDatabaseType doesn't override EscapeSqlIdentifier so NPoco will escape with []. SQLite docs say > "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility." Also could have updated SqliteSyntaxProvider to match npoco but decided against it. * Fixes for paginated custom order by * Fix tests broken by lack of unique indexes. * Fix SqlServerTableByTableTest tests. These tests didn't actually do anything as the tables already exist so schema creator just returned. Did however point out that the default implementation for DoesTableExist just returns false so added a default naive implementation. * Fix ValidateLoginSession - SelectTop must come later * dry up database cleanup * Fix up db migration tests. We can't drop pk in sqlite without recreating table. Test looks to be testing that add column works as intended which we can test. * Prevent schema creation errors. * SQLite ignore lock tests, WAL back on. * Fix package schema tests * Fix NPocoFetchTests - case sensitivity not under test * Fix AdvancedMigrationTests (where possible) Migrations probably need a good look later. Maybe nuke old migrations and only support moving to v10 from v9. If we do that can do some cleanup. * Cleanup test database configuration * Run integration tests against SQLite on build agent. * Drop MS.Data.SQLite System.Data.SQLite was quicker to roll out due to more CLR type mapping * YAML * Skip Umbraco.Tests.Integration.SqlCe * Drop SqlServerTableByTable tests. Until this week they did nothing anyway as they with NewSchemaPerTest so the tests all passed as CreateTable was no op (already exists). Also all of the tables are created in an empty database by SchemaValidationTest.cs DatabaseSchemaCreation_Produces_DatabaseSchemaResult_With_Zero_Errors * Might aswell run against macOS also. * Copy azure pipelines task header layout * Delete SQLCe projects * Remove SQL CE specific code. * Remove SQL CE NuSpec, template params, build script setup * Delete umbraco-netcore-only.sln * Add SkipTests solution configuration and use for codeql * Remove reference to deleted nuspec file. * Refactor ConnectionStrings WRT DataDirectory placeholder & ProviderName. At this point you can try out SQLite support by setting the following in appsettings.json and then completing the install process. "ConnectionStrings": { "umbracoDbDSN": "Data Source=|DataDirectory|/umbraco.sqlite", "umbracoDbDSN_ProviderName": "System.Data.SQLite" }, Not currently possible via installer UI without provider name pre-set in configuration. * Switch to Microsoft.Data.Sqlite Some gross hacks but will be good to find out if this works with apple silicon. * Enable selection of SQLite via installer UI (also quick install) * Remove SqlServerDbProviderFactoryCreator to cleanup a TODO * Move SQL Server support to its own class library * Add persistence dependencies to Umbraco.CMS metapackage * Bugfix packages delete query Created invalid query for SQLite. * Try out cypress tests Linux + SQLite * Prevent cypress test artifact upload failure on attempt 2+ * LocalDb bugfixes * Drop redundant enum * Move SqlClient constant * Misc whitespace * Remove IsSqlCe extension (TODO: drop non 9->10 migrations later). * Umbraco.Persistence.* -> Umbraco.Cms.Persistence.* * Display quick install defaults and per provider default database name. * Misc remove old comment * little re-arrange * Remove almost all usages of IsSqlite extension. * visual adjustments * Custom Database Configuration is last step and should then say Install. * use text instead of disabled inputs * move legend, rename to Install * Update SqlMainDomLock to work without distributed locks. * Added IDistributedLockingMechanism interface and in memory impl. * Drop locking from ISqlSyntaxProvider & wire up scope to abstraction. * Added SqlServerDistributedLockingMechanism * Move distributed locking interfaces and exceptions to Core + xmldocs. * Fix tests, Misc cleanup, Add SQL distributed locking integration tests * Provide mechanism to specify DistributedLockingMechanism in config (even if added by composer) * Nomplementation -> NoImplementation * Fix misleading comment * Integration tests use SqlServerDistributedLockingMechanism when possible * Handle up-gradable locks SqlServerDistributedLockingMechanism. TODO: InMemoryDistributedLockingMechanism. Note: Nuked SqlServerDistributedLockingMechanismTests, will still sleep at night. Is covered by Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.LockTests * Make tests pass for InMemoryDistributedLockingMechanism, pretty hacky. * Tweak constraints on WithCollectionBuilder so i can drop bad constructor * Added SqliteDistributedLockingMechanism * Dropped InMemoryDistributedMechanism + magic InMemoryDistributedMechanism was pretty rubbish and now we have a decent implementation for SQLite as we no longer block readers see 8d1f42b. Also drop the CollectionBuilder setup, instead do the same as we do for syntax providers etc, it's more automagical so we never require an explicit selection although we are allowing for it. However keeping the optional IUmbracoBuilder constructor param for CollectionBuilders as it's extremely useful. * Fix quick install "" database name. * Hide Database Configuration section when a connection string is pre-set. Doesn't seem worth it to extract db name from connection string. * Ensure wal test 2+ * Fix logging inconsistencies. * Ensure in transaction when obtaining locks + no-op the SQLite read lock. There's no point in running the query just to make a single test pass. * Fix installer database display names * Allow SQLite shared cache without losing deferred transactions * Opt into shared cache for new SQLite databases + fix filename * Fix misc inconsistency in .gitignore * Prefer our interceptor interface * Restore DEBUG_DATABASES code OnConnectionOpened in case it's used. * Back to private cache. * Added retry strategy for SQLite + refactor out SQL server specific stuff * Fix SQL server tests. * Misc - Orphaned comment, incorrect casing. * InMemory SQLite test database & turn shared cache back on everywhere. Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
2022-03-11 16:14:20 +00:00
schemaCreator.InitializeDatabaseSchema();
transaction.Complete();
_cachedDatabaseInitCommands = database.Commands
.Where(x => !x.Text.StartsWith("SELECT ", StringComparison.OrdinalIgnoreCase))
.ToArray();
}
}
}
}