JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.79k stars 441 forks source link

Unable to create and ingore custom index for mt_events table #3193

Closed zhenyi2697 closed 3 months ago

zhenyi2697 commented 3 months ago

Version: Marten 6.0.5 Languages: C#/.Net

Issue description: Hi, I'm trying to create a custom index in the built in mtevents table. According to the documentation here: https://marten-docs-v6.netlify.app/documents/indexing/, I should be able to do that if I don't prefix the index name with `mt` prefix, however, when I tried to run the following SQL on our DB:

CREATE INDEX IF NOT EXISTS custom_events_idx_timestamp ON dbo.mt_events ("timestamp");

The schema check still fails with the following error:

Unhandled exception. Weasel.Core.Migrations.DatabaseValidationException: Configuration to Schema Validation for Database 'Marten' Failed! These changes detected: drop index if exists dbo.custom_events_idx_timestamp; at Weasel.Core.Migrations.DatabaseBase`1.AssertDatabaseMatchesConfigurationAsync(CancellationToken ct) at Marten.Services.MartenActivator.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Start(IHost host)

I have the following set up for my DocumentStore:

options.AutoCreateSchemaObjects = AutoCreate.None;
options.GeneratedCodeMode = TypeLoadMode.Auto;

And this method when register Marten service:

.AssertDatabaseMatchesConfigurationOnStartup()

I expect not having mt_ prefix for built-in table could skip the schema checking, but seems it's not the case. Any suggestion on how to unblock the custom index creation would be helpful. Thank you.

jeremydmiller commented 3 months ago

And the docs are long out of date. As of v4, Marten is going to insist on owning all indexes. I'll try to find and correct the documentation