fix: make development database seeding reliable

This commit is contained in:
2026-07-30 10:03:45 +08:00
parent 98585aa521
commit bf370605d4
3 changed files with 9 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ using Tiku.Infrastructure;
using Tiku.Infrastructure.Persistence;
using Tiku.Infrastructure.Bootstrap;
using Tiku.Application;
using Tiku.Application.Security;
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning);
@@ -47,6 +48,8 @@ builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider();
using var host = builder.Build();
await using var scope = host.Services.CreateAsyncScope();
scope.ServiceProvider.GetRequiredService<ITenantContextInitializer>()
.InitializeSystem(null, "Database migration and bootstrap");
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
await dbContext.Database.MigrateAsync();
var catalogSeeder = ActivatorUtilities.CreateInstance<BuiltinBackofficeCatalogSeeder>(scope.ServiceProvider);

View File

@@ -411,6 +411,7 @@ public static class DevelopmentPlatformAdminSeeder
IdempotencyKey = "demo-platform-payment-quote",
Status = PlatformBillingQuoteStatus.Converted,
Purpose = PlatformBillingOrderPurpose.NewSubscription,
OriginalAmountCents = 19900,
TotalAmountCents = 19900,
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7)
};
@@ -422,6 +423,7 @@ public static class DevelopmentPlatformAdminSeeder
IdempotencyKey = "demo-platform-payment-order",
Purpose = PlatformBillingOrderPurpose.NewSubscription,
Status = PlatformBillingOrderStatus.PendingPayment,
OriginalAmountCents = 19900,
TotalAmountCents = 19900,
ExpiresAt = DateTimeOffset.UtcNow.AddDays(7)
};

View File

@@ -100,6 +100,10 @@ public sealed class PlatformAdminBootstrapperTests
Assert.Equal(BackendPermissions.Platform.Count, await context.PlatformBackendRolePermissions.CountAsync());
Assert.Single(context.PlatformBackendUserRoles);
Assert.Single(context.AuditLogs);
var quote = await context.PlatformBillingQuotes.SingleAsync();
Assert.Equal(quote.OriginalAmountCents - quote.DiscountAmountCents, quote.TotalAmountCents);
var order = await context.PlatformBillingOrders.SingleAsync();
Assert.Equal(order.OriginalAmountCents - order.DiscountAmountCents, order.TotalAmountCents);
}
[Fact]