Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DuplicateField] on a property named Time causes the index to be recreated on every run #2414

Closed
alexrp opened this issue Dec 4, 2022 · 1 comment · Fixed by JasperFx/weasel#77

Comments

@alexrp
Copy link

alexrp commented Dec 4, 2022

Haven't created an isolated repro yet, but here's roughly what the situation looks like:

public sealed class Article
{
    public required string Id { get; set; }

    public required string Title { get; set; }

    public required string Content { get; set; }

    [DuplicateField(NotNull = false, IndexSortOrder = SortOrder.Desc)]
    public required Instant Time { get; set; }
}

Configuration:

services
    .AddMarten(opts =>
    {
        opts.SourceCodeWritingEnabled = false;

        opts.RegisterDocumentTypes(
            typeof(Article)
                .Assembly
                .ExportedTypes
                .Where(t => t is
                {
                    IsClass: true,
                    IsAbstract: false,
                    IsNested: false,
                }));

        opts.UseDefaultSerialization(
            casing: Casing.SnakeCase,
            collectionStorage: CollectionStorage.AsArray,
            serializerType: SerializerType.SystemTextJson);
        opts.UseNodaTime();

        opts.Connection("...");
        opts.RetryPolicy(DefaultRetryPolicy.Times(5));

        opts.AutoCreateSchemaObjects = AutoCreate.All;
    })
    .UseLightweightSessions()
    .ApplyAllDatabaseChangesOnStartup()
    .AssertDatabaseMatchesConfigurationOnStartup()
    .Services;

This results in:

[23:58:09.662][INF][Marten.IDocumentStore][0] Executed schema update SQL:
                                                                         drop index if exists public.mt_doc_article_idx_time;
CREATE INDEX mt_doc_article_idx_time ON public.mt_doc_article USING btree (time DESC);

Unhandled exception. Weasel.Core.Migrations.DatabaseValidationException: Configuration to Schema Validation for Database 'Marten' Failed! These changes detected:

                     drop index if exists public.mt_doc_article_idx_time;
CREATE INDEX mt_doc_article_idx_time ON public.mt_doc_article USING btree (time DESC);

From what I can gather, it's the property name that's the issue; changing it to e.g. ArticleTime makes things work as expected.

@mysticmind
Copy link
Member

When using a Postgres keyword as a column name, assertion to validate the index definition fails since the column name is returned with double quotes.

Added a fix in Weasel JasperFx/weasel#77.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants