using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Options;

namespace IRaCIS.Core.Infra.EFCore.Context;


/// <summary>
/// Design-time DbContext Creation  用于迁移时指定使用哪个数据库
/// </summary>
public class IRaCISDBContextFactory : IDesignTimeDbContextFactory<IRaCISDBContext>
{
    public IRaCISDBContext CreateDbContext(string[] args)
    {
        var optionsBuilder = new DbContextOptionsBuilder<IRaCISDBContext>();
        optionsBuilder.UseSqlServer("Server=106.14.89.110,1435;Database=Test_IRC;User ID=sa;Password=xc@123456;TrustServerCertificate=true", contextOptionsBuilder => contextOptionsBuilder.EnableRetryOnFailure());
        //迁移的时候，不生成外键
        optionsBuilder.ReplaceService<IMigrationsSqlGenerator, NoForeignKeyMigrationsSqlGenerator>();
        return new IRaCISDBContext(optionsBuilder.Options);
    }
}

