mcpField
D
d1-04-db-config

d1-04-db-config

github.com/softinter-chiangraiDevelopment046 installsUpdated 9w ago
Repository

About d1-04-db-config

A project skill for configuring a PostgreSQL connection in an ASP.NET Core API with Entity Framework Core. It distinguishes the host connection string used by EF CLI from the container connection string and notes that this step requires no redeployment.

Key features

  1. 01Add Npgsql EF Core packages
  2. 02Set the development connection string
  3. 03Register AppDbContext with UseNpgsql
  4. 04Keep host and container connection strings distinct

Use cases

  1. 01Configure an API to connect to PostgreSQL
  2. 02Prepare an EF Core project for database migrations

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/softinter-chiangrai/up-ai-skill-training --skill d1-04-db-config

After installing, type/d1-04-db-configin Claude Code to confirm it loaded.

Details

From the project README

Day 1 · Step 4 — Configure the DB connection (no redeploy)

cd up-api
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
dotnet add package Microsoft.EntityFrameworkCore.Design

appsettings.Development.json:

{
  "ConnectionStrings": {
    "Default": "Host=localhost;Port=5432;Database=up_db;Username=upadmin;Password=uppass"
  }
}

Use localhost here because EF CLI commands (next steps) run from the host. Inside the up-api container the connection string instead uses the compose service name db — that's already set in the container's environment from the docker-deploy step, don't change it.

Data/AppDbContext.cs:

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
    // DbSet<Entity> properties are added in the entity-migration step
}

Program.cs:

builder.Services.AddDbContext<AppDbContext>(opt =>
    opt.UseNpgsql(builder.Configuration.GetConnectionString("Default")));

This step is code + config only — do not redeploy.

Comments

Markdown supported