Skip to content

Is ApplyAllDatabaseChangesOnStartup required for Initial Baseline Data? #219

Description

@marcominerva

Following the instructions available at https://polecat.jasperfx.net/documents/initial-data.html, I have defined the following configuration:

builder.Services.AddPolecat(options =>
{
    options.ConnectionString = "...";   

    options.InitialData.Add(new SeedUsers());
});

public class SeedUsers : IInitialData
{
    public async Task Populate(IDocumentStore store, CancellationToken cancellationToken)
    {
        await using var session = store.LightweightSession();

        if (await session.Query<User>().AnyAsync(cancellationToken))
        {
            return;
        }

        var roles = new[] { "Administrator", "User", "Manager", "Reviewer", "Contributor" };

        var faker = new Faker<User>("en")
            .RuleFor(u => u.Id, _ => Guid.NewGuid())
            .RuleFor(u => u.FirstName, f => f.Name.FirstName())
            .RuleFor(u => u.LastName, f => f.Name.LastName());

        session.Store(faker.Generate(50).ToArray());

        await session.SaveChangesAsync(cancellationToken);
    }
}

However, I have verified that the seeding is not executed unless I call the ApplyAllDatabaseChangesOnStartup method after AddPolecat. When I do so, I notice that additional tables are created in the database besides pc_doc_user:

Image

On the other hand, if I do not call the ApplyAllDatabaseChangesOnStartup method, even if the seeding does not run, when I try to work with the User documents, only the pc_doc_user table is created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions