2024-02-12 22:01:15 +03:30
|
|
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
|
|
|
|
|
2024-04-16 20:01:34 +03:30
|
|
|
|
namespace Netina.Repository.Models;
|
2023-12-16 20:25:12 +03:30
|
|
|
|
|
|
|
|
|
|
|
2024-08-09 21:55:16 +03:30
|
|
|
|
public class ApplicationContext(DbContextOptions<ApplicationContext> options, ILogger<ApplicationContext> logger)
|
|
|
|
|
|
: IdentityDbContext<ApplicationUser, ApplicationRole, Guid>(options)
|
2023-12-16 20:25:12 +03:30
|
|
|
|
{
|
2024-08-09 21:55:16 +03:30
|
|
|
|
private readonly Assembly _projectAssembly = options.GetExtension<DbContextOptionCustomExtensions>().ProjectAssembly;
|
2023-12-16 20:25:12 +03:30
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
var stopwatch = new Stopwatch();
|
|
|
|
|
|
stopwatch.Start();
|
|
|
|
|
|
base.OnModelCreating(builder);
|
|
|
|
|
|
var entitiesAssembly = _projectAssembly;
|
2024-08-09 21:55:16 +03:30
|
|
|
|
builder.RegisterAllEntities<ApiEntity>(logger, entitiesAssembly);
|
2023-12-16 20:25:12 +03:30
|
|
|
|
stopwatch.Stop();
|
2024-08-09 21:55:16 +03:30
|
|
|
|
logger.LogInformation($"!!!!!!! RegisterAllEntities : {stopwatch.ElapsedMilliseconds}ms !!!!!!!");
|
2023-12-16 20:25:12 +03:30
|
|
|
|
|
|
|
|
|
|
|
2024-05-24 16:18:56 +03:30
|
|
|
|
builder.HasPostgresExtension("pg_trgm");
|
|
|
|
|
|
builder.HasPostgresExtension("fuzzystrmatch");
|
|
|
|
|
|
|
2023-12-16 20:25:12 +03:30
|
|
|
|
RenameIdentityTables(builder);
|
|
|
|
|
|
builder.RegisterEntityTypeConfiguration(entitiesAssembly);
|
|
|
|
|
|
builder.AddPluralizingTableNameConvention();
|
|
|
|
|
|
builder.AddRestrictDeleteBehaviorConvention();
|
2024-04-15 21:01:40 +03:30
|
|
|
|
|
2023-12-16 20:25:12 +03:30
|
|
|
|
//builder.AddSequentialGuidForIdConvention();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void RenameIdentityTables(ModelBuilder builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
builder.HasDefaultSchema("public");
|
|
|
|
|
|
builder.Entity<ApplicationUser>().ToTable("Users");
|
|
|
|
|
|
builder.Entity<ApplicationRole>().ToTable("Roles");
|
2024-04-18 19:19:54 +03:30
|
|
|
|
|
2023-12-16 20:25:12 +03:30
|
|
|
|
builder.Entity<IdentityRoleClaim<Guid>>().ToTable("RoleClaims");
|
|
|
|
|
|
builder.Entity<IdentityUserRole<Guid>>().ToTable("UserRoles");
|
|
|
|
|
|
builder.Entity<IdentityUserClaim<Guid>>().ToTable("Claims");
|
|
|
|
|
|
builder.Entity<IdentityUserLogin<Guid>>().ToTable("Logins");
|
|
|
|
|
|
builder.Entity<IdentityUserToken<Guid>>().ToTable("Tokens");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|