2023-07-24 09:24:32 +09:00
|
|
|
using System;
|
2020-11-17 13:46:23 +01:00
|
|
|
using BTCPayServer.Abstractions.Contracts;
|
|
|
|
using BTCPayServer.Abstractions.Models;
|
2020-06-28 17:55:27 +09:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-08-27 09:53:28 +09:00
|
|
|
using Microsoft.Extensions.Logging;
|
2021-01-06 15:51:13 +01:00
|
|
|
using Microsoft.Extensions.Options;
|
2024-04-25 17:27:45 +09:00
|
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
|
|
namespace BTCPayServer.Data
|
|
|
|
{
|
2020-11-17 13:46:23 +01:00
|
|
|
public class ApplicationDbContextFactory : BaseDbContextFactory<ApplicationDbContext>
|
2017-10-27 17:53:04 +09:00
|
|
|
{
|
2024-08-27 09:53:28 +09:00
|
|
|
public ApplicationDbContextFactory(IOptions<DatabaseOptions> options, ILoggerFactory loggerFactory) : base(options, "")
|
2018-07-19 19:31:17 +09:00
|
|
|
{
|
2024-08-27 09:53:28 +09:00
|
|
|
LoggerFactory = loggerFactory;
|
2018-07-19 19:31:17 +09:00
|
|
|
}
|
|
|
|
|
2024-08-27 09:53:28 +09:00
|
|
|
public ILoggerFactory LoggerFactory { get; }
|
|
|
|
|
2024-04-25 17:27:45 +09:00
|
|
|
public override ApplicationDbContext CreateContext(Action<NpgsqlDbContextOptionsBuilder> npgsqlOptionsAction = null)
|
2017-10-27 17:53:04 +09:00
|
|
|
{
|
|
|
|
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
|
2024-08-27 09:53:28 +09:00
|
|
|
builder.UseLoggerFactory(LoggerFactory);
|
2024-09-09 21:21:04 +09:00
|
|
|
builder.AddInterceptors(MigrationInterceptor.Instance);
|
2024-04-25 17:27:45 +09:00
|
|
|
ConfigureBuilder(builder, npgsqlOptionsAction);
|
2017-10-27 17:53:04 +09:00
|
|
|
return new ApplicationDbContext(builder.Options);
|
|
|
|
}
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
}
|