Skip to content

refactor(dal): unblock EF Core migration generation — ProjectVDbContext model validation #346

@Vasar007

Description

@Vasar007

Summary: EF Core 10's model validator rejects ProjectVDbContext at first access — MigrateAsync, EnsureCreatedAsync, and any LINQ / raw-SQL query through DbSet all hit the same validator:

The 'RefreshTokenDbInfo' property 'UserDbInfo.RefreshToken' could not be mapped because the database provider does not support this type.

UserDbInfoConfiguration.Configure mapped a navigation-typed property (RefreshTokenDbInfo? RefreshToken) as an EF scalar via builder.Property(e => e.RefreshToken). The reverse fix — builder.Ignore or [NotMapped] — surfaces a follow-on binding error because the only constructor on UserDbInfo takes RefreshTokenDbInfo? refreshToken, and EF's constructor binder cannot bind a navigation parameter to a mapped scalar.

A partial fix landed during Phase 2 at the UserDbInfo ctor level (a 6-arg internal ctor that EF can bind + [NotMapped] on the RefreshToken property) — enough to make the test-side raw-SQL channel viable, but NOT enough to make migration generation work.

Where

  • Sources/Libraries/ProjectV.DataAccessLayer/Services/Users/UserDbInfoConfiguration.cs — the Configure method.
  • Sources/Libraries/ProjectV.DataAccessLayer/Services/Users/Models/UserDbInfo.cs — constructor shape + the [NotMapped] partial fix.
  • Sources/Libraries/ProjectV.DataAccessLayer/Services/Tokens/Models/RefreshTokenDbInfo.csWrappedUserId is never assigned by any ctor (always default(UserId)).
  • Sources/Libraries/ProjectV.DataAccessLayer/Migrations/.gitkeep — placeholder for the future InitialCreate migration once the model is clean.
  • Sources/WebServices/ProjectV.ProcessingWebService/Program.cs — currently calls EnsureCreatedAsync guarded by CanUseDatabase=false in appsettings.json; the production schema story.

Workaround in place (test-side only)

The Phase 2 DAL integration suite bypasses EF entirely — Sources/Tests/ProjectV.DataAccessLayer.Tests/ForTests/DbCollectionFixture.cs issues raw CREATE TABLE statements through Npgsql.NpgsqlConnection directly; the per-test TRUNCATE flows through the same channel. The dotnet-ef 10.0.8 tooling + ProjectVDbContextDesignTimeFactory : IDesignTimeDbContextFactory<…> are installed and committed so the next attempt at dotnet ef migrations add InitialCreate can run without re-bootstrapping.

Decisions needed before unblocking

  1. Should UserDbInfo.RefreshToken be removed entirely (the live token row lives in tokens keyed on RefreshTokenDbInfo.UserId) OR turned into an explicit HasOne()...WithOne() relationship?
  2. What to do with RefreshTokenDbInfo.WrappedUserId — currently always default(UserId) because no ctor assigns it.
  3. Does the production app keep EnsureCreatedAsync as its schema story, or move to migrations?

Acceptance

Surfaced by

Phase 2 Test Coverage (milestone v0.9.8) — DAL integration slice on ProjectV.DataAccessLayer.Tests. Companion to #339 (token-uniqueness decision) and #340 (tokens.user_name rename, which is blocked on this unblocking).

Metadata

Metadata

Assignees

Labels

area: Core LibraryRelated tot the core librarytype: Code MaintenanceNew feature/requirement which is targeting on improve architecture, realization and code style

Projects

Status

To do

Relationships

None yet

Development

No branches or pull requests

Issue actions