feat: migrate snowflake ids and refresh migrations
This commit is contained in:
@@ -19,6 +19,6 @@ public sealed class TenantProvider : ITenantProvider
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Guid GetCurrentTenantId()
|
||||
=> _tenantContextAccessor.Current?.TenantId ?? Guid.Empty;
|
||||
public long GetCurrentTenantId()
|
||||
=> _tenantContextAccessor.Current?.TenantId ?? 0;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public sealed class TenantResolutionMiddleware
|
||||
// 1. Header 中的租户 ID
|
||||
if (!string.IsNullOrWhiteSpace(options.TenantIdHeaderName) &&
|
||||
request.Headers.TryGetValue(options.TenantIdHeaderName, out var tenantHeader) &&
|
||||
Guid.TryParse(tenantHeader.FirstOrDefault(), out var headerTenantId))
|
||||
long.TryParse(tenantHeader.FirstOrDefault(), out var headerTenantId))
|
||||
{
|
||||
return new TenantContext(headerTenantId, null, $"header:{options.TenantIdHeaderName}");
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public sealed class TenantResolutionMiddleware
|
||||
|
||||
// 4. Token Claim
|
||||
var claim = context.User?.FindFirst("tenant_id");
|
||||
if (claim != null && Guid.TryParse(claim.Value, out var claimTenant))
|
||||
if (claim != null && long.TryParse(claim.Value, out var claimTenant))
|
||||
{
|
||||
return new TenantContext(claimTenant, null, "claim:tenant_id");
|
||||
}
|
||||
@@ -149,9 +149,9 @@ public sealed class TenantResolutionMiddleware
|
||||
return TenantContext.Empty;
|
||||
}
|
||||
|
||||
private static bool TryResolveByCode(string? code, TenantResolutionOptions options, out Guid tenantId)
|
||||
private static bool TryResolveByCode(string? code, TenantResolutionOptions options, out long tenantId)
|
||||
{
|
||||
tenantId = Guid.Empty;
|
||||
tenantId = 0;
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -20,14 +20,14 @@ public sealed class TenantResolutionOptions
|
||||
/// <summary>
|
||||
/// 明确指定 host 与租户 ID 对应关系的映射表(精确匹配)。
|
||||
/// </summary>
|
||||
public IDictionary<string, Guid> DomainTenantMap { get; set; }
|
||||
= new Dictionary<string, Guid>(StringComparer.OrdinalIgnoreCase);
|
||||
public IDictionary<string, long> DomainTenantMap { get; set; }
|
||||
= new Dictionary<string, long>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 租户编码到租户 ID 的映射表,用于 header 或子域名解析。
|
||||
/// </summary>
|
||||
public IDictionary<string, Guid> CodeTenantMap { get; set; }
|
||||
= new Dictionary<string, Guid>(StringComparer.OrdinalIgnoreCase);
|
||||
public IDictionary<string, long> CodeTenantMap { get; set; }
|
||||
= new Dictionary<string, long>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 根域(不含子域),用于形如 {tenant}.rootDomain 的场景,例如 admin.takeoutsaas.com。
|
||||
@@ -47,10 +47,10 @@ public sealed class TenantResolutionOptions
|
||||
/// <summary>
|
||||
/// 对外只读视图,便于审计日志输出。
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, Guid> DomainMappings => new ReadOnlyDictionary<string, Guid>(DomainTenantMap);
|
||||
public IReadOnlyDictionary<string, long> DomainMappings => new ReadOnlyDictionary<string, long>(DomainTenantMap);
|
||||
|
||||
/// <summary>
|
||||
/// 对外只读的编码映射。
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, Guid> CodeMappings => new ReadOnlyDictionary<string, Guid>(CodeTenantMap);
|
||||
public IReadOnlyDictionary<string, long> CodeMappings => new ReadOnlyDictionary<string, long>(CodeTenantMap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user