diff --git a/src/DocumentDbTests/Indexes/NgramSearchTests.cs b/src/DocumentDbTests/Indexes/NgramSearchTests.cs index ddda5a0b32..8549817d7e 100644 --- a/src/DocumentDbTests/Indexes/NgramSearchTests.cs +++ b/src/DocumentDbTests/Indexes/NgramSearchTests.cs @@ -44,8 +44,6 @@ public async Task test_ngram_search_returns_data() var store = DocumentStore.For(_ => { _.Connection(Marten.Testing.Harness.ConnectionSource.ConnectionString); - - // This creates _.Schema.For().NgramIndex(x => x.UserName); }); @@ -83,7 +81,6 @@ public async Task test_ngram_search_returns_data_using_db_schema() var store = DocumentStore.For(_ => { _.Connection(Marten.Testing.Harness.ConnectionSource.ConnectionString); - _.DatabaseSchemaName = "ngram_test"; // This creates an ngram index for efficient sub string based matching @@ -118,11 +115,10 @@ public async Task test_ngram_search_returns_data_using_db_schema() [Fact] public async Task test_ngram_on_nested_prop_search_returns_data() - { +{ var store = DocumentStore.For(_ => { _.Connection(Marten.Testing.Harness.ConnectionSource.ConnectionString); - // This creates _.Schema.For().NgramIndex(x => x.Address.Line1); }); @@ -164,8 +160,6 @@ public async Task test_ngram_when_using_non_ascii_characters(){ }); await using var session = store.LightweightSession(); - - //The ngram uðmu should only exist in bjork, if special characters ignored it will return Umut var umut = new User(1, "Umut Aral"); var bjork = new User(2, "Björk Guðmundsdóttir"); diff --git a/src/Marten/Schema/DocumentSchema.cs b/src/Marten/Schema/DocumentSchema.cs index 83b49a0457..948b64c07f 100644 --- a/src/Marten/Schema/DocumentSchema.cs +++ b/src/Marten/Schema/DocumentSchema.cs @@ -46,7 +46,7 @@ public DocumentSchema(DocumentMapping mapping) public IEnumerable DependentTypes() { yield return typeof(SystemFunctions); - + yield return typeof(RequiredExtensions); foreach (var referencedType in _mapping.ReferencedTypes()) yield return referencedType; } diff --git a/src/Marten/Storage/RequiredExtensions.cs b/src/Marten/Storage/RequiredExtensions.cs new file mode 100644 index 0000000000..efc7c08238 --- /dev/null +++ b/src/Marten/Storage/RequiredExtensions.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Weasel.Core; +using Weasel.Core.Migrations; +using Weasel.Postgresql; + +namespace Marten.Storage; + +internal class RequiredExtensions: IFeatureSchema +{ + private readonly StoreOptions _options; + + public RequiredExtensions(StoreOptions options) + { + _options = options; + } + + public ISchemaObject[] Objects => [new Extension("unaccent")]; + + public string Identifier => "requiredextensions"; + + public Migrator Migrator => _options.Advanced.Migrator; + + public Type StorageType => typeof(RequiredExtensions); + + public IEnumerable DependentTypes() + { + yield break; + } + + public void WritePermissions(Migrator rules, TextWriter writer) + { + //Nothing + } +} diff --git a/src/Marten/Storage/StorageFeatures.cs b/src/Marten/Storage/StorageFeatures.cs index 747e805359..ca39a29704 100644 --- a/src/Marten/Storage/StorageFeatures.cs +++ b/src/Marten/Storage/StorageFeatures.cs @@ -42,6 +42,7 @@ internal StorageFeatures(StoreOptions options) _options = options; SystemFunctions = new SystemFunctions(options); + RequiredExtensions = new RequiredExtensions(options); } /// @@ -50,6 +51,7 @@ internal StorageFeatures(StoreOptions options) public List ExtendedSchemaObjects { get; } = new(); internal SystemFunctions SystemFunctions { get; } + internal RequiredExtensions RequiredExtensions{get;} internal IEnumerable AllDocumentMappings => _documentMappings.Value.Enumerate().Select(x => x.Value); @@ -262,6 +264,7 @@ public IFeatureSchema FindFeature(Type featureType) internal void PostProcessConfiguration() { + Add(RequiredExtensions); SystemFunctions.AddSystemFunction(_options, "mt_immutable_timestamp", "text"); SystemFunctions.AddSystemFunction(_options, "mt_immutable_timestamptz", "text"); SystemFunctions.AddSystemFunction(_options, "mt_immutable_time", "text"); @@ -278,7 +281,7 @@ internal void PostProcessConfiguration() SystemFunctions.AddSystemFunction(_options, "mt_jsonb_move", "jsonb,text[],text"); SystemFunctions.AddSystemFunction(_options, "mt_jsonb_path_to_array", "text,char(1)"); SystemFunctions.AddSystemFunction(_options, "mt_jsonb_remove", "jsonb,text[],jsonb"); - SystemFunctions.AddSystemFunction(_options, "mt_jsonb_patch", "jsonb,jsonb"); + SystemFunctions.AddSystemFunction(_options, "mt_jsonb_patch", "jsonb,jsonb"); Add(SystemFunctions); @@ -303,6 +306,7 @@ internal void PostProcessConfiguration() internal IEnumerable AllActiveFeatures(IMartenDatabase database) { + yield return RequiredExtensions; yield return SystemFunctions; if (_options.Events.As().IsActive(_options))