using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using ServerBase; using ServerCore; namespace BrokerApiCore; public class MetaverseBrokerDbContext: DbContext { public DbSet SapphireExchangeOrders { get; set; } public DbSet PlanetInfos { get; set; } public DbSet PlanetItemExchangeOrders { get; set; } //PlanetItemExchangeOrderAmountUserLimit public DbSet PlanetItemExchangeOrderAmountUserLimits { get; set; } //PlanetItemExchangeOrderAmountTotalLimit public DbSet PlanetItemExchangeOrderAmountTotalLimits { get; set; } public MetaverseBrokerDbContext(DbContextOptions options) : base(options) { // base.Database.EnsureCreated(); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new PlanetInfoConfig()); // todo PlanetExchangeOrderConfig으로 교체 예정 modelBuilder.ApplyConfiguration(new SapphireExchangeOrderConfig()); modelBuilder.ApplyConfiguration(new PlanetExchangeOrderConfig()); modelBuilder.ApplyConfiguration(new PlanetItemExchangeOrderAmountUserLimitConfig()); modelBuilder.ApplyConfiguration(new PlanetItemExchangeOrderAmountTotalLimitConfig()); base.OnModelCreating(modelBuilder); } } // ef core 마이그레이션 도구에서 디자인타임에 사용함 public class MetaverseBrokerDbContextFactory : IDesignTimeDbContextFactory { public MetaverseBrokerDbContext CreateDbContext(string[] args) { // nlog 설정 var nlog_config_path = "../../bin/Debug/Config/nlog.config"; var full_path = Path.GetFullPath(nlog_config_path); Console.WriteLine("[MetaverseBrokerDbContextFactory] Full path: {0}", full_path); Log.NLogFileName = full_path; Log.initLog("BrokerApiServer", "Developer"); var server_config = new ServerConfigMetaverseBroker(); server_config.setConfigFilePath("../../bin/Debug/Config/ServerConfig.json"); server_config.tryLoadConfig().GetAwaiter().GetResult(); var connection_string = server_config.MetaverseBroker?.MetaverseBrokerDbLocal; Console.WriteLine("[MetaverseBrokerDbContextFactory] Connection string: {0}", connection_string); if (string.IsNullOrEmpty(connection_string)) { throw new ApplicationException("Connection string is empty."); } var mysql_version = ServerVersion.AutoDetect(connection_string); Console.WriteLine("[MetaverseBrokerDbContextFactory] Mysql vsersion: {0}", mysql_version.ToString()); // var mysql_version = ServerVersion.Create(new Version(11, 6, 2), ServerType.MariaDb); var options_builder = new DbContextOptionsBuilder(); options_builder.UseMySql(connection_string, mysql_version, builder => builder.EnableRetryOnFailure(3)).EnableDetailedErrors(); return new MetaverseBrokerDbContext(options_builder.Options); } }