From d82de2200fa8199696c6f8202695749cb8e2cd5f Mon Sep 17 00:00:00 2001 From: Dmitry Afonchenko Date: Fri, 6 Nov 2026 22:52:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B7=D0=B4=D0=BD=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D1=8B=D0=B5=20=D0=BF=D1=83=D1=88=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D1=85=D0=BE=D0=B4=D1=8F=D1=82=20=D1=83=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=B8=20=D0=BD=D0=B0=20=D0=B2=D1=81=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B7=D0=B4=D0=BD=D0=B8=D0=BA=D0=B8,=20?= =?UTF-8?q?=D1=83=20=D0=BA=D0=B0=D0=B6=D0=B4=D0=BE=D0=B3=D0=BE=20=D0=BF?= =?UTF-8?q?=D1=83=D1=88=D0=B0=20=D1=81=D0=B2=D0=BE=D1=8F=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TAcLBj2Fn8nAKE4qWyn5es --- FEATURES.md | 1 + .../Services/TelegramNotificationService.cs | 14 +- .../NotificationTriggerConfiguration.cs | 2 +- ...idenNotificationTriggerVariant.Designer.cs | 1813 +++++++++++++++++ ...6183831_WidenNotificationTriggerVariant.cs | 40 + .../Migrations/TraleDbContextModelSnapshot.cs | 4 +- .../HourlyNotificationWorker.cs | 12 +- .../src/analytics/appEvents.test.ts | 11 + .../miniapp-src/src/analytics/appEvents.ts | 14 +- .../HourlyNotificationWorkerTests.cs | 29 +- .../Telegram/ReferralBonusTextTests.cs | 2 +- .../TelegramNotificationServiceTests.cs | 6 +- .../HolidayNotificationServiceTests.cs | 27 + .../Onboarding/FirstMinutesTests.cs | 2 +- 14 files changed, 1954 insertions(+), 23 deletions(-) create mode 100644 src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.Designer.cs create mode 100644 src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.cs diff --git a/FEATURES.md b/FEATURES.md index 11572c8b..7992081a 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -413,6 +413,7 @@ Location: `src/Persistence/Migrations/`. Test greps the migration class name (af | `AddTranslationCache` | Adds `TranslationCache` (normalised key + direction unique, definition / additional info / example, source, classified flag, hit count, timestamps): repeated Georgian lookups are answered from the DB instead of the external dictionary sites. | | `AddAppEvents` | Adds `AppEvents` — mini-app moments outside lessons: event (`app_open`, `app_ready`, `app_error`, `screen`, `paywall`, `app_hide`), target (screen or paywall trigger), value (ms to load / seconds open), Telegram platform, start parameter, date; indexed by (event, date) and (user, date). | | `RemapNumbersLessonProgress` | Data only: «Числа» went from 5 lessons to 11, so `CompletedLessonsJson.numbers` is remapped — old 1 (1–10) → 1–4, old 2 (11–20) → 5–6, old 3 (21–100) → 7–10, old 4 (100+, ordinals, days) → 11; old 5 (listening 1–20) has no counterpart. | +| `WidenNotificationTriggerVariant` | `NotificationTriggers.Variant` 10 → 32 chars: holiday keys longer than 10 (`svetitskhovloba`, `independence`, `language-day`) failed the claim insert, so those holiday pushes never went out. | --- diff --git a/src/Infrastructure/Telegram/Services/TelegramNotificationService.cs b/src/Infrastructure/Telegram/Services/TelegramNotificationService.cs index 8e98b289..ebb25b26 100644 --- a/src/Infrastructure/Telegram/Services/TelegramNotificationService.cs +++ b/src/Infrastructure/Telegram/Services/TelegramNotificationService.cs @@ -193,7 +193,7 @@ await _client.SendTextMessageAsync( private InlineKeyboardMarkup BuildStreakMilestoneKeyboard() { - var url = _botConfig.NormalizedHost() + "/"; + var url = _botConfig.NormalizedHost() + "/?src=push_streak"; return new InlineKeyboardMarkup(new[] { new[] @@ -253,7 +253,7 @@ internal static string BuildCoinsStalePushText(int availableXp) => private InlineKeyboardMarkup BuildCoinsStaleKeyboard() { - var url = $"{_botConfig.NormalizedHost()}/?screen=feed"; + var url = $"{_botConfig.NormalizedHost()}/?screen=feed&src=push_coins"; return new InlineKeyboardMarkup(new[] { new[] @@ -318,7 +318,7 @@ internal static string BuildHolidayPushText(Holiday holiday) private InlineKeyboardMarkup BuildHolidayPushKeyboard() { - var url = _botConfig.NormalizedHost() + "/"; + var url = _botConfig.NormalizedHost() + "/?src=push_holiday"; return new InlineKeyboardMarkup(new[] { new[] @@ -400,7 +400,7 @@ public async Task SendFirstOpenReminderAsync(Domain.Entities.User user, Cancella // No mini-app in this environment — there is nothing to open, so nothing to remind about. if (!_botConfig.MiniAppEnabled || string.IsNullOrEmpty(_botConfig.HostAddress)) return; - var keyboard = FirstStepMessage.Keyboard(_botConfig.NormalizedHost() + "/"); + var keyboard = FirstStepMessage.Keyboard(_botConfig.NormalizedHost() + "/?src=push_first_open"); try { @@ -438,7 +438,7 @@ await _client.SendTextMessageAsync( private InlineKeyboardMarkup? BuildReferralBonusKeyboard() { if (!_botConfig.MiniAppEnabled || string.IsNullOrEmpty(_botConfig.HostAddress)) return null; - var url = _botConfig.NormalizedHost() + "/"; + var url = _botConfig.NormalizedHost() + "/?src=push_referral"; return new InlineKeyboardMarkup(new[] { new[] @@ -457,12 +457,12 @@ private InlineKeyboardMarkup BuildDailyReturnPushKeyboard(string variant, string string url, label; if (variant == "feed") { - url = $"{host}/?screen=feed"; + url = $"{host}/?screen=feed&src=push_return_feed"; label = "Покормить Бомбору 🦴"; } else { - url = $"{host}/?screen=practice&moduleId={moduleId}&lessonId={lessonId}"; + url = $"{host}/?screen=practice&moduleId={moduleId}&lessonId={lessonId}&src=push_return_{variant}"; label = "Продолжить урок 📖"; } return new InlineKeyboardMarkup(new[] diff --git a/src/Persistence/Configurations/NotificationTriggerConfiguration.cs b/src/Persistence/Configurations/NotificationTriggerConfiguration.cs index 95d8f4b1..bd290da7 100644 --- a/src/Persistence/Configurations/NotificationTriggerConfiguration.cs +++ b/src/Persistence/Configurations/NotificationTriggerConfiguration.cs @@ -13,7 +13,7 @@ public void Configure(EntityTypeBuilder builder) builder.Property(x => x.UserId).IsRequired(); builder.Property(x => x.Source).IsRequired().HasMaxLength(100); builder.Property(x => x.LastSentAt).IsRequired(); - builder.Property(x => x.Variant).IsRequired(false).HasMaxLength(10); + builder.Property(x => x.Variant).IsRequired(false).HasMaxLength(32); // UserId stores the Telegram ID (long), not the User PK (Guid). No FK relationship: // HasPrincipalKey(TelegramId) would promote TelegramId to an alternate key, breaking diff --git a/src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.Designer.cs b/src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.Designer.cs new file mode 100644 index 00000000..fc3758e5 --- /dev/null +++ b/src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.Designer.cs @@ -0,0 +1,1813 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Persistence; + +#nullable disable + +namespace Persistence.Migrations +{ + [DbContext(typeof(TraleDbContext))] + [Migration("20261106183831_WidenNotificationTriggerVariant")] + partial class WidenNotificationTriggerVariant + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.25") + .HasAnnotation("Proxies:ChangeTracking", false) + .HasAnnotation("Proxies:CheckEquality", false) + .HasAnnotation("Proxies:LazyLoading", true) + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Domain.Entities.Achievement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AchievementTypeId") + .HasColumnType("uuid"); + + b.Property("DateAddedUtc") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Achievements"); + }); + + modelBuilder.Entity("Domain.Entities.AppEvent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Event") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Platform") + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("StartParam") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Target") + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("Event", "CreatedAtUtc"); + + b.HasIndex("UserId", "CreatedAtUtc"); + + b.ToTable("AppEvents", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.BroadcastCampaign", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Audience") + .HasColumnType("integer"); + + b.Property("ButtonQuery") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("ButtonText") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("GiftDays") + .HasColumnType("integer"); + + b.Property("GiftOfferEndsAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(48) + .HasColumnType("character varying(48)"); + + b.Property("Message") + .IsRequired() + .HasColumnType("text"); + + b.Property("SurveyJson") + .HasColumnType("jsonb"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique(); + + b.ToTable("BroadcastCampaigns"); + }); + + modelBuilder.Entity("Domain.Entities.BroadcastDelivery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CampaignId") + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Error") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("GiftAccessUntilUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("GiftGrantedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("IsSample") + .HasColumnType("boolean"); + + b.Property("OpenedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("SentAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SurveyFinishedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("SurveyOpenedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("TelegramId") + .HasColumnType("bigint"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("CampaignId", "Status"); + + b.HasIndex("CampaignId", "UserId") + .IsUnique(); + + b.ToTable("BroadcastDeliveries"); + }); + + modelBuilder.Entity("Domain.Entities.FeedbackReply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ClientToken") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Error") + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("Kind") + .HasColumnType("integer"); + + b.Property("Quote") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Text") + .HasMaxLength(3500) + .HasColumnType("character varying(3500)"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ClientToken") + .IsUnique(); + + b.HasIndex("UserId", "CreatedAtUtc"); + + b.ToTable("FeedbackReplies"); + }); + + modelBuilder.Entity("Domain.Entities.GeorgianQuizSession", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CorrectAnswersCount") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CurrentQuestionIndex") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("IncorrectAnswersCount") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("LessonId") + .HasColumnType("integer"); + + b.Property("QuestionsJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("StartedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("TelegramUserId") + .HasColumnType("bigint"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("WeakVerbsJson") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("[]"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAtUtc"); + + b.HasIndex("TelegramUserId"); + + b.HasIndex("UserId"); + + b.ToTable("GeorgianQuizSessions"); + }); + + modelBuilder.Entity("Domain.Entities.Invoice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("PreCheckoutQueryId") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Invoices"); + }); + + modelBuilder.Entity("Domain.Entities.LessonEvent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Event") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("LessonId") + .HasColumnType("integer"); + + b.Property("ModuleId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Step") + .HasColumnType("integer"); + + b.Property("StepKind") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "CreatedAtUtc"); + + b.HasIndex("ModuleId", "LessonId", "CreatedAtUtc"); + + b.ToTable("LessonEvents", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.MiniAppUserProgress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActivityDaysJson") + .HasColumnType("text"); + + b.Property("CompletedLessonsJson") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("{}"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Hearts") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(5); + + b.Property("HeartsUpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("LastFedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("LastPlayedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("LastTreatIndex") + .HasColumnType("integer"); + + b.Property("Level") + .HasColumnType("text"); + + b.Property("MaxHearts") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(5); + + b.Property("OnboardingHintsJson") + .HasColumnType("text"); + + b.Property("SentenceBuilderProgressJson") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("{}"); + + b.Property("Streak") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("TotalTreatsGiven") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("Xp") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("XpSpent") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("MiniAppUserProgresses"); + }); + + modelBuilder.Entity("Domain.Entities.ModelBudgetDay", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Day") + .HasColumnType("date"); + + b.Property("Generations") + .HasColumnType("integer"); + + b.Property("Requests") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("Day", "UserId") + .IsUnique(); + + b.ToTable("ModelBudgetDays"); + }); + + modelBuilder.Entity("Domain.Entities.NotificationTrigger", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("LastSentAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.Property("Variant") + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.HasIndex("UserId", "Source") + .IsUnique(); + + b.ToTable("NotificationTriggers"); + }); + + modelBuilder.Entity("Domain.Entities.Payment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Currency") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("character varying(8)"); + + b.Property("PayloadId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Plan") + .HasColumnType("integer"); + + b.Property("PurchasedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("RefundedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("TelegramPaymentChargeId") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("TelegramPaymentChargeId") + .IsUnique(); + + b.HasIndex("UserId"); + + b.ToTable("Payments"); + }); + + modelBuilder.Entity("Domain.Entities.ProcessedUpdate", b => + { + b.Property("UpdateId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("UpdateId")); + + b.Property("ProcessedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RequestType") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("UserTelegramId") + .HasColumnType("bigint"); + + b.HasKey("UpdateId"); + + b.HasIndex("ProcessedAt") + .HasDatabaseName("IX_ProcessedUpdate_ProcessedAt"); + + b.ToTable("ProcessedUpdates"); + }); + + modelBuilder.Entity("Domain.Entities.QueuedTranslation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Attempts") + .HasColumnType("integer"); + + b.Property("ChatId") + .HasColumnType("bigint"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("FinishedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("LeaseOwner") + .HasColumnType("uuid"); + + b.Property("LeaseUntilUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("MessageId") + .HasColumnType("integer"); + + b.Property("NoticeSent") + .HasColumnType("boolean"); + + b.Property("Outcome") + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Source") + .HasColumnType("integer"); + + b.Property("Stage") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("State") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("VerbLookup") + .HasColumnType("boolean"); + + b.Property("VocabularyEntryId") + .HasColumnType("uuid"); + + b.Property("Word") + .IsRequired() + .HasColumnType("text"); + + b.Property("WordKey") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAtUtc"); + + b.HasIndex("UserId", "WordKey", "CreatedAtUtc"); + + b.ToTable("QueuedTranslations", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CorrectAnswersCount") + .HasColumnType("integer"); + + b.Property("DateStarted") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone"); + + b.Property("IncorrectAnswersCount") + .HasColumnType("integer"); + + b.Property("IsCompleted") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(false); + + b.Property("QuizType") + .IsRequired() + .HasMaxLength(13) + .HasColumnType("character varying(13)"); + + b.Property("ShareableQuizId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Quizzes"); + + b.HasDiscriminator("QuizType").HasValue("Quiz"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Domain.Entities.QuizQuestion", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Answer") + .IsRequired() + .HasColumnType("text"); + + b.Property("Example") + .IsRequired() + .HasColumnType("text"); + + b.Property("OrderInQuiz") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("Question") + .IsRequired() + .HasColumnType("text"); + + b.Property("QuestionType") + .IsRequired() + .HasMaxLength(34) + .HasColumnType("character varying(34)"); + + b.Property("QuizId") + .HasColumnType("uuid"); + + b.Property("VocabularyEntryId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("QuizId"); + + b.HasIndex("VocabularyEntryId"); + + b.ToTable("QuizQuestions"); + + b.HasDiscriminator("QuestionType").HasValue("QuizQuestion"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("Domain.Entities.Referral", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ActivatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("ActivationTrigger") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("BonusRefereeDays") + .HasColumnType("integer"); + + b.Property("BonusReferrerDays") + .HasColumnType("integer"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("RefereeUserId") + .HasColumnType("uuid"); + + b.Property("ReferrerUserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RefereeUserId") + .IsUnique(); + + b.HasIndex("ReferrerUserId", "RefereeUserId") + .IsUnique(); + + b.ToTable("Referrals"); + }); + + modelBuilder.Entity("Domain.Entities.ShareableQuiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedByUserId") + .HasColumnType("uuid"); + + b.Property("CreatedByUserName") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateAddedUtc") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone"); + + b.Property("QuizId") + .HasColumnType("uuid"); + + b.Property("QuizType") + .HasColumnType("integer"); + + b.Property("VocabularyEntriesIds") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CreatedByUserId"); + + b.HasIndex("QuizId") + .IsUnique(); + + b.ToTable("ShareableQuizzes"); + }); + + modelBuilder.Entity("Domain.Entities.TranslationCacheEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AdditionalInfo") + .IsRequired() + .HasColumnType("text"); + + b.Property("Classified") + .HasColumnType("boolean"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Definition") + .IsRequired() + .HasColumnType("text"); + + b.Property("Direction") + .HasColumnType("integer"); + + b.Property("Example") + .IsRequired() + .HasColumnType("text"); + + b.Property("HitCount") + .HasColumnType("integer"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("LastHitAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.HasIndex("Key", "Direction") + .IsUnique(); + + b.ToTable("TranslationCache", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccountType") + .HasColumnType("integer"); + + b.Property("AcquisitionSource") + .HasColumnType("text"); + + b.Property("BonusAccessUntilUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("InitialLanguageSet") + .HasColumnType("boolean"); + + b.Property("IsActive") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("IsPro") + .HasColumnType("boolean"); + + b.Property("NotificationsEnabled") + .HasColumnType("boolean"); + + b.Property("ProPurchasedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("RegisteredAtUtc") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone"); + + b.Property("SubscribedUntil") + .HasColumnType("timestamp with time zone"); + + b.Property("SubscriptionPlan") + .HasColumnType("integer"); + + b.Property("TelegramId") + .HasColumnType("bigint"); + + b.Property("TrialBonusDays") + .HasColumnType("integer"); + + b.Property("UserSettingsId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Domain.Entities.UserFeedback", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CampaignKey") + .HasMaxLength(48) + .HasColumnType("character varying(48)"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Kind") + .HasColumnType("integer"); + + b.Property("Option") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("QuestionId") + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("Text") + .HasMaxLength(2000) + .HasColumnType("character varying(2000)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAtUtc"); + + b.HasIndex("UserId", "CampaignKey", "QuestionId") + .IsUnique() + .HasFilter("\"Kind\" = 1"); + + b.HasIndex("UserId", "Kind", "CreatedAtUtc"); + + b.ToTable("UserFeedback", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.UserSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CurrentLanguage") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("UsersSettings"); + }); + + modelBuilder.Entity("Domain.Entities.UserVerb", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ExamPassedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("LastPlayedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Level") + .HasColumnType("integer"); + + b.Property("RecentScenesJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("SessionsPlayed") + .HasColumnType("integer"); + + b.Property("StartedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("StoryCompleted") + .HasColumnType("boolean"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("VerbId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("VerbId"); + + b.HasIndex("UserId", "VerbId") + .IsUnique(); + + b.ToTable("UserVerbs"); + }); + + modelBuilder.Entity("Domain.Entities.Verb", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CardJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("ContentHash") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Kind") + .IsRequired() + .HasMaxLength(16) + .HasColumnType("character varying(16)"); + + b.Property("Lemma") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("PresentJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Translation") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("Lemma") + .IsUnique(); + + b.ToTable("Verbs"); + }); + + modelBuilder.Entity("Domain.Entities.VerbForm", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Form") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Meaning") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("MeaningNote") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Person") + .HasColumnType("integer"); + + b.Property("Tense") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Unverified") + .HasColumnType("boolean"); + + b.Property("VerbId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("Form"); + + b.HasIndex("VerbId"); + + b.ToTable("VerbForms"); + }); + + modelBuilder.Entity("Domain.Entities.VerbFormProgress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BestStep") + .HasColumnType("integer"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("NextDueAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Person") + .HasColumnType("integer"); + + b.Property("Reviews") + .HasColumnType("integer"); + + b.Property("Step") + .HasColumnType("integer"); + + b.Property("Tense") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("VerbId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("VerbId"); + + b.HasIndex("UserId", "NextDueAtUtc"); + + b.HasIndex("UserId", "VerbId", "Tense", "Person") + .IsUnique(); + + b.ToTable("VerbFormProgresses"); + }); + + modelBuilder.Entity("Domain.Entities.VerbProvenance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ApprovedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("AskedText") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("CompletedTensesJson") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("[]"); + + b.Property("FormsAttested") + .HasColumnType("integer"); + + b.Property("FormsTotal") + .HasColumnType("integer"); + + b.Property("GeneratorModel") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("LemmaInLexicon") + .HasColumnType("boolean"); + + b.Property("MissingTensesJson") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("[]"); + + b.Property("OwnerApprovedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("OwnerApprovedBy") + .HasColumnType("bigint"); + + b.Property("RepairRounds") + .HasColumnType("integer"); + + b.Property("ReviewerModel") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("ReviewerReasons") + .IsRequired() + .HasColumnType("text"); + + b.Property("RevisedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("TenseReviewsJson") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("[]"); + + b.Property("UnattestedFormsJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("VerbId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("VerbId") + .IsUnique(); + + b.ToTable("VerbProvenances"); + }); + + modelBuilder.Entity("Domain.Entities.VerbSectionVisit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("FirstOpenedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("LastOpenedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Opens") + .HasColumnType("integer"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("Source"); + + b.HasIndex("UserId", "Source") + .IsUnique(); + + b.ToTable("VerbSectionVisits"); + }); + + modelBuilder.Entity("Domain.Entities.VerbSession", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("Done") + .HasColumnType("integer"); + + b.Property("FinishedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("PlanJson") + .IsRequired() + .HasColumnType("text"); + + b.Property("Scene") + .HasColumnType("integer"); + + b.Property("StartedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("VerbId") + .HasColumnType("uuid"); + + b.Property("XpEarned") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("VerbId"); + + b.HasIndex("UserId", "FinishedAtUtc"); + + b.HasIndex("UserId", "VerbId", "FinishedAtUtc"); + + b.ToTable("VerbSessions"); + }); + + modelBuilder.Entity("Domain.Entities.VocabularyEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AdditionalInfo") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateAddedUtc") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone"); + + b.Property("Definition") + .IsRequired() + .HasColumnType("text"); + + b.Property("Example") + .IsRequired() + .HasColumnType("text"); + + b.Property("FailedAnswersCount") + .HasColumnType("integer"); + + b.Property("Language") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasDefaultValue(0); + + b.Property("SuccessAnswersCount") + .HasColumnType("integer"); + + b.Property("SuccessAnswersCountInReverseDirection") + .HasColumnType("integer"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("Word") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("DateAddedUtc"); + + b.HasIndex("UserId"); + + b.ToTable("VocabularyEntries"); + }); + + modelBuilder.Entity("Domain.Entities.WaitlistEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(254) + .HasColumnType("character varying(254)"); + + b.Property("Language") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Platform") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("Source") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.HasKey("Id"); + + b.HasIndex("CreatedAtUtc"); + + b.HasIndex("Email", "Language") + .IsUnique(); + + b.ToTable("WaitlistEntries", (string)null); + }); + + modelBuilder.Entity("Domain.Entities.SharedQuiz", b => + { + b.HasBaseType("Domain.Entities.Quiz"); + + b.Property("CreatedByUserName") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreatedByUserScore") + .HasColumnType("double precision"); + + b.HasDiscriminator().HasValue("SharedQuiz"); + }); + + modelBuilder.Entity("Domain.Entities.UserQuiz", b => + { + b.HasBaseType("Domain.Entities.Quiz"); + + b.HasDiscriminator().HasValue("UserQuiz"); + }); + + modelBuilder.Entity("Domain.Entities.QuizQuestionWithTypeAnswer", b => + { + b.HasBaseType("Domain.Entities.QuizQuestion"); + + b.HasDiscriminator().HasValue("QuizQuestionWithTypeAnswer"); + }); + + modelBuilder.Entity("Domain.Entities.QuizQuestionWithVariants", b => + { + b.HasBaseType("Domain.Entities.QuizQuestion"); + + b.Property("Variants") + .IsRequired() + .HasColumnType("text"); + + b.HasDiscriminator().HasValue("QuizQuestionWithVariants"); + }); + + modelBuilder.Entity("Domain.Entities.Achievement", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany("Achievements") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.AppEvent", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.BroadcastDelivery", b => + { + b.HasOne("Domain.Entities.BroadcastCampaign", null) + .WithMany() + .HasForeignKey("CampaignId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.FeedbackReply", b => + { + b.HasOne("Domain.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.GeorgianQuizSession", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.Invoice", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany("Invoices") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.LessonEvent", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.MiniAppUserProgress", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.Payment", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany("Payments") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.QueuedTranslation", b => + { + b.HasOne("Domain.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.Quiz", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany("Quizzes") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.QuizQuestion", b => + { + b.HasOne("Domain.Entities.Quiz", null) + .WithMany("QuizQuestions") + .HasForeignKey("QuizId"); + + b.HasOne("Domain.Entities.VocabularyEntry", "VocabularyEntry") + .WithMany("QuizQuestions") + .HasForeignKey("VocabularyEntryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("VocabularyEntry"); + }); + + modelBuilder.Entity("Domain.Entities.ShareableQuiz", b => + { + b.HasOne("Domain.Entities.User", "CreatedByUser") + .WithMany("ShareableQuizzes") + .HasForeignKey("CreatedByUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.Quiz", "Quiz") + .WithOne("ShareableQuiz") + .HasForeignKey("Domain.Entities.ShareableQuiz", "QuizId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CreatedByUser"); + + b.Navigation("Quiz"); + }); + + modelBuilder.Entity("Domain.Entities.UserFeedback", b => + { + b.HasOne("Domain.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Domain.Entities.UserSettings", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithOne("Settings") + .HasForeignKey("Domain.Entities.UserSettings", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.UserVerb", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.Verb", "Verb") + .WithMany() + .HasForeignKey("VerbId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + + b.Navigation("Verb"); + }); + + modelBuilder.Entity("Domain.Entities.VerbForm", b => + { + b.HasOne("Domain.Entities.Verb", "Verb") + .WithMany("Forms") + .HasForeignKey("VerbId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Verb"); + }); + + modelBuilder.Entity("Domain.Entities.VerbFormProgress", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.Verb", "Verb") + .WithMany() + .HasForeignKey("VerbId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + + b.Navigation("Verb"); + }); + + modelBuilder.Entity("Domain.Entities.VerbProvenance", b => + { + b.HasOne("Domain.Entities.Verb", "Verb") + .WithOne() + .HasForeignKey("Domain.Entities.VerbProvenance", "VerbId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Verb"); + }); + + modelBuilder.Entity("Domain.Entities.VerbSectionVisit", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.VerbSession", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Domain.Entities.Verb", "Verb") + .WithMany() + .HasForeignKey("VerbId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + + b.Navigation("Verb"); + }); + + modelBuilder.Entity("Domain.Entities.VocabularyEntry", b => + { + b.HasOne("Domain.Entities.User", "User") + .WithMany("VocabularyEntries") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Domain.Entities.Quiz", b => + { + b.Navigation("QuizQuestions"); + + b.Navigation("ShareableQuiz"); + }); + + modelBuilder.Entity("Domain.Entities.User", b => + { + b.Navigation("Achievements"); + + b.Navigation("Invoices"); + + b.Navigation("Payments"); + + b.Navigation("Quizzes"); + + b.Navigation("Settings") + .IsRequired(); + + b.Navigation("ShareableQuizzes"); + + b.Navigation("VocabularyEntries"); + }); + + modelBuilder.Entity("Domain.Entities.Verb", b => + { + b.Navigation("Forms"); + }); + + modelBuilder.Entity("Domain.Entities.VocabularyEntry", b => + { + b.Navigation("QuizQuestions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.cs b/src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.cs new file mode 100644 index 00000000..75b24b4f --- /dev/null +++ b/src/Persistence/Migrations/20261106183831_WidenNotificationTriggerVariant.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Persistence.Migrations +{ + /// + public partial class WidenNotificationTriggerVariant : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Variant", + table: "NotificationTriggers", + type: "character varying(32)", + maxLength: 32, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(10)", + oldMaxLength: 10, + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Variant", + table: "NotificationTriggers", + type: "character varying(10)", + maxLength: 10, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(32)", + oldMaxLength: 32, + oldNullable: true); + } + } +} diff --git a/src/Persistence/Migrations/TraleDbContextModelSnapshot.cs b/src/Persistence/Migrations/TraleDbContextModelSnapshot.cs index 50db7633..6ab55f0e 100644 --- a/src/Persistence/Migrations/TraleDbContextModelSnapshot.cs +++ b/src/Persistence/Migrations/TraleDbContextModelSnapshot.cs @@ -507,8 +507,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bigint"); b.Property("Variant") - .HasMaxLength(10) - .HasColumnType("character varying(10)"); + .HasMaxLength(32) + .HasColumnType("character varying(32)"); b.HasKey("Id"); diff --git a/src/Trale/HostedServices/HourlyNotificationWorker.cs b/src/Trale/HostedServices/HourlyNotificationWorker.cs index b4ec4347..16543c5f 100644 --- a/src/Trale/HostedServices/HourlyNotificationWorker.cs +++ b/src/Trale/HostedServices/HourlyNotificationWorker.cs @@ -67,12 +67,20 @@ public static TimeSpan ComputeDelayUntilNextHour(DateTime nowUtc) /// failure doesn't block the others. The dispatcher's own logic decides whether the /// current tick is actually a send-worthy moment. /// - public async Task RunOnceAsync(CancellationToken ct) + public Task RunOnceAsync(CancellationToken ct) => RunOnceAsync(DateTime.UtcNow, ct); + + /// + /// Same fan-out for a given moment. The holiday dispatcher only checks "is today a holiday", + /// so the 09:00 Tbilisi guard lives here: without it the push went out on the first tick of + /// the Tbilisi day, at night. + /// + public async Task RunOnceAsync(DateTime nowUtc, CancellationToken ct) { await using var scope = scopeFactory.CreateAsyncScope(); var sp = scope.ServiceProvider; - await DispatchSafelyAsync(sp, "Holiday", ct); + if (Application.Notifications.TbilisiMorningWindow.IsHolidayPushHour(nowUtc)) + await DispatchSafelyAsync(sp, "Holiday", ct); await DispatchSafelyAsync(sp, "Coins", ct); await DispatchSafelyAsync(sp, "Streak", ct); await DispatchSafelyAsync(sp, "FirstOpenReminder", ct); diff --git a/src/Trale/miniapp-src/src/analytics/appEvents.test.ts b/src/Trale/miniapp-src/src/analytics/appEvents.test.ts index c5647026..0396603c 100644 --- a/src/Trale/miniapp-src/src/analytics/appEvents.test.ts +++ b/src/Trale/miniapp-src/src/analytics/appEvents.test.ts @@ -22,6 +22,17 @@ describe('app events tracker', () => { expect(batches[0][0].value).toBeGreaterThanOrEqual(0) }) + it('takes the push tag from the button address when there is no start_param', () => { + window.history.replaceState(null, '', '/?screen=feed&src=push_coins') + appEvents.opened() + expect(batches[0][0]).toMatchObject({ event: 'app_open', startParam: 'push_coins' }) + window.history.replaceState(null, '', '/?src=bad%20tag') + __setAppEventSender(b => { batches.push(b) }) + appEvents.opened() + expect(batches[1][0].startParam).toBeUndefined() + window.history.replaceState(null, '', '/') + }) + it('marks a load where the server did not know the person', () => { appEvents.ready(false) appEvents.ready(true) diff --git a/src/Trale/miniapp-src/src/analytics/appEvents.ts b/src/Trale/miniapp-src/src/analytics/appEvents.ts index 3963b481..c2be0335 100644 --- a/src/Trale/miniapp-src/src/analytics/appEvents.ts +++ b/src/Trale/miniapp-src/src/analytics/appEvents.ts @@ -50,6 +50,18 @@ function enabled(): boolean { } catch { return false } } +/** + * По какой ссылке открыли: start_param Telegram (t.me/…?startapp=…) или метка ?src= на кнопке пуша + * (push_holiday, push_return_miss…) — так видно, сколько людей вернулось по каждому пушу. + */ +function openSource(t: any): string | null { + try { + if (t?.initDataUnsafe?.start_param) return String(t.initDataUnsafe.start_param) + const src = new URLSearchParams(window.location.search).get('src') + return src && /^[a-z0-9_-]{1,64}$/.test(src) ? src : null + } catch { return null } +} + function sinceLoad(): number { try { return Math.round(performance.now()) } catch { return 0 } } @@ -100,7 +112,7 @@ export const appEvents = { event: 'app_open', value: sinceLoad(), ...(t?.platform ? { platform: String(t.platform) } : {}), - ...(t?.initDataUnsafe?.start_param ? { startParam: String(t.initDataUnsafe.start_param) } : {}) + ...(openSource(t) ? { startParam: openSource(t)! } : {}) }, true) }, /** Первый экран получил данные; target «no-auth» — сервер не узнал человека, приложение открылось гостем. */ diff --git a/tests/Infrastructure.UnitTests/HostedServices/HourlyNotificationWorkerTests.cs b/tests/Infrastructure.UnitTests/HostedServices/HourlyNotificationWorkerTests.cs index b9d08884..24093647 100644 --- a/tests/Infrastructure.UnitTests/HostedServices/HourlyNotificationWorkerTests.cs +++ b/tests/Infrastructure.UnitTests/HostedServices/HourlyNotificationWorkerTests.cs @@ -21,6 +21,9 @@ namespace Infrastructure.UnitTests.HostedServices; [TestFixture] public class HourlyNotificationWorkerTests { + // 09:00 Tbilisi — the only hour the holiday dispatcher runs. + private static readonly DateTime HolidayHour = new(2026, 11, 4, 5, 0, 0, DateTimeKind.Utc); + private static HourlyNotificationWorker BuildWorker(IServiceScopeFactory scopeFactory) => new(scopeFactory, NullLogger.Instance); @@ -84,13 +87,29 @@ public async Task RunOnceAsync_InvokesAllThreeDispatchersOnce() var sp = BuildProvider(holiday.Object, coins.Object, streak.Object); var worker = BuildWorker(sp.GetRequiredService()); - await worker.RunOnceAsync(CancellationToken.None); + await worker.RunOnceAsync(HolidayHour, CancellationToken.None); holiday.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); coins.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); streak.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); } + [Test] + public async Task RunOnceAsync_OutsideTheTbilisiMorning_SkipsTheHolidayPush() + { + // 20:00 UTC on 3 Nov = 00:00 Tbilisi on 4 Nov (Tbilisoba): the push used to go out at night. + var holiday = new Mock(MockBehavior.Strict); + var coins = new Mock(); + var streak = new Mock(); + var sp = BuildProvider(holiday.Object, coins.Object, streak.Object); + var worker = BuildWorker(sp.GetRequiredService()); + + await worker.RunOnceAsync(new DateTime(2026, 11, 3, 20, 0, 0, DateTimeKind.Utc), CancellationToken.None); + + holiday.Verify(s => s.DispatchAsync(It.IsAny()), Times.Never); + coins.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); + } + [Test] public async Task RunOnceAsync_InvokesTheFirstOpenReminder_EvenWhenAnEarlierDispatcherThrows() { @@ -104,7 +123,7 @@ public async Task RunOnceAsync_InvokesTheFirstOpenReminder_EvenWhenAnEarlierDisp services.AddSingleton(reminder.Object); var worker = BuildWorker(services.BuildServiceProvider().GetRequiredService()); - await worker.RunOnceAsync(CancellationToken.None); + await worker.RunOnceAsync(HolidayHour, CancellationToken.None); reminder.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); } @@ -125,7 +144,7 @@ public async Task RunOnceAsync_WhenHolidayThrows_StillInvokesCoinsAndStreak() var sp = BuildProvider(holiday.Object, coins.Object, streak.Object); var worker = BuildWorker(sp.GetRequiredService()); - await Should.NotThrowAsync(() => worker.RunOnceAsync(CancellationToken.None)); + await Should.NotThrowAsync(() => worker.RunOnceAsync(HolidayHour, CancellationToken.None)); coins.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); streak.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); } @@ -145,7 +164,7 @@ public async Task RunOnceAsync_WhenCoinsThrows_StreakStillRuns() var sp = BuildProvider(holiday.Object, coins.Object, streak.Object); var worker = BuildWorker(sp.GetRequiredService()); - await Should.NotThrowAsync(() => worker.RunOnceAsync(CancellationToken.None)); + await Should.NotThrowAsync(() => worker.RunOnceAsync(HolidayHour, CancellationToken.None)); streak.Verify(s => s.DispatchAsync(It.IsAny()), Times.Once); } @@ -166,7 +185,7 @@ public async Task RunOnceAsync_PropagatesHostShutdownCancellation() var sp = BuildProvider(holiday.Object, coins.Object, streak.Object); var worker = BuildWorker(sp.GetRequiredService()); - await Should.ThrowAsync(() => worker.RunOnceAsync(cts.Token)); + await Should.ThrowAsync(() => worker.RunOnceAsync(HolidayHour, cts.Token)); } [Test] diff --git a/tests/Infrastructure.UnitTests/Telegram/ReferralBonusTextTests.cs b/tests/Infrastructure.UnitTests/Telegram/ReferralBonusTextTests.cs index a9fcccec..9bea1b70 100644 --- a/tests/Infrastructure.UnitTests/Telegram/ReferralBonusTextTests.cs +++ b/tests/Infrastructure.UnitTests/Telegram/ReferralBonusTextTests.cs @@ -66,7 +66,7 @@ public async System.Threading.Tasks.Task SaysWhatWasGrantedAndUntilWhen(Referral Text(sent.Single()).ShouldBe(expected); var markup = sent.Single().GetType().GetProperty("ReplyMarkup")?.GetValue(sent.Single()) as InlineKeyboardMarkup; - markup!.InlineKeyboard.Single().Single().WebApp!.Url.ShouldBe("https://test.tralebot.com/"); + markup!.InlineKeyboard.Single().Single().WebApp!.Url.ShouldBe("https://test.tralebot.com/?src=push_referral"); } [Test] diff --git a/tests/Infrastructure.UnitTests/Telegram/TelegramNotificationServiceTests.cs b/tests/Infrastructure.UnitTests/Telegram/TelegramNotificationServiceTests.cs index 59014203..c3c40cb5 100644 --- a/tests/Infrastructure.UnitTests/Telegram/TelegramNotificationServiceTests.cs +++ b/tests/Infrastructure.UnitTests/Telegram/TelegramNotificationServiceTests.cs @@ -89,7 +89,7 @@ public async Task SendDailyReturnPushAsync_MessageContainsCorrectDeepLinkUrl() var button = markup.InlineKeyboard.SelectMany(r => r).Single(); button.WebApp.ShouldNotBeNull(); // Deep-links straight into the lesson screen, not just the app. - button.WebApp.Url.ShouldBe($"{TestHost}/?screen=practice&moduleId=alphabet&lessonId=7"); + button.WebApp.Url.ShouldBe($"{TestHost}/?screen=practice&moduleId=alphabet&lessonId=7&src=push_return_miss"); } [Test] @@ -102,7 +102,7 @@ public async Task SendDailyReturnPushAsync_FeedVariant_DeepLinksToFeedScreen() var button = ReflectMarkup(captured.Single())!.InlineKeyboard.SelectMany(r => r).Single(); button.WebApp.ShouldNotBeNull(); - button.WebApp.Url.ShouldBe($"{TestHost}/?screen=feed"); + button.WebApp.Url.ShouldBe($"{TestHost}/?screen=feed&src=push_return_feed"); } [Test] @@ -260,7 +260,7 @@ public async Task SendCoinsStalePushAsync_KeyboardOpensFeedScreen() markup.ShouldNotBeNull(); var button = markup.InlineKeyboard.SelectMany(r => r).Single(); button.WebApp.ShouldNotBeNull(); - button.WebApp.Url.ShouldBe($"{TestHost}/?screen=feed"); + button.WebApp.Url.ShouldBe($"{TestHost}/?screen=feed&src=push_coins"); button.Url.ShouldBeNull(); // WebApp button, not a plain URL } diff --git a/tests/IntegrationTests/Notifications/HolidayNotificationServiceTests.cs b/tests/IntegrationTests/Notifications/HolidayNotificationServiceTests.cs index 06a20b43..9e353b99 100644 --- a/tests/IntegrationTests/Notifications/HolidayNotificationServiceTests.cs +++ b/tests/IntegrationTests/Notifications/HolidayNotificationServiceTests.cs @@ -150,6 +150,33 @@ public async Task DispatchAsync_ConcurrentRuns_RecordsExactlyOneTriggerPerUser() because: "concurrent dispatch runs must collapse to a single holiday trigger via the unique (UserId, Source) index"); } + [Test] + public async Task DispatchAsync_EveryRealHoliday_FitsTheTriggerRowAndIsSent() + { + // The holiday key is stored as the trigger variant: a key longer than the column + // ("svetitskhovloba", "independence") failed the insert and nobody got that push. + var holidays = new HolidayCalendarService().AllHolidays(); + for (var i = 0; i < holidays.Count; i++) + { + var telegramId = HolidayTelegramId + 100 + i; + await SeedActiveUserAsync(telegramId); + + await using (var scope = WithStubbedHoliday(holidays[i]).Services.CreateAsyncScope()) + { + var dispatcher = scope.ServiceProvider.GetRequiredService(); + await dispatcher.DispatchAsync(CancellationToken.None); + } + + await using var verifyScope = _testServer.Services.CreateAsyncScope(); + var db = verifyScope.ServiceProvider.GetRequiredService(); + var variant = await db.NotificationTriggers + .Where(t => t.UserId == telegramId && t.Source == "holiday") + .Select(t => t.Variant) + .SingleOrDefaultAsync(); + variant.Should().Be(holidays[i].Key); + } + } + private async Task SeedActiveUserAsync(long telegramId, bool notificationsEnabled = true) { await using var scope = _testServer.Services.CreateAsyncScope(); diff --git a/tests/IntegrationTests/Onboarding/FirstMinutesTests.cs b/tests/IntegrationTests/Onboarding/FirstMinutesTests.cs index bde65115..fd34cdcd 100644 --- a/tests/IntegrationTests/Onboarding/FirstMinutesTests.cs +++ b/tests/IntegrationTests/Onboarding/FirstMinutesTests.cs @@ -158,7 +158,7 @@ public async Task Newcomer_who_did_not_open_the_mini_app_is_reminded_once_a_day_ message.Text.Should().Be("Это Бомбора 🐶 Первая грузинская буква всё ещё ждёт тебя — это одна минута. Заглянешь?"); var button = Buttons(message).Should().ContainSingle().Subject; button.Text.Should().Be("🚀 Узнать первую букву"); - button.WebApp!.Url.Should().Be($"{SignedMiniApp.Host}/"); + button.WebApp!.Url.Should().Be($"{SignedMiniApp.Host}/?src=push_first_open"); } [Test]