Adding Database Migrations for Entity Framework Core

Adding Database Migrations for Entity Framework Core with TD Web API

Hỗ trợ các DB Providers sau:

  1. MSSQL
  2. MySQL
  3. PostgreSQL
  4. Oracle

Cấu hình trong src/Host/Configurations/database.json.

Các loại database được hỗ trợ

  • MSSQL - mssql
  • MySQL - mysql
  • PostgreSQL - postgresql
  • Oracle - oracle

TD Web API gồm các EF Core DB Context sau:

  1. ApplicationDbContext - Entities của ứng dụng được tham chiếu ở đây
  2. TenantDbContext - Liên quan tới Finbuckle’s Multitenancy.

Sau khi đã thêm các entities vào Domain project và thêm cấu hình phù hợp trong TD.WebApi.Infrastructure.Persistence.ConfigurationTD.WebApi.Infrastructure.Persistence.Context, cách để tạo migrations:

  • Mở command terminal trên thư mục của Host Project và dùng lệnh:
dotnet ef migrations add <CommitMessage> --project .././Migrators/Migrators.<DBProvider>/ --context ApplicationDbContext -o Migrations/Application

Trong đó

  • <CommitMessage> mô tả Migration
  • <DBProvider> Database Provider (MSSQL, MySQL, Oracle hoặc PostgreSQL)

Ví dụ Tạo migrations cho ApplicationDbContext,

dotnet ef migrations add AddedMenuEntity --project .././Migrators/Migrators.MSSQL/ --context ApplicationDbContext -o Migrations/Application

Tạo migrations cho TenantDbContext,

dotnet ef migrations add ModifiedTenantTable --project .././Migrators/Migrators.MSSQL/ --context TenantDbContext -o Migrations/Tenant

Like TDWebAPI? ❤️

Here is what you can do to show your support!

Buy me a Coffee ☕