Seeding database during migration fails when using newly added Enum
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Start with the migration flow in EFCore.Relational/Migrations/Internal/Migrator.cs, especially the seeding and ReloadTypes order linked in the issue. Reproduce with the EF Core 9 migration bundle, newly added PostgreSQL enum, and seeder described in the issue; compare the failure before and after calling ReloadTypes. Done means seeding during migration can use the new enum without either reported exception.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
I have a migration in EF Core 9 (package: Npgsql.EntityFrameworkCore.PostgreSQL 9.0.4) adding new enum type:
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:Enum:event_stack_event_status", "closed,new,taken,unknown")
The enum is registered like so:
services.AddDbContext<DatabaseContext>(options =>
{
options.UseNpgsql(
CreateConnString(variables.DatabaseName),
npsqlOptions =>
{
npsqlOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery);
npsqlOptions.MapEnum<EventStackEventStatus>();
});
options.UseDataSeeding();
options.ConfigureWarnings(c => c.Log((RelationalEventId.CommandExecuted, LogLevel.Debug)));
}, ServiceLifetime.Transient);
The UseDataSeeding is my extension simply adding seeder implementation:
public static void UseDataSeeding(this DbContextOptionsBuilder options)
{
options.UseSeeding(
(ctx, storeManagementPerformed) => SeedAsync(ctx, storeManagementPerformed).Wait());
options.UseAsyncSeeding(SeedAsync);
}
Migration is applied via migration bundle. During the seed process, where the enum is used, I'm getting error:
System.NotSupportedException: The data type name 'event_stack_event_status' isn't present in your database. You may need to install an extension or upgrade to a newer version.
As far as I know this is an issue with type cache which doesn't contain new enum mapping. I tried to call ReloadTypes in data seeder on current database connection from database context but it changed error to:
System.InvalidCastException: Writing values of 'EventStackEventStatus' is not supported for parameters having DataTypeName 'public.event_stack_event_status'
I'm aware of this issue: #292 and PR that solving it #2951, but it's not applying here because seeder is called during Migrate method before ReloadTypes is called: https://github.com/dotnet/efcore/blob/main/src/EFCore.Relational/Migrations/Internal/Migrator.cs#L192
The only workaround I see right now is to move data seeding to application start. Is there a way to solve it so I can still use data seeding during migration?
- Linguagem predominante
- C#
- Estrelas
- 1.8k
- Forks
- 268
- Merge médio
- 2h 35min
- PRs com merge (30d)
- 136
Preparar o ambiente
Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de npgsql/efcore.pg
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
NTS: the M ordinate is dropped from geometry SQL literals and from geometries stored in JSONTalvez já em andamento @Ahmed7991 assumiu há 6 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
npgsql/efcore.pg#4093 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
`TimeSpan`/`Duration` component members: negative values are floored, and intervals computed in SQL are read field by fieldTalvez já em andamento @jeremy-morren assumiu há 12 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
Numeric storage parameters are formatted with the current culture, so migrations emit 0,01 instead of 0.01Talvez já em andamento @Sorbitol assumiu há 12 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 30/100
Mantenedores costumam responder em até 1 dia
-
`Contains` on a JSON primitive collection compares JSON text, so `DateTime` and `TimeOnly` items never matchTalvez já em andamento @Mr444-dev assumiu há 8 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
npgsql/efcore.pg#4099 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de npgsql/efcore.pg
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
SubtitleEdit/subtitleedit#16825 ·
Mantenedores costumam responder em até 1 dia
-
ci-flake kind:tests size:S type:bug
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
elsa-workflows/elsa-foundation#4058 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
games-on-whales/wolf-ui#23 ·
-
SkillsAbertawayfinder:grilling
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
DigiBanks99/lopen#37 ·
-
:watch: Not Triaged aspnet-core/svc razor-pages/subsvc Source - Docs.ms
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
dotnet/AspNetCore.Docs#38126 ·
Mantenedores costumam responder em até 1 dia