30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using TeamUp.Modules.Integrations.Domain;
|
||
|
|
using TeamUp.SharedKernel.Persistence;
|
||
|
|
|
||
|
|
namespace TeamUp.Modules.Integrations.Persistence;
|
||
|
|
|
||
|
|
internal sealed class IntegrationsDbContext(DbContextOptions<IntegrationsDbContext> options)
|
||
|
|
: DbContext(options), IModuleDbContext
|
||
|
|
{
|
||
|
|
public DbSet<ApiConfig> ApiConfigs => Set<ApiConfig>();
|
||
|
|
|
||
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||
|
|
{
|
||
|
|
modelBuilder.HasDefaultSchema("integrations");
|
||
|
|
|
||
|
|
modelBuilder.Entity<ApiConfig>(config =>
|
||
|
|
{
|
||
|
|
config.ToTable("api_configs");
|
||
|
|
config.HasKey(c => c.Id);
|
||
|
|
config.Property(c => c.Name).HasMaxLength(120).IsRequired();
|
||
|
|
config.Property(c => c.Provider).HasMaxLength(60).IsRequired();
|
||
|
|
config.Property(c => c.Model).HasMaxLength(120).IsRequired();
|
||
|
|
config.Property(c => c.Endpoint).HasMaxLength(500);
|
||
|
|
config.Property(c => c.EncryptedKey).IsRequired();
|
||
|
|
config.HasIndex(c => c.OrganizationId);
|
||
|
|
config.HasIndex(c => new { c.OrganizationId, c.Name }).IsUnique();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|