init
This commit is contained in:
47
backend/FateMaster.API/Data/ApplicationDbContext.cs
Normal file
47
backend/FateMaster.API/Data/ApplicationDbContext.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using FateMaster.API.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FateMaster.API.Data;
|
||||
|
||||
public class ApplicationDbContext : DbContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<DivinationRecord> DivinationRecords { get; set; }
|
||||
public DbSet<SystemConfig> SystemConfigs { get; set; }
|
||||
public DbSet<PriceConfig> PriceConfigs { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// 配置索引
|
||||
modelBuilder.Entity<DivinationRecord>()
|
||||
.HasIndex(d => d.Type);
|
||||
|
||||
modelBuilder.Entity<DivinationRecord>()
|
||||
.HasIndex(d => d.PaymentStatus);
|
||||
|
||||
modelBuilder.Entity<DivinationRecord>()
|
||||
.HasIndex(d => d.CreatedAt);
|
||||
|
||||
modelBuilder.Entity<SystemConfig>()
|
||||
.HasIndex(s => s.ConfigKey)
|
||||
.IsUnique();
|
||||
|
||||
modelBuilder.Entity<PriceConfig>()
|
||||
.HasIndex(p => p.ServiceType);
|
||||
|
||||
// 初始化数据
|
||||
modelBuilder.Entity<PriceConfig>().HasData(
|
||||
new PriceConfig { Id = 1, ServiceType = "bazi", Price = 99, Currency = "CNY" },
|
||||
new PriceConfig { Id = 2, ServiceType = "career", Price = 88, Currency = "CNY" },
|
||||
new PriceConfig { Id = 3, ServiceType = "marriage", Price = 88, Currency = "CNY" },
|
||||
new PriceConfig { Id = 4, ServiceType = "tarot", Price = 66, Currency = "CNY" },
|
||||
new PriceConfig { Id = 5, ServiceType = "zodiac", Price = 29, Currency = "CNY" }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user