diff --git a/Configuration/OpenIddictSetup.cs b/Configuration/OpenIddictSetup.cs index 7ed5834..bcaff04 100644 --- a/Configuration/OpenIddictSetup.cs +++ b/Configuration/OpenIddictSetup.cs @@ -36,7 +36,7 @@ public static class OpenIddictSetup builder.AddCore(options => { options.UseEntityFrameworkCore() - .UseDbContext(); + .UseDbContext(); options.UseQuartz(); }); diff --git a/Controllers/AccessLogsController.cs b/Controllers/AccessLogsController.cs index 3abe130..aa8edb1 100644 --- a/Controllers/AccessLogsController.cs +++ b/Controllers/AccessLogsController.cs @@ -1,5 +1,6 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -11,11 +12,11 @@ namespace Fengling.AuthService.Controllers; [Authorize] public class AccessLogsController : ControllerBase { - private readonly ApplicationDbContext _context; + private readonly PlatformDbContext _context; private readonly ILogger _logger; public AccessLogsController( - ApplicationDbContext context, + PlatformDbContext context, ILogger logger) { _context = context; diff --git a/Controllers/AccountController.cs b/Controllers/AccountController.cs index 94f61a0..bed6027 100644 --- a/Controllers/AccountController.cs +++ b/Controllers/AccountController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Fengling.AuthService.ViewModels; using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; using Fengling.Platform.Infrastructure; @@ -15,7 +17,7 @@ namespace Fengling.AuthService.Controllers; public class AccountController( UserManager userManager, SignInManager signInManager, - ApplicationDbContext dbContext, + PlatformDbContext dbContext, ILogger logger, PlatformDbContext platformDbContext) : Controller diff --git a/Controllers/AuditLogsController.cs b/Controllers/AuditLogsController.cs index f009aca..8480ebd 100644 --- a/Controllers/AuditLogsController.cs +++ b/Controllers/AuditLogsController.cs @@ -1,5 +1,6 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -11,11 +12,11 @@ namespace Fengling.AuthService.Controllers; [Authorize] public class AuditLogsController : ControllerBase { - private readonly ApplicationDbContext _context; + private readonly PlatformDbContext _context; private readonly ILogger _logger; public AuditLogsController( - ApplicationDbContext context, + PlatformDbContext context, ILogger logger) { _context = context; diff --git a/Controllers/AuthorizationController.cs b/Controllers/AuthorizationController.cs index 3ac9707..436c5d0 100644 --- a/Controllers/AuthorizationController.cs +++ b/Controllers/AuthorizationController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Identity; diff --git a/Controllers/LogoutController.cs b/Controllers/LogoutController.cs index ef6a810..548d2d8 100644 --- a/Controllers/LogoutController.cs +++ b/Controllers/LogoutController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; diff --git a/Controllers/RolesController.cs b/Controllers/RolesController.cs index 3d4b424..06f57f0 100644 --- a/Controllers/RolesController.cs +++ b/Controllers/RolesController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -13,13 +15,13 @@ namespace Fengling.AuthService.Controllers; [Authorize] public class RolesController : ControllerBase { - private readonly ApplicationDbContext _context; + private readonly PlatformDbContext _context; private readonly RoleManager _roleManager; private readonly UserManager _userManager; private readonly ILogger _logger; public RolesController( - ApplicationDbContext context, + PlatformDbContext context, RoleManager roleManager, UserManager userManager, ILogger logger) @@ -122,7 +124,6 @@ public class RolesController : ControllerBase id = u.Id, userName = u.UserName, email = u.Email, - realName = u.RealName, tenantId = u.TenantInfo.TenantId, roles = await _userManager.GetRolesAsync(u), isActive = !u.LockoutEnabled || u.LockoutEnd == null || u.LockoutEnd < DateTimeOffset.UtcNow, diff --git a/Controllers/StatsController.cs b/Controllers/StatsController.cs index ff9c816..df9a006 100644 --- a/Controllers/StatsController.cs +++ b/Controllers/StatsController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -12,7 +14,7 @@ namespace Fengling.AuthService.Controllers; [Route("api/[controller]")] [Authorize] public class StatsController( - ApplicationDbContext context, + PlatformDbContext context, IOpenIddictApplicationManager applicationManager, ILogger logger, PlatformDbContext platformDbContext) diff --git a/Controllers/TenantsController.cs b/Controllers/TenantsController.cs index d4b76c6..35d7d12 100644 --- a/Controllers/TenantsController.cs +++ b/Controllers/TenantsController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -15,7 +17,7 @@ namespace Fengling.AuthService.Controllers; [Route("api/[controller]")] [Authorize] public class TenantsController( - ApplicationDbContext context, + PlatformDbContext context, UserManager userManager, ILogger logger, PlatformDbContext platformDbContext) @@ -122,6 +124,8 @@ public class TenantsController( var users = await context.Users .Where(u => + u.TenantInfo != null + && u.TenantInfo.TenantId == tenant.Id && !u.IsDeleted) .ToListAsync(); @@ -131,8 +135,7 @@ public class TenantsController( id = u.Id, userName = u.UserName, email = u.Email, - realName = u.RealName, - tenantId = u.TenantInfo.TenantId, + tenantId = u.TenantInfo?.TenantId, roles = await userManager.GetRolesAsync(u), isActive = !u.LockoutEnabled || u.LockoutEnd == null || u.LockoutEnd < DateTimeOffset.UtcNow, createdAt = u.CreatedTime, diff --git a/Controllers/TokenController.cs b/Controllers/TokenController.cs index d634a64..121d1f2 100644 --- a/Controllers/TokenController.cs +++ b/Controllers/TokenController.cs @@ -1,5 +1,7 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; + +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; diff --git a/Controllers/UsersController.cs b/Controllers/UsersController.cs index ba5c035..afba307 100644 --- a/Controllers/UsersController.cs +++ b/Controllers/UsersController.cs @@ -1,12 +1,12 @@ -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; +using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System.Security.Claims; using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; -using Fengling.Platform.Infrastructure; namespace Fengling.AuthService.Controllers; @@ -14,7 +14,6 @@ namespace Fengling.AuthService.Controllers; [Route("api/[controller]")] [Authorize] public class UsersController( - ApplicationDbContext context, UserManager userManager, RoleManager roleManager, ILogger logger, @@ -30,7 +29,7 @@ public class UsersController( [FromQuery] string? email = null, [FromQuery] string? tenantCode = null) { - var query = context.Users.AsQueryable(); + var query = platformDbContext.Users.AsQueryable(); if (!string.IsNullOrEmpty(userName)) { @@ -59,8 +58,6 @@ public class UsersController( id = u.Id, userName = u.UserName, email = u.Email, - realName = u.RealName, - phone = u.Phone, tenantId = u.TenantInfo.TenantId, roles = (await userManager.GetRolesAsync(u)).ToList(), emailConfirmed = u.EmailConfirmed, @@ -80,7 +77,7 @@ public class UsersController( [HttpGet("{id}")] public async Task> GetUser(long id) { - var user = await context.Users.FindAsync(id); + var user = await platformDbContext.Users.FindAsync(id); if (user == null) { return NotFound(); @@ -93,8 +90,6 @@ public class UsersController( id = user.Id, userName = user.UserName, email = user.Email, - realName = user.RealName, - phone = user.Phone, tenantId = user.TenantInfo.TenantId, roles, emailConfirmed = user.EmailConfirmed, @@ -122,11 +117,9 @@ public class UsersController( { UserName = dto.UserName, Email = dto.Email, - RealName = dto.RealName, - Phone = dto.Phone, TenantInfo = new TenantInfo(tenant!), EmailConfirmed = dto.EmailConfirmed, - CreatedTime = DateTime.UtcNow, + CreatedTime = DateTimeOffset.UtcNow, }; var result = await userManager.CreateAsync(user, dto.Password); @@ -161,7 +154,7 @@ public class UsersController( [HttpPut("{id}")] public async Task UpdateUser(long id, UpdateUserDto dto) { - var user = await context.Users.FindAsync(id); + var user = await platformDbContext.Users.FindAsync(id); if (user == null) { return NotFound(); @@ -170,10 +163,8 @@ public class UsersController( var oldValue = System.Text.Json.JsonSerializer.Serialize(user); user.Email = dto.Email; - user.RealName = dto.RealName; - user.Phone = dto.Phone; user.EmailConfirmed = dto.EmailConfirmed; - user.UpdatedTime = DateTime.UtcNow; + user.UpdatedTime = DateTimeOffset.UtcNow; if (dto.IsActive) { @@ -186,7 +177,7 @@ public class UsersController( await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.MaxValue); } - await context.SaveChangesAsync(); + await platformDbContext.SaveChangesAsync(); await CreateAuditLog("user", "update", "User", user.Id, user.UserName, oldValue, System.Text.Json.JsonSerializer.Serialize(user)); @@ -218,7 +209,7 @@ public class UsersController( [HttpDelete("{id}")] public async Task DeleteUser(long id) { - var user = await context.Users.FindAsync(id); + var user = await platformDbContext.Users.FindAsync(id); if (user == null) { return NotFound(); @@ -227,7 +218,7 @@ public class UsersController( var oldValue = System.Text.Json.JsonSerializer.Serialize(user); user.IsDeleted = true; user.UpdatedTime = DateTime.UtcNow; - await context.SaveChangesAsync(); + await platformDbContext.SaveChangesAsync(); await CreateAuditLog("user", "delete", "User", user.Id, user.UserName, oldValue); @@ -254,8 +245,8 @@ public class UsersController( NewValue = newValue, }; - context.AuditLogs.Add(log); - await context.SaveChangesAsync(); + platformDbContext.AuditLogs.Add(log); + await platformDbContext.SaveChangesAsync(); } private string SerializeToJson(object obj) diff --git a/Data/ApplicationDbContext.cs b/Data/ApplicationDbContext.cs deleted file mode 100644 index 93ae24e..0000000 --- a/Data/ApplicationDbContext.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Fengling.AuthService.Models; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; - -namespace Fengling.AuthService.Data; - -public class ApplicationDbContext(DbContextOptions options) - : IdentityDbContext(options) -{ - public DbSet AccessLogs { get; set; } - public DbSet AuditLogs { get; set; } - - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); - - builder.Entity(entity => - { - entity.Property(e => e.RealName).HasMaxLength(100); - entity.Property(e => e.Phone).HasMaxLength(20); - entity.HasIndex(e => e.Phone).IsUnique(); - - entity.OwnsOne(e => e.TenantInfo, navigationBuilder => - { - navigationBuilder.Property(e => e.TenantCode).HasColumnName("TenantCode"); - navigationBuilder.Property(e => e.TenantId).HasColumnName("TenantId"); - navigationBuilder.Property(e => e.TenantName).HasColumnName("TenantName"); - navigationBuilder.WithOwner(); - }); - }); - - builder.Entity(entity => { entity.Property(e => e.Description).HasMaxLength(200); }); - - - - builder.Entity(entity => - { - entity.HasKey(e => e.Id); - entity.HasIndex(e => e.CreatedAt); - entity.HasIndex(e => e.UserName); - entity.HasIndex(e => e.TenantId); - entity.HasIndex(e => e.Action); - entity.HasIndex(e => e.Status); - entity.Property(e => e.UserName).HasMaxLength(50); - entity.Property(e => e.TenantId).HasMaxLength(50); - entity.Property(e => e.Action).HasMaxLength(20); - entity.Property(e => e.Resource).HasMaxLength(200); - entity.Property(e => e.Method).HasMaxLength(10); - entity.Property(e => e.IpAddress).HasMaxLength(50); - entity.Property(e => e.UserAgent).HasMaxLength(500); - entity.Property(e => e.Status).HasMaxLength(20); - }); - - builder.Entity(entity => - { - entity.HasKey(e => e.Id); - entity.HasIndex(e => e.CreatedAt); - entity.HasIndex(e => e.Operator); - entity.HasIndex(e => e.TenantId); - entity.HasIndex(e => e.Operation); - entity.HasIndex(e => e.Action); - entity.Property(e => e.Operator).HasMaxLength(50); - entity.Property(e => e.TenantId).HasMaxLength(50); - entity.Property(e => e.Operation).HasMaxLength(20); - entity.Property(e => e.Action).HasMaxLength(20); - entity.Property(e => e.TargetType).HasMaxLength(50); - entity.Property(e => e.TargetName).HasMaxLength(100); - entity.Property(e => e.IpAddress).HasMaxLength(50); - entity.Property(e => e.Description).HasMaxLength(500); - entity.Property(e => e.Status).HasMaxLength(20); - }); - } -} \ No newline at end of file diff --git a/Data/ApplicationDbContextFactory.cs b/Data/ApplicationDbContextFactory.cs deleted file mode 100644 index b8e0436..0000000 --- a/Data/ApplicationDbContextFactory.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Fengling.AuthService.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; - -namespace Fengling.AuthService.Data; - -public class ApplicationDbContextFactory : IDesignTimeDbContextFactory -{ - public ApplicationDbContext CreateDbContext(string[] args) - { - var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseNpgsql("Host=81.68.223.70;Port=15432;Database=fengling_auth;Username=movingsam;Password=sl52788542"); - optionsBuilder.UseOpenIddict(); - return new ApplicationDbContext(optionsBuilder.Options); - } -} diff --git a/Data/SeedData.cs b/Data/SeedData.cs deleted file mode 100644 index c8b66ce..0000000 --- a/Data/SeedData.cs +++ /dev/null @@ -1,194 +0,0 @@ -using Fengling.AuthService.Models; -using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; -using Fengling.Platform.Infrastructure; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; -using OpenIddict.Abstractions; - -namespace Fengling.AuthService.Data; - -public static class SeedData -{ - public static async Task Initialize(IServiceProvider serviceProvider) - { - using var scope = serviceProvider.CreateScope(); - var context = scope.ServiceProvider.GetRequiredService(); - var userManager = scope.ServiceProvider.GetRequiredService>(); - var roleManager = scope.ServiceProvider.GetRequiredService>(); - var applicationManager = scope.ServiceProvider.GetRequiredService(); - var scopeManager = scope.ServiceProvider.GetRequiredService(); - - var platformDbContext = scope.ServiceProvider.GetRequiredService(); - - var adminTenant = await platformDbContext.InitializeAsync(); - await context.Database.EnsureCreatedAsync(); - - - var adminRole = await roleManager.FindByNameAsync("Admin"); - if (adminRole == null) - { - adminRole = new ApplicationRole - { - Name = "Admin", - DisplayName = "管理员", - Description = "System administrator", - TenantId = adminTenant.Id, - IsSystem = true, - Permissions = new List - { - "user.manage", "user.view", - "role.manage", "role.view", - "tenant.manage", "tenant.view", - "oauth.manage", "oauth.view", - "log.view", "system.config" - }, - CreatedTime = DateTime.UtcNow - }; - await roleManager.CreateAsync(adminRole); - } - - var userRole = await roleManager.FindByNameAsync("User"); - if (userRole == null) - { - userRole = new ApplicationRole - { - Name = "User", - DisplayName = "普通用户", - Description = "Regular user", - TenantId = adminTenant.Id, - IsSystem = true, - Permissions = new List { "user.view" }, - CreatedTime = DateTime.UtcNow - }; - await roleManager.CreateAsync(userRole); - } - - var adminUser = await userManager.FindByNameAsync("admin"); - if (adminUser == null) - { - adminUser = new ApplicationUser - { - UserName = "admin", - Email = "admin@fengling.local", - RealName = "系统管理员", - Phone = "13800138000", - TenantInfo = new TenantInfo(adminTenant), - EmailConfirmed = true, - IsDeleted = false, - CreatedTime = DateTime.UtcNow - }; - - var result = await userManager.CreateAsync(adminUser, "Admin@123"); - if (result.Succeeded) - { - await userManager.AddToRoleAsync(adminUser, "Admin"); - } - } - - var testUser = await userManager.FindByNameAsync("testuser"); - if (testUser == null) - { - testUser = new ApplicationUser - { - UserName = "testuser", - Email = "test@fengling.local", - RealName = "测试用户", - Phone = "13900139000", - TenantInfo = new TenantInfo(adminTenant.Id, adminTenant.TenantCode, adminTenant.Name), - EmailConfirmed = true, - IsDeleted = false, - CreatedTime = DateTime.UtcNow - }; - - var result = await userManager.CreateAsync(testUser, "Test@123"); - if (result.Succeeded) - { - await userManager.AddToRoleAsync(testUser, "User"); - } - } - - var consoleClient = await applicationManager.FindByClientIdAsync("fengling-console"); - - if (consoleClient == null) - { - var descriptor = new OpenIddictApplicationDescriptor - { - ClientId = "fengling-console", - DisplayName = "Fengling Console", - Permissions = - { - OpenIddictConstants.Permissions.Endpoints.Authorization, - OpenIddictConstants.Permissions.Endpoints.EndSession, - OpenIddictConstants.Permissions.Endpoints.Token, - OpenIddictConstants.Permissions.Endpoints.Introspection - } - }; - - foreach (var uri in new[] - { - "http://localhost:5777/auth/callback", - "https://console.fengling.local/auth/callback" - }) - { - descriptor.RedirectUris.Add(new Uri(uri)); - } - - foreach (var uri in new[] - { - "http://localhost:5777/", - "https://console.fengling.local/" - }) - { - descriptor.PostLogoutRedirectUris.Add(new Uri(uri)); - } - - descriptor.Permissions.Add(OpenIddictConstants.Permissions.ResponseTypes.Code); - - var scopes = new[] - { - OpenIddictConstants.Permissions.Prefixes.Scope + "api", - OpenIddictConstants.Permissions.Prefixes.Scope + OpenIddictConstants.Scopes.OfflineAccess, - OpenIddictConstants.Permissions.Prefixes.Scope + OpenIddictConstants.Scopes.OpenId, - OpenIddictConstants.Permissions.Prefixes.Scope + OpenIddictConstants.Scopes.Profile, - OpenIddictConstants.Permissions.Prefixes.Scope + OpenIddictConstants.Scopes.Roles, - OpenIddictConstants.Permissions.Prefixes.Scope + OpenIddictConstants.Scopes.Email - }; - - foreach (var permissionScope in scopes) - { - descriptor.Permissions.Add(permissionScope); - } - - var grantTypes = new[] - { - OpenIddictConstants.Permissions.Prefixes.GrantType + OpenIddictConstants.GrantTypes.AuthorizationCode, - OpenIddictConstants.Permissions.Prefixes.GrantType + OpenIddictConstants.GrantTypes.RefreshToken - }; - - foreach (var grantType in grantTypes) - { - descriptor.Permissions.Add(grantType); - } - - await applicationManager.CreateAsync(descriptor); - } - - var resourceServerClient = await applicationManager.FindByClientIdAsync("fengling-api"); - - if (resourceServerClient == null) - { - var resourceDescriptor = new OpenIddictApplicationDescriptor - { - ClientId = "fengling-api", - ClientSecret = "fengling-api-secret", - DisplayName = "Fengling API", - Permissions = - { - OpenIddictConstants.Permissions.Endpoints.Introspection - } - }; - - await applicationManager.CreateAsync(resourceDescriptor); - } - } -} \ No newline at end of file diff --git a/Migrations/20260218145654_Initial.Designer.cs b/Migrations/20260218145654_Initial.Designer.cs deleted file mode 100644 index 8806b30..0000000 --- a/Migrations/20260218145654_Initial.Designer.cs +++ /dev/null @@ -1,748 +0,0 @@ -// -using System; -using System.Collections.Generic; -using Fengling.AuthService.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Fengling.AuthService.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - [Migration("20260218145654_Initial")] - partial class Initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.2") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Fengling.AuthService.Models.AccessLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Action") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Duration") - .HasColumnType("integer"); - - b.Property("ErrorMessage") - .HasColumnType("text"); - - b.Property("IpAddress") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Method") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("RequestData") - .HasColumnType("text"); - - b.Property("Resource") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("ResponseData") - .HasColumnType("text"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("TenantId") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("UserAgent") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("UserName") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("Action"); - - b.HasIndex("CreatedAt"); - - b.HasIndex("Status"); - - b.HasIndex("TenantId"); - - b.HasIndex("UserName"); - - b.ToTable("AccessLogs"); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.ApplicationRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("IsSystem") - .HasColumnType("boolean"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.PrimitiveCollection>("Permissions") - .HasColumnType("text[]"); - - b.Property("TenantId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.ApplicationUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("Phone") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("RealName") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UpdatedTime") - .HasColumnType("timestamp with time zone"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.HasIndex("Phone") - .IsUnique(); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Action") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("ErrorMessage") - .HasColumnType("text"); - - b.Property("IpAddress") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("Operation") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("Operator") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("TargetId") - .HasColumnType("bigint"); - - b.Property("TargetName") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TargetType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("TenantId") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("Action"); - - b.HasIndex("CreatedAt"); - - b.HasIndex("Operation"); - - b.HasIndex("Operator"); - - b.HasIndex("TenantId"); - - b.ToTable("AuditLogs"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("bigint"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("bigint"); - - b.Property("RoleId") - .HasColumnType("bigint"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("bigint"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ApplicationType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ClientId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ClientSecret") - .HasColumnType("text"); - - b.Property("ClientType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ConsentType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("DisplayNames") - .HasColumnType("text"); - - b.Property("JsonWebKeySet") - .HasColumnType("text"); - - b.Property("Permissions") - .HasColumnType("text"); - - b.Property("PostLogoutRedirectUris") - .HasColumnType("text"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("RedirectUris") - .HasColumnType("text"); - - b.Property("Requirements") - .HasColumnType("text"); - - b.Property("Settings") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ClientId") - .IsUnique(); - - b.ToTable("OpenIddictApplications", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ApplicationId") - .HasColumnType("text"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("CreationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("Scopes") - .HasColumnType("text"); - - b.Property("Status") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Subject") - .HasMaxLength(400) - .HasColumnType("character varying(400)"); - - b.Property("Type") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("ApplicationId", "Status", "Subject", "Type"); - - b.ToTable("OpenIddictAuthorizations", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreScope", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Description") - .HasColumnType("text"); - - b.Property("Descriptions") - .HasColumnType("text"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("DisplayNames") - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("Resources") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("OpenIddictScopes", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreToken", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ApplicationId") - .HasColumnType("text"); - - b.Property("AuthorizationId") - .HasColumnType("text"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("CreationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("ExpirationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Payload") - .HasColumnType("text"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("RedemptionDate") - .HasColumnType("timestamp with time zone"); - - b.Property("ReferenceId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Status") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Subject") - .HasMaxLength(400) - .HasColumnType("character varying(400)"); - - b.Property("Type") - .HasMaxLength(150) - .HasColumnType("character varying(150)"); - - b.HasKey("Id"); - - b.HasIndex("AuthorizationId"); - - b.HasIndex("ReferenceId") - .IsUnique(); - - b.HasIndex("ApplicationId", "Status", "Subject", "Type"); - - b.ToTable("OpenIddictTokens", (string)null); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.ApplicationUser", b => - { - b.OwnsOne("Fengling.Platform.Domain.AggregatesModel.TenantAggregate.TenantInfo", "TenantInfo", b1 => - { - b1.Property("ApplicationUserId") - .HasColumnType("bigint"); - - b1.Property("TenantCode") - .IsRequired() - .HasColumnType("text") - .HasColumnName("TenantCode"); - - b1.Property("TenantId") - .HasColumnType("bigint") - .HasColumnName("TenantId"); - - b1.Property("TenantName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("TenantName"); - - b1.HasKey("ApplicationUserId"); - - b1.ToTable("AspNetUsers"); - - b1.WithOwner() - .HasForeignKey("ApplicationUserId"); - }); - - b.Navigation("TenantInfo") - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", b => - { - b.HasOne("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", "Application") - .WithMany("Authorizations") - .HasForeignKey("ApplicationId"); - - b.Navigation("Application"); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreToken", b => - { - b.HasOne("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", "Application") - .WithMany("Tokens") - .HasForeignKey("ApplicationId"); - - b.HasOne("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", "Authorization") - .WithMany("Tokens") - .HasForeignKey("AuthorizationId"); - - b.Navigation("Application"); - - b.Navigation("Authorization"); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", b => - { - b.Navigation("Authorizations"); - - b.Navigation("Tokens"); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", b => - { - b.Navigation("Tokens"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Migrations/20260218145654_Initial.cs b/Migrations/20260218145654_Initial.cs deleted file mode 100644 index d1bc9f7..0000000 --- a/Migrations/20260218145654_Initial.cs +++ /dev/null @@ -1,500 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Fengling.AuthService.Migrations -{ - /// - public partial class Initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AccessLogs", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserName = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - TenantId = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - Action = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), - Resource = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), - Method = table.Column(type: "character varying(10)", maxLength: 10, nullable: true), - IpAddress = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - UserAgent = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), - Duration = table.Column(type: "integer", nullable: false), - RequestData = table.Column(type: "text", nullable: true), - ResponseData = table.Column(type: "text", nullable: true), - ErrorMessage = table.Column(type: "text", nullable: true), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AccessLogs", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Description = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), - CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), - TenantId = table.Column(type: "bigint", nullable: true), - IsSystem = table.Column(type: "boolean", nullable: false), - DisplayName = table.Column(type: "text", nullable: true), - Permissions = table.Column>(type: "text[]", nullable: true), - Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RealName = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - Phone = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), - TenantId = table.Column(type: "bigint", nullable: false), - TenantCode = table.Column(type: "text", nullable: false), - TenantName = table.Column(type: "text", nullable: false), - CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedTime = table.Column(type: "timestamp with time zone", nullable: true), - IsDeleted = table.Column(type: "boolean", nullable: false), - UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "boolean", nullable: false), - PasswordHash = table.Column(type: "text", nullable: true), - SecurityStamp = table.Column(type: "text", nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true), - PhoneNumber = table.Column(type: "text", nullable: true), - PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), - TwoFactorEnabled = table.Column(type: "boolean", nullable: false), - LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), - LockoutEnabled = table.Column(type: "boolean", nullable: false), - AccessFailedCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AuditLogs", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Operator = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - TenantId = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - Operation = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), - Action = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), - TargetType = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - TargetId = table.Column(type: "bigint", nullable: true), - TargetName = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - IpAddress = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), - OldValue = table.Column(type: "text", nullable: true), - NewValue = table.Column(type: "text", nullable: true), - ErrorMessage = table.Column(type: "text", nullable: true), - Status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AuditLogs", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "OpenIddictApplications", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - ApplicationType = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - ClientId = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - ClientSecret = table.Column(type: "text", nullable: true), - ClientType = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - ConcurrencyToken = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - ConsentType = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - DisplayName = table.Column(type: "text", nullable: true), - DisplayNames = table.Column(type: "text", nullable: true), - JsonWebKeySet = table.Column(type: "text", nullable: true), - Permissions = table.Column(type: "text", nullable: true), - PostLogoutRedirectUris = table.Column(type: "text", nullable: true), - Properties = table.Column(type: "text", nullable: true), - RedirectUris = table.Column(type: "text", nullable: true), - Requirements = table.Column(type: "text", nullable: true), - Settings = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictApplications", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "OpenIddictScopes", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - ConcurrencyToken = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - Description = table.Column(type: "text", nullable: true), - Descriptions = table.Column(type: "text", nullable: true), - DisplayName = table.Column(type: "text", nullable: true), - DisplayNames = table.Column(type: "text", nullable: true), - Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), - Properties = table.Column(type: "text", nullable: true), - Resources = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictScopes", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "bigint", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "bigint", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "text", nullable: false), - ProviderKey = table.Column(type: "text", nullable: false), - ProviderDisplayName = table.Column(type: "text", nullable: true), - UserId = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "bigint", nullable: false), - RoleId = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "bigint", nullable: false), - LoginProvider = table.Column(type: "text", nullable: false), - Name = table.Column(type: "text", nullable: false), - Value = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "OpenIddictAuthorizations", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - ApplicationId = table.Column(type: "text", nullable: true), - ConcurrencyToken = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - CreationDate = table.Column(type: "timestamp with time zone", nullable: true), - Properties = table.Column(type: "text", nullable: true), - Scopes = table.Column(type: "text", nullable: true), - Status = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - Subject = table.Column(type: "character varying(400)", maxLength: 400, nullable: true), - Type = table.Column(type: "character varying(50)", maxLength: 50, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictAuthorizations", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictAuthorizations_OpenIddictApplications_Application~", - column: x => x.ApplicationId, - principalTable: "OpenIddictApplications", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "OpenIddictTokens", - columns: table => new - { - Id = table.Column(type: "text", nullable: false), - ApplicationId = table.Column(type: "text", nullable: true), - AuthorizationId = table.Column(type: "text", nullable: true), - ConcurrencyToken = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - CreationDate = table.Column(type: "timestamp with time zone", nullable: true), - ExpirationDate = table.Column(type: "timestamp with time zone", nullable: true), - Payload = table.Column(type: "text", nullable: true), - Properties = table.Column(type: "text", nullable: true), - RedemptionDate = table.Column(type: "timestamp with time zone", nullable: true), - ReferenceId = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - Status = table.Column(type: "character varying(50)", maxLength: 50, nullable: true), - Subject = table.Column(type: "character varying(400)", maxLength: 400, nullable: true), - Type = table.Column(type: "character varying(150)", maxLength: 150, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_OpenIddictTokens", x => x.Id); - table.ForeignKey( - name: "FK_OpenIddictTokens_OpenIddictApplications_ApplicationId", - column: x => x.ApplicationId, - principalTable: "OpenIddictApplications", - principalColumn: "Id"); - table.ForeignKey( - name: "FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId", - column: x => x.AuthorizationId, - principalTable: "OpenIddictAuthorizations", - principalColumn: "Id"); - }); - - migrationBuilder.CreateIndex( - name: "IX_AccessLogs_Action", - table: "AccessLogs", - column: "Action"); - - migrationBuilder.CreateIndex( - name: "IX_AccessLogs_CreatedAt", - table: "AccessLogs", - column: "CreatedAt"); - - migrationBuilder.CreateIndex( - name: "IX_AccessLogs_Status", - table: "AccessLogs", - column: "Status"); - - migrationBuilder.CreateIndex( - name: "IX_AccessLogs_TenantId", - table: "AccessLogs", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_AccessLogs_UserName", - table: "AccessLogs", - column: "UserName"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUsers_Phone", - table: "AspNetUsers", - column: "Phone", - unique: true); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_AuditLogs_Action", - table: "AuditLogs", - column: "Action"); - - migrationBuilder.CreateIndex( - name: "IX_AuditLogs_CreatedAt", - table: "AuditLogs", - column: "CreatedAt"); - - migrationBuilder.CreateIndex( - name: "IX_AuditLogs_Operation", - table: "AuditLogs", - column: "Operation"); - - migrationBuilder.CreateIndex( - name: "IX_AuditLogs_Operator", - table: "AuditLogs", - column: "Operator"); - - migrationBuilder.CreateIndex( - name: "IX_AuditLogs_TenantId", - table: "AuditLogs", - column: "TenantId"); - - migrationBuilder.CreateIndex( - name: "IX_OpenIddictApplications_ClientId", - table: "OpenIddictApplications", - column: "ClientId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_OpenIddictAuthorizations_ApplicationId_Status_Subject_Type", - table: "OpenIddictAuthorizations", - columns: new[] { "ApplicationId", "Status", "Subject", "Type" }); - - migrationBuilder.CreateIndex( - name: "IX_OpenIddictScopes_Name", - table: "OpenIddictScopes", - column: "Name", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type", - table: "OpenIddictTokens", - columns: new[] { "ApplicationId", "Status", "Subject", "Type" }); - - migrationBuilder.CreateIndex( - name: "IX_OpenIddictTokens_AuthorizationId", - table: "OpenIddictTokens", - column: "AuthorizationId"); - - migrationBuilder.CreateIndex( - name: "IX_OpenIddictTokens_ReferenceId", - table: "OpenIddictTokens", - column: "ReferenceId", - unique: true); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AccessLogs"); - - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "AuditLogs"); - - migrationBuilder.DropTable( - name: "OpenIddictScopes"); - - migrationBuilder.DropTable( - name: "OpenIddictTokens"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - - migrationBuilder.DropTable( - name: "OpenIddictAuthorizations"); - - migrationBuilder.DropTable( - name: "OpenIddictApplications"); - } - } -} diff --git a/Migrations/ApplicationDbContextModelSnapshot.cs b/Migrations/ApplicationDbContextModelSnapshot.cs deleted file mode 100644 index 935f985..0000000 --- a/Migrations/ApplicationDbContextModelSnapshot.cs +++ /dev/null @@ -1,745 +0,0 @@ -// -using System; -using System.Collections.Generic; -using Fengling.AuthService.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace Fengling.AuthService.Migrations -{ - [DbContext(typeof(ApplicationDbContext))] - partial class ApplicationDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.2") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("Fengling.AuthService.Models.AccessLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Action") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Duration") - .HasColumnType("integer"); - - b.Property("ErrorMessage") - .HasColumnType("text"); - - b.Property("IpAddress") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Method") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); - - b.Property("RequestData") - .HasColumnType("text"); - - b.Property("Resource") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("ResponseData") - .HasColumnType("text"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("TenantId") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("UserAgent") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("UserName") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("Action"); - - b.HasIndex("CreatedAt"); - - b.HasIndex("Status"); - - b.HasIndex("TenantId"); - - b.HasIndex("UserName"); - - b.ToTable("AccessLogs"); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.ApplicationRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("IsSystem") - .HasColumnType("boolean"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.PrimitiveCollection>("Permissions") - .HasColumnType("text[]"); - - b.Property("TenantId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.ApplicationUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("CreatedTime") - .HasColumnType("timestamp with time zone"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("IsDeleted") - .HasColumnType("boolean"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("Phone") - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("RealName") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UpdatedTime") - .HasColumnType("timestamp with time zone"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.HasIndex("Phone") - .IsUnique(); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.AuditLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Action") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("CreatedAt") - .HasColumnType("timestamp with time zone"); - - b.Property("Description") - .HasMaxLength(500) - .HasColumnType("character varying(500)"); - - b.Property("ErrorMessage") - .HasColumnType("text"); - - b.Property("IpAddress") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("NewValue") - .HasColumnType("text"); - - b.Property("OldValue") - .HasColumnType("text"); - - b.Property("Operation") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("Operator") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Status") - .IsRequired() - .HasMaxLength(20) - .HasColumnType("character varying(20)"); - - b.Property("TargetId") - .HasColumnType("bigint"); - - b.Property("TargetName") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TargetType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("TenantId") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("Action"); - - b.HasIndex("CreatedAt"); - - b.HasIndex("Operation"); - - b.HasIndex("Operator"); - - b.HasIndex("TenantId"); - - b.ToTable("AuditLogs"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("bigint"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("bigint"); - - b.Property("RoleId") - .HasColumnType("bigint"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("bigint"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ApplicationType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ClientId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("ClientSecret") - .HasColumnType("text"); - - b.Property("ClientType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("ConsentType") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("DisplayNames") - .HasColumnType("text"); - - b.Property("JsonWebKeySet") - .HasColumnType("text"); - - b.Property("Permissions") - .HasColumnType("text"); - - b.Property("PostLogoutRedirectUris") - .HasColumnType("text"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("RedirectUris") - .HasColumnType("text"); - - b.Property("Requirements") - .HasColumnType("text"); - - b.Property("Settings") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("ClientId") - .IsUnique(); - - b.ToTable("OpenIddictApplications", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ApplicationId") - .HasColumnType("text"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("CreationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("Scopes") - .HasColumnType("text"); - - b.Property("Status") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Subject") - .HasMaxLength(400) - .HasColumnType("character varying(400)"); - - b.Property("Type") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.HasKey("Id"); - - b.HasIndex("ApplicationId", "Status", "Subject", "Type"); - - b.ToTable("OpenIddictAuthorizations", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreScope", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Description") - .HasColumnType("text"); - - b.Property("Descriptions") - .HasColumnType("text"); - - b.Property("DisplayName") - .HasColumnType("text"); - - b.Property("DisplayNames") - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(200) - .HasColumnType("character varying(200)"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("Resources") - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("OpenIddictScopes", (string)null); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreToken", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("text"); - - b.Property("ApplicationId") - .HasColumnType("text"); - - b.Property("AuthorizationId") - .HasColumnType("text"); - - b.Property("ConcurrencyToken") - .IsConcurrencyToken() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("CreationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("ExpirationDate") - .HasColumnType("timestamp with time zone"); - - b.Property("Payload") - .HasColumnType("text"); - - b.Property("Properties") - .HasColumnType("text"); - - b.Property("RedemptionDate") - .HasColumnType("timestamp with time zone"); - - b.Property("ReferenceId") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("Status") - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Subject") - .HasMaxLength(400) - .HasColumnType("character varying(400)"); - - b.Property("Type") - .HasMaxLength(150) - .HasColumnType("character varying(150)"); - - b.HasKey("Id"); - - b.HasIndex("AuthorizationId"); - - b.HasIndex("ReferenceId") - .IsUnique(); - - b.HasIndex("ApplicationId", "Status", "Subject", "Type"); - - b.ToTable("OpenIddictTokens", (string)null); - }); - - modelBuilder.Entity("Fengling.AuthService.Models.ApplicationUser", b => - { - b.OwnsOne("Fengling.Platform.Domain.AggregatesModel.TenantAggregate.TenantInfo", "TenantInfo", b1 => - { - b1.Property("ApplicationUserId") - .HasColumnType("bigint"); - - b1.Property("TenantCode") - .IsRequired() - .HasColumnType("text") - .HasColumnName("TenantCode"); - - b1.Property("TenantId") - .HasColumnType("bigint") - .HasColumnName("TenantId"); - - b1.Property("TenantName") - .IsRequired() - .HasColumnType("text") - .HasColumnName("TenantName"); - - b1.HasKey("ApplicationUserId"); - - b1.ToTable("AspNetUsers"); - - b1.WithOwner() - .HasForeignKey("ApplicationUserId"); - }); - - b.Navigation("TenantInfo") - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Fengling.AuthService.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", b => - { - b.HasOne("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", "Application") - .WithMany("Authorizations") - .HasForeignKey("ApplicationId"); - - b.Navigation("Application"); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreToken", b => - { - b.HasOne("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", "Application") - .WithMany("Tokens") - .HasForeignKey("ApplicationId"); - - b.HasOne("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", "Authorization") - .WithMany("Tokens") - .HasForeignKey("AuthorizationId"); - - b.Navigation("Application"); - - b.Navigation("Authorization"); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreApplication", b => - { - b.Navigation("Authorizations"); - - b.Navigation("Tokens"); - }); - - modelBuilder.Entity("OpenIddict.EntityFrameworkCore.Models.OpenIddictEntityFrameworkCoreAuthorization", b => - { - b.Navigation("Tokens"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Models/AccessLog.cs b/Models/AccessLog.cs deleted file mode 100644 index d0c4a2e..0000000 --- a/Models/AccessLog.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Fengling.AuthService.Models; - -public class AccessLog -{ - [Key] - public long Id { get; set; } - - [MaxLength(50)] - public string? UserName { get; set; } - - [MaxLength(50)] - public string? TenantId { get; set; } - - [MaxLength(20)] - public string Action { get; set; } = string.Empty; - - [MaxLength(200)] - public string? Resource { get; set; } - - [MaxLength(10)] - public string? Method { get; set; } - - [MaxLength(50)] - public string? IpAddress { get; set; } - - [MaxLength(500)] - public string? UserAgent { get; set; } - - [MaxLength(20)] - public string Status { get; set; } = "success"; - - public int Duration { get; set; } - - public string? RequestData { get; set; } - - public string? ResponseData { get; set; } - - public string? ErrorMessage { get; set; } - - public DateTime CreatedAt { get; set; } = DateTime.UtcNow; -} diff --git a/Models/ApplicationRole.cs b/Models/ApplicationRole.cs deleted file mode 100644 index a015315..0000000 --- a/Models/ApplicationRole.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Fengling.AuthService.Models; - -public class ApplicationRole : IdentityRole -{ - public string? Description { get; set; } - public DateTime CreatedTime { get; set; } = DateTime.UtcNow; - public long? TenantId { get; set; } - public bool IsSystem { get; set; } - public string? DisplayName { get; set; } - public List? Permissions { get; set; } -} diff --git a/Models/ApplicationUser.cs b/Models/ApplicationUser.cs deleted file mode 100644 index 57a293d..0000000 --- a/Models/ApplicationUser.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Fengling.Platform.Domain.AggregatesModel.TenantAggregate; -using Microsoft.AspNetCore.Identity; - -namespace Fengling.AuthService.Models; - -public class ApplicationUser : IdentityUser -{ - public string? RealName { get; set; } - public string? Phone { get; set; } - public TenantInfo TenantInfo { get; set; } = null!; - public DateTime CreatedTime { get; set; } = DateTime.UtcNow; - public DateTime? UpdatedTime { get; set; } - public bool IsDeleted { get; set; } -} diff --git a/Models/AuditLog.cs b/Models/AuditLog.cs deleted file mode 100644 index 60708c6..0000000 --- a/Models/AuditLog.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Fengling.AuthService.Models; - -public class AuditLog -{ - [Key] - public long Id { get; set; } - - [MaxLength(50)] - [Required] - public string Operator { get; set; } = string.Empty; - - [MaxLength(50)] - public string? TenantId { get; set; } - - [MaxLength(20)] - public string Operation { get; set; } = string.Empty; - - [MaxLength(20)] - public string Action { get; set; } = string.Empty; - - [MaxLength(50)] - public string? TargetType { get; set; } - - public long? TargetId { get; set; } - - [MaxLength(100)] - public string? TargetName { get; set; } - - [MaxLength(50)] - public string IpAddress { get; set; } = string.Empty; - - [MaxLength(500)] - public string? Description { get; set; } - - public string? OldValue { get; set; } - - public string? NewValue { get; set; } - - public string? ErrorMessage { get; set; } - - [MaxLength(20)] - public string Status { get; set; } = "success"; - - public DateTime CreatedAt { get; set; } = DateTime.UtcNow; -} diff --git a/Program.cs b/Program.cs index f4d8b51..80696e1 100644 --- a/Program.cs +++ b/Program.cs @@ -1,18 +1,16 @@ using System.Reflection; using Fengling.AuthService.Configuration; -using Fengling.AuthService.Data; -using Fengling.AuthService.Models; +using Fengling.Platform.Domain.AggregatesModel.UserAggregate; +using Fengling.Platform.Domain.AggregatesModel.RoleAggregate; using Fengling.Platform.Infrastructure; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi; using NetCorePal.Extensions.DependencyInjection; -using OpenTelemetry; using OpenTelemetry.Resources; using OpenTelemetry.Trace; using Serilog; -using SeedData = Fengling.AuthService.Data.SeedData; var builder = WebApplication.CreateBuilder(args); @@ -25,25 +23,17 @@ Log.Logger = new LoggerConfiguration() builder.Host.UseSerilog(); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); -builder.Services.AddDbContext(options => +builder.Services.AddDbContext(options => { options.UseNpgsql(connectionString); options.UseOpenIddict(); }); - -builder.Services.AddDbContext(options => -{ - options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")); - options.UseOpenIddict(); -}); - - builder.Services.AddRazorPages(); builder.Services.AddControllersWithViews(); builder.Services.AddIdentity() - .AddEntityFrameworkStores() + .AddEntityFrameworkStores() .AddDefaultTokenProviders(); builder.Services.AddAuthentication(options => @@ -74,9 +64,10 @@ builder.Services.AddHealthChecks() .AddNpgSql(builder.Configuration.GetConnectionString("DefaultConnection")!); -builder.Services.AddRepositories(typeof(ApplicationDbContext).Assembly, typeof(PlatformDbContext).Assembly); -builder.Services.AddMediatR(x => x.RegisterServicesFromAssemblies(typeof(PlatformDbContext).Assembly - , Assembly.GetExecutingAssembly()) +builder.Services.AddRepositories(typeof(PlatformDbContext).Assembly); +builder.Services.AddMediatR(x => x.RegisterServicesFromAssemblies( + typeof(PlatformDbContext).Assembly, + Assembly.GetExecutingAssembly()) .AddCommandLockBehavior() .AddKnownExceptionValidationBehavior() .AddUnitOfWorkBehaviors() @@ -107,7 +98,7 @@ var app = builder.Build(); using (var scope = app.Services.CreateScope()) { - await SeedData.Initialize(scope.ServiceProvider); + await scope.InitializeAsync(); } app.UseCors(x =>