Skip to content

Commit

Permalink
Exposing the IgnoreIndex() functionality to the public configuation A…
Browse files Browse the repository at this point in the history
…PI. Closes GH-2247
  • Loading branch information
Jeremy D. Miller authored and Jeremy D. Miller committed May 26, 2022
1 parent 0323496 commit f01b4b7
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Linq;
using Marten;
using Marten.Schema;
using Marten.Storage;
using Marten.Testing.Documents;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;

namespace DocumentDbTests.Configuration
{
public class ignoring_indexes_on_document_table : OneOffConfigurationsContext
{
[Fact]
public void index_is_ignored_on_document_table()
{
var mapping = DocumentMapping.For<User>();
mapping.IgnoreIndex("foo");

var table = new DocumentTable(mapping);
table.IgnoredIndexes.Any(x => x == "foo").ShouldBeTrue();
}

[Fact]
public void ignore_index_through_configuration()
{
var store = DocumentStore.For(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.Schema.For<User>().IgnoreIndex("foo");
});

var mapping = store.Options.Storage.MappingFor(typeof(User));
new DocumentTable(mapping).IgnoredIndexes.Single().ShouldBe("foo");
}
}
}
12 changes: 12 additions & 0 deletions src/Marten/MartenRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ internal DocumentMappingExpression(DocumentMappingBuilder<T> builder)
_builder = builder;
}

/// <summary>
/// Direct the schema migration detection to ignore the presence of the
/// named index on the document storage table
/// </summary>
/// <param name="indexName"></param>
/// <returns></returns>
public DocumentMappingExpression<T> IgnoreIndex(string indexName)
{
_builder.Alter = m => m.IgnoreIndex(indexName);
return this;
}

/// <summary>
/// Specify the property searching mechanism for this document type. The default is
/// JSON_Locator_Only
Expand Down
Loading

0 comments on commit f01b4b7

Please sign in to comment.