Skip to content

chore: update EF Core packages and add dev tooling#8

Merged
simanga-dev merged 3 commits into
masterfrom
chore/update
Apr 7, 2026
Merged

chore: update EF Core packages and add dev tooling#8
simanga-dev merged 3 commits into
masterfrom
chore/update

Conversation

@simanga-dev
Copy link
Copy Markdown
Owner

@simanga-dev simanga-dev commented Feb 25, 2026

  • Updated Npgsql packages to 10.x for EF Core 10 compatibility
  • Removed legacy EntityFramework 6.x package
  • Fixed duplicate AddDbContext registration
  • Added design-time DbContext factory for EF migrations
  • Added justfile with common dev commands
  • Added .envrc for direnv support

Summary by CodeRabbit

  • Chores

    • Upgraded target framework to .NET 10 and updated NuGet packages; removed legacy EF6 dependency.
    • Added a design-time DB context factory for identity.
    • Added EF Core migration and updated model snapshot to adjust identity column types and discriminator mapping.
    • Removed duplicate identity DB registration.
  • Infrastructure

    • Added development automation tasks for running, building, migrations, Docker, and cleanup.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Adds a design-time EF Core DbContext factory, upgrades the project and EF/Npgsql packages to .NET 10, introduces a migration and updated model snapshot adjusting identity column types and discriminator, removes a duplicate DbContext registration in startup, and adds a justfile with development tasks.

Changes

Cohort / File(s) Summary
Project & Packages
CarpentryShop.csproj
TargetFramework → net10.0, removed legacy EntityFramework, updated ASP.NET Core, EF Core, EF tools, Npgsql and related package versions to 10.x.
Design-time EF Core
Areas/Identity/Data/DesignTimeDbContextFactory.cs
New DesignTimeDbContextFactory implementing IDesignTimeDbContextFactory<CarpentryShopIdentityDbContext> that reads DB_CONNECTION and configures UseNpgsql.
Migrations (migration + designer)
Migrations/20260225143925_UpdateModels.cs, Migrations/20260225143925_UpdateModels.Designer.cs
New migration UpdateModels: changes four Identity token/login columns from varchar(128) to text. Designer defines model entities (Box, Order, OrderBox, Product) and Identity schema.
Model Snapshot
Migrations/CarpentryShopIdentityDbContextModelSnapshot.cs
Product version → 10.0.3; discriminator changed to HasDiscriminator<string>("Discriminator"); Identity login/token columns updated to text (removed 128-length constraints).
Startup
Program.cs
Removed duplicate registration of CarpentryShopIdentityDbContext; consolidated AddDbContext with UseNpgsql.
Developer tooling
justfile
Added justfile with recipes: run, watch, build, restore, migrations helpers, db-update/rollback/status, docker-build/up/down, clean, and related tasks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐇 I nibble code and hop with glee,
New factories, migrations — whee!
Packages polished, snapshots neat,
Justfile recipes make devs upbeat,
A little rabbit’s hop toward harmony.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: updating EF Core and related packages to version 10, and adding development tooling (justfile and design-time factory).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/update

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
Program.cs (1)

13-16: Consider using InvalidOperationException instead of the base Exception.

Throwing System.Exception makes it harder for callers (or global exception handlers) to distinguish configuration errors from other failures. A more specific type like InvalidOperationException better communicates intent and is consistent with the factory class added in this PR.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Program.cs` around lines 13 - 16, Replace the generic throw new Exception in
Program.cs when connectionString is empty with a more specific
InvalidOperationException to clearly signal a configuration error; update the
throw site that checks string.IsNullOrEmpty(connectionString) so it throws new
InvalidOperationException with the same descriptive message (or include nameof
for the environment variable) to match the factory-class style used elsewhere.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CarpentryShop.csproj`:
- Around line 5-6: The XML comment on the csproj is doubly-escaped and
unreadable; replace or remove the garbled comment node so the project file
contains a normal XML comment or none at all. Locate the RuntimeIdentifier
element and the adjacent commented line (the node that contains "&lt;!&ndash; 
This line is the temp fix  &ndash;&gt;") and either delete that commented node
or rewrite it as a standard XML comment such as <!-- This line is the temp fix
--> so it renders correctly and no HTML entities remain.

In `@Program.cs`:
- Around line 42-45: The code registers UseHttpsRedirection middleware twice in
non-development mode: once guarded by app.Environment.IsDevelopment() (negated)
and once unconditionally; remove the duplicate by deleting the unconditional
call to app.UseHttpsRedirection() so the middleware is only added when
!app.Environment.IsDevelopment(); locate the unconditional
app.UseHttpsRedirection() invocation (the second occurrence) and remove it,
leaving the existing guarded block (if (!app.Environment.IsDevelopment()) {
app.UseHttpsRedirection(); }) intact.
- Around line 59-65: The startup code is calling Database.EnsureCreated() which
conflicts with EF Core migrations; update the scope block that obtains
CarpentryShopIdentityDbContext via app.Services.CreateScope() to either remove
the EnsureCreated call entirely (so the justfile/db-update handles migrations)
or replace context.Database.EnsureCreated() with context.Database.Migrate() to
apply migrations at startup; ensure you keep the same scope/service resolution
(CreateScope, GetRequiredService<CarpentryShopIdentityDbContext>) and only
change the Database.* call accordingly.

---

Nitpick comments:
In `@Program.cs`:
- Around line 13-16: Replace the generic throw new Exception in Program.cs when
connectionString is empty with a more specific InvalidOperationException to
clearly signal a configuration error; update the throw site that checks
string.IsNullOrEmpty(connectionString) so it throws new
InvalidOperationException with the same descriptive message (or include nameof
for the environment variable) to match the factory-class style used elsewhere.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a484db9 and 07299b4.

📒 Files selected for processing (7)
  • Areas/Identity/Data/DesignTimeDbContextFactory.cs
  • CarpentryShop.csproj
  • Migrations/20260225143925_UpdateModels.Designer.cs
  • Migrations/20260225143925_UpdateModels.cs
  • Migrations/CarpentryShopIdentityDbContextModelSnapshot.cs
  • Program.cs
  • justfile

Comment thread CarpentryShop.csproj Outdated
Comment thread Program.cs
Comment on lines +42 to +45
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

UseHttpsRedirection is invoked twice in non-development mode.

Lines 42–45 call UseHttpsRedirection() when !IsDevelopment(), and line 67 calls it unconditionally. In production this means the middleware runs twice. Remove one of the two calls.

Proposed fix — remove the unconditional call
-app.UseHttpsRedirection();
-
 app.UseStaticFiles();

Also applies to: 67-67

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Program.cs` around lines 42 - 45, The code registers UseHttpsRedirection
middleware twice in non-development mode: once guarded by
app.Environment.IsDevelopment() (negated) and once unconditionally; remove the
duplicate by deleting the unconditional call to app.UseHttpsRedirection() so the
middleware is only added when !app.Environment.IsDevelopment(); locate the
unconditional app.UseHttpsRedirection() invocation (the second occurrence) and
remove it, leaving the existing guarded block (if
(!app.Environment.IsDevelopment()) { app.UseHttpsRedirection(); }) intact.

Comment thread Program.cs
Comment on lines +59 to +65
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<CarpentryShopIdentityDbContext>();
context.Database.EnsureCreated();
// DbInitializer.Initialize(context);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

EnsureCreated() conflicts with EF Core migrations.

Database.EnsureCreated() creates the schema without recording anything in the migration history table. If it runs before migrations, subsequent dotnet ef database update calls will fail because the tables already exist but __EFMigrationsHistory is empty. This directly conflicts with the migrations added in this PR and the justfile db-update/migrate commands.

Replace with Database.Migrate() if you want auto-migration at startup, or remove this block entirely and rely on the justfile's db-update recipe to apply migrations explicitly.

Proposed fix
 using (var scope = app.Services.CreateScope())
 {
     var services = scope.ServiceProvider;
     var context = services.GetRequiredService<CarpentryShopIdentityDbContext>();
-    context.Database.EnsureCreated();
+    context.Database.Migrate();
     // DbInitializer.Initialize(context);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Program.cs` around lines 59 - 65, The startup code is calling
Database.EnsureCreated() which conflicts with EF Core migrations; update the
scope block that obtains CarpentryShopIdentityDbContext via
app.Services.CreateScope() to either remove the EnsureCreated call entirely (so
the justfile/db-update handles migrations) or replace
context.Database.EnsureCreated() with context.Database.Migrate() to apply
migrations at startup; ensure you keep the same scope/service resolution
(CreateScope, GetRequiredService<CarpentryShopIdentityDbContext>) and only
change the Database.* call accordingly.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
CarpentryShop.csproj (2)

23-24: Remove unused Npgsql package reference.

Npgsql.EntityFrameworkCore.PostgreSQL includes Npgsql as a transitive dependency. No direct usage of Npgsql APIs was found in the codebase—all references are to Npgsql.EntityFrameworkCore.PostgreSQL.Metadata in migration files. Remove the direct reference to Npgsql to avoid unnecessary dependency bloat.

Cleanup
-    <PackageReference Include="Npgsql" Version="10.0.0" />
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CarpentryShop.csproj` around lines 23 - 24, Remove the unnecessary direct
PackageReference to Npgsql (the line with PackageReference Include="Npgsql"
Version="10.0.0") from the project file because Npgsql is already provided
transitively by Npgsql.EntityFrameworkCore.PostgreSQL; keep the existing
PackageReference to Npgsql.EntityFrameworkCore.PostgreSQL
(Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0") and run a
restore/build to verify nothing else directly depends on Npgsql.

21-22: Mark dev-only tooling packages as private assets.

At lines 21–22, both Microsoft.EntityFrameworkCore.Tools and Microsoft.VisualStudio.Web.CodeGeneration.Design are design-time-only packages. Adding PrivateAssets=all prevents them from flowing into runtime or publish dependency graphs—a recommended practice for .NET 10 ASP.NET Core projects.

Proposed change
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.3" />
-    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="10.0.2" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.3">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
+    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="10.0.2">
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+    </PackageReference>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CarpentryShop.csproj` around lines 21 - 22, Update the two design-time
package references so they don't flow into runtime/publish graphs: modify the
PackageReference entries for Microsoft.EntityFrameworkCore.Tools and
Microsoft.VisualStudio.Web.CodeGeneration.Design to include PrivateAssets="all"
(and optionally IncludeAssets/ExcludeAssets if desired) so they remain dev-only;
locate and change the PackageReference elements named
Microsoft.EntityFrameworkCore.Tools and
Microsoft.VisualStudio.Web.CodeGeneration.Design to add the PrivateAssets
attribute.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CarpentryShop.csproj`:
- Around line 3-6: Update CI and container SDK versions to match the project
TargetFramework value net10.0: change the workflow variable named dotnet-version
from 8.0.x to 10.0.x and update the Docker base image tag from
mcr.microsoft.com/dotnet/sdk:8.0 to mcr.microsoft.com/dotnet/sdk:10.0. In the
project file remove the explicit Npgsql PackageReference (the EF provider
supplies it transitively) and mark the tooling PackageReference entries for
Microsoft.EntityFrameworkCore.Tools and
Microsoft.VisualStudio.Web.CodeGeneration.Design with PrivateAssets="all" so
they do not flow as transitive dependencies.

---

Nitpick comments:
In `@CarpentryShop.csproj`:
- Around line 23-24: Remove the unnecessary direct PackageReference to Npgsql
(the line with PackageReference Include="Npgsql" Version="10.0.0") from the
project file because Npgsql is already provided transitively by
Npgsql.EntityFrameworkCore.PostgreSQL; keep the existing PackageReference to
Npgsql.EntityFrameworkCore.PostgreSQL
(Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0") and run a
restore/build to verify nothing else directly depends on Npgsql.
- Around line 21-22: Update the two design-time package references so they don't
flow into runtime/publish graphs: modify the PackageReference entries for
Microsoft.EntityFrameworkCore.Tools and
Microsoft.VisualStudio.Web.CodeGeneration.Design to include PrivateAssets="all"
(and optionally IncludeAssets/ExcludeAssets if desired) so they remain dev-only;
locate and change the PackageReference elements named
Microsoft.EntityFrameworkCore.Tools and
Microsoft.VisualStudio.Web.CodeGeneration.Design to add the PrivateAssets
attribute.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07299b4 and 139b1a9.

📒 Files selected for processing (1)
  • CarpentryShop.csproj

Comment thread CarpentryShop.csproj
Comment on lines +3 to +6
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier> <!-- &lt;!&ndash; This line is the temp fix &ndash;&gt; -->
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<AllowMissingPrunePackageData>true</AllowMissingPrunePackageData>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Target frameworks =="
rg -nP --glob '*.csproj' '<TargetFramework>[^<]+</TargetFramework>|<TargetFrameworks>[^<]+</TargetFrameworks>'

echo "== global.json =="
fd -HI '^global\.json$' -x sh -c 'echo "--- {} ---"; cat "{}"'

echo "== CI dotnet setup =="
rg -n --glob '*.yml' --glob '*.yaml' 'setup-dotnet|dotnet-version|10\.0|net10\.0'

Repository: simanga-dev/carpentry-shop

Length of output: 203


🏁 Script executed:

# Check for direct Npgsql API usage
echo "== Searching for Npgsql usage in codebase =="
rg -n 'using Npgsql|Npgsql\.' --type cs -A 2

Repository: simanga-dev/carpentry-shop

Length of output: 999


🏁 Script executed:

# List all files to understand structure
echo "== Repository structure =="
git ls-files | head -20

Repository: simanga-dev/carpentry-shop

Length of output: 816


🏁 Script executed:

cat -n .github/workflows/dotnet.yml

Repository: simanga-dev/carpentry-shop

Length of output: 1528


🏁 Script executed:

cat -n Dockerfile

Repository: simanga-dev/carpentry-shop

Length of output: 605


Update CI and Docker SDK to .NET 10 to match target framework.

The project targets net10.0 but CI workflow and Dockerfile are pinned to SDK 8.0. Build and restore will fail:

  • .github/workflows/dotnet.yml line 20: change dotnet-version: 8.0.x10.0.x
  • Dockerfile line 3: change mcr.microsoft.com/dotnet/sdk:8.0mcr.microsoft.com/dotnet/sdk:10.0

Additionally, remove the explicit Npgsql package reference (line 23 in CarpentryShop.csproj) — the provider package brings it transitively and only EFCore metadata imports are used in the codebase. Mark dev-time tooling packages (Microsoft.EntityFrameworkCore.Tools, Microsoft.VisualStudio.Web.CodeGeneration.Design) as PrivateAssets="all" to prevent transitive dependency leakage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CarpentryShop.csproj` around lines 3 - 6, Update CI and container SDK
versions to match the project TargetFramework value net10.0: change the workflow
variable named dotnet-version from 8.0.x to 10.0.x and update the Docker base
image tag from mcr.microsoft.com/dotnet/sdk:8.0 to
mcr.microsoft.com/dotnet/sdk:10.0. In the project file remove the explicit
Npgsql PackageReference (the EF provider supplies it transitively) and mark the
tooling PackageReference entries for Microsoft.EntityFrameworkCore.Tools and
Microsoft.VisualStudio.Web.CodeGeneration.Design with PrivateAssets="all" so
they do not flow as transitive dependencies.

@simanga-dev simanga-dev merged commit b38432d into master Apr 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant