Add domestic vendor push infrastructure

This commit is contained in:
2026-07-26 01:45:59 +08:00
parent 7cca34b331
commit 0738953e6d
77 changed files with 6470 additions and 855 deletions
@@ -17,7 +17,12 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
public DbSet<AppConfig> AppConfigs => Set<AppConfig>();
public DbSet<AiPersona> AiPersonas => Set<AiPersona>();
public DbSet<AiAvatar> AiAvatars => Set<AiAvatar>();
public DbSet<Sticker> Stickers => Set<Sticker>();
public DbSet<Sticker> Stickers => Set<Sticker>();
public DbSet<PushDevice> PushDevices => Set<PushDevice>();
public DbSet<UserPushPreference> UserPushPreferences => Set<UserPushPreference>();
public DbSet<PushMessage> PushMessages => Set<PushMessage>();
public DbSet<PushDelivery> PushDeliveries => Set<PushDelivery>();
public DbSet<BudgetNotificationReceipt> BudgetNotificationReceipts => Set<BudgetNotificationReceipt>();
protected override void OnModelCreating(ModelBuilder b)
{
@@ -67,6 +72,76 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op
b.Entity<AiAvatar>(e => e.HasIndex(x => x.Key).IsUnique());
b.Entity<Sticker>(e => e.HasIndex(x => x.Key).IsUnique());
b.Entity<PushDevice>(e =>
{
e.Property(x => x.InstallationId).HasMaxLength(64);
e.Property(x => x.Provider).HasMaxLength(16);
e.Property(x => x.TokenCiphertext).HasMaxLength(6144);
e.Property(x => x.TokenHash).HasMaxLength(64);
e.Property(x => x.UnbindTokenHash).HasMaxLength(64);
e.Property(x => x.PackageName).HasMaxLength(128);
e.Property(x => x.Flavor).HasMaxLength(24);
e.Property(x => x.AppVersion).HasMaxLength(32);
e.Property(x => x.DisabledReason).HasMaxLength(64);
e.HasIndex(x => new { x.PackageName, x.InstallationId }).IsUnique();
e.HasIndex(x => new { x.Provider, x.PackageName, x.TokenHash }).IsUnique();
e.HasIndex(x => new { x.UserId, x.IsActive });
e.HasIndex(x => x.LastSeenAt);
e.HasOne(x => x.User).WithMany(x => x.PushDevices)
.HasForeignKey(x => x.UserId).OnDelete(DeleteBehavior.Cascade);
});
b.Entity<UserPushPreference>(e =>
{
e.Property(x => x.Category).HasMaxLength(24);
e.HasIndex(x => new { x.UserId, x.Category }).IsUnique();
e.HasOne(x => x.User).WithMany(x => x.PushPreferences)
.HasForeignKey(x => x.UserId).OnDelete(DeleteBehavior.Cascade);
});
b.Entity<PushMessage>(e =>
{
e.Property(x => x.PublicId).HasMaxLength(36);
e.Property(x => x.Source).HasMaxLength(24);
e.Property(x => x.State).HasMaxLength(24);
e.Property(x => x.Category).HasMaxLength(24);
e.Property(x => x.Title).HasMaxLength(80);
e.Property(x => x.Body).HasMaxLength(240);
e.Property(x => x.Action).HasMaxLength(24);
e.Property(x => x.EntityId).HasMaxLength(64);
e.Property(x => x.Flavor).HasMaxLength(24);
e.Property(x => x.ProviderFilter).HasMaxLength(16);
e.HasIndex(x => x.PublicId).IsUnique();
e.HasIndex(x => new { x.State, x.ScheduledAt });
e.HasIndex(x => new { x.TargetUserId, x.CreatedAt });
});
b.Entity<PushDelivery>(e =>
{
e.Property(x => x.Provider).HasMaxLength(16);
e.Property(x => x.State).HasMaxLength(24);
e.Property(x => x.LeaseId).HasMaxLength(36);
e.Property(x => x.ProviderMessageId).HasMaxLength(128);
e.Property(x => x.ErrorCode).HasMaxLength(64);
e.Property(x => x.ErrorMessage).HasMaxLength(400);
e.HasIndex(x => new { x.PushMessageId, x.PushDeviceId }).IsUnique();
e.HasIndex(x => new { x.State, x.NextAttemptAt, x.LeaseExpiresAt });
e.HasOne(x => x.PushMessage).WithMany(x => x.Deliveries)
.HasForeignKey(x => x.PushMessageId).OnDelete(DeleteBehavior.Cascade);
e.HasOne(x => x.PushDevice).WithMany(x => x.Deliveries)
.HasForeignKey(x => x.PushDeviceId).OnDelete(DeleteBehavior.Cascade);
});
b.Entity<BudgetNotificationReceipt>(e =>
{
e.HasIndex(x => new { x.BudgetId, x.Period, x.Threshold }).IsUnique();
e.HasIndex(x => new { x.UserId, x.Period });
e.HasOne(x => x.User).WithMany()
.HasForeignKey(x => x.UserId).OnDelete(DeleteBehavior.Cascade);
e.HasOne(x => x.Budget).WithMany()
.HasForeignKey(x => x.BudgetId).OnDelete(DeleteBehavior.Cascade);
});
// MySQL DATETIME has no timezone metadata. Preserve stored UTC wall-clock
// values and restore DateTimeKind.Utc whenever EF materializes them.
var utcDateTimeConverter = new ValueConverter<DateTime, DateTime>(