mcpField
D
d1-05-entity-migration

d1-05-entity-migration

github.com/softinter-chiangrai数据与数据库046 次安装9 周前更新
代码仓库

关于 d1-05-entity-migration

用于在 `up-api` 中定义实体并创建数据库迁移的技能。它按要求使用实体名和列定义,并在无需重新部署的情况下更新运行中的 Postgres 数据库。

主要功能

  1. 01收集实体名称和列定义
  2. 02将实体加入 `AppDbContext`
  3. 03创建并应用 EF 迁移
  4. 04验证数据库表

适用场景

  1. 01在 `up-api` 中添加指定实体
  2. 02无需重新部署即可更新运行中的数据库结构

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/softinter-chiangrai/up-ai-skill-training --skill d1-05-entity-migration

安装后在 Claude Code 中输入/d1-05-entity-migration确认已加载。

详细介绍

第 1 天 · 步骤 5 — 实体 + 迁移(无需重新部署)

开始前: 请提供:

  1. 实体名称(PascalCase,例如 Product、Order、User)— 必填
  2. 列(格式:ColumnName:Type,以逗号分隔,例如 Name:string, Price:decimal, Stock:int)— 必填
  3. 可空列(可选,默认所有非字符串/Id 列均不可为空)— 可选

请严格按指定内容使用。不要建议、添加或修改列。

up-api/Entities/<Entity>.cs:

public class <Entity>
{
    public int Id { get; set; }
    // one property per given column, e.g.:
    // public string Name { get; set; } = string.Empty;
    // public decimal Price { get; set; }
}

添加到 AppDbContext:

public DbSet<<Entity>> <Entity>s => Set<<Entity>>();
cd up-api
dotnet ef migrations add Init<Entity>
dotnet ef database update

此操作会通过 db-config 步骤中的 localhost:5432 连接字符串,在已运行的 Postgres 容器中执行——无需重新部署。请验证表是否存在(在 psql 中运行 \dt,或快速使用 docker exec 进入 db 容器)。

评论

支持 Markdown