4.4 KiB
Plan: One-time (non-expiring) IELTS + DUOLINGO subscriptions
Goal
Treat IELTS and DUOLINGO plan categories as one-time purchases that never expire. LEARN_ENGLISH continues to use duration-based expiry and 7-day reminders.
Approach
Extend the existing DUOLINGO lifetime pattern (far-future expires_at sentinel 9999-12-31) to also cover IELTS. Do not make expires_at nullable or add a LIFETIME duration unit.
Lifetime logic already funnels through domain.IsLifetimeSubscriptionCategory → CalculateSubscriptionExpiresAt. Checkout, subscribe, admin grant/extend, and activated-email copy already call those helpers.
Product decisions (assumed)
- Admin create/edit plan: hide duration for IELTS/DUOLINGO; show One-time · Never expires; still POST
duration_value=1,duration_unit=YEARso API validation passes. - Admin Extend: hide/disable for lifetime-category active subscriptions (already lifetime).
- Migration: backfill existing IELTS
user_subscriptionsto the sentinel (same shape as000079for DUOLINGO; unscoped by status).
Backend (Yimaru-BackEnd)
1. Lifetime predicate
File: internal/domain/subscriptions.go
- Update comments on
LifetimeSubscriptionExpiresAt/CalculateSubscriptionExpiresAt. - Change
IsLifetimeSubscriptionCategoryto return true forIELTSandDUOLINGO(usenormalizeSubscriptionCategory).
No changes needed in subscribe/checkout/admin apply services — they already call CalculateSubscriptionExpiresAt.
2. Expiry sweep queries
File: db/query/subscriptions.sql
In GetExpiredSubscriptions and GetExpiringSubscriptions, replace:
AND sp.category <> 'DUOLINGO'
with:
AND sp.category = 'LEARN_ENGLISH'
(ListLearnEnglishSubscriptionsExpiringInSevenDays already filters LEARN_ENGLISH only.)
3. Regenerate sqlc
sqlc generate
Updates gen/db/subscriptions.sql.go.
4. Migration 000099 (next after 000098)
Up (db/migrations/000099_ielts_lifetime_subscriptions.up.sql) — mirror 000079:
UPDATE user_subscriptions us
SET
expires_at = TIMESTAMPTZ '9999-12-31 23:59:59+00',
updated_at = CURRENT_TIMESTAMP
FROM subscription_plans sp
WHERE us.plan_id = sp.id
AND sp.category = 'IELTS'
AND us.expires_at < TIMESTAMPTZ '9999-01-01 00:00:00+00';
Down: no-op (same as 000079).
5. Tests
| File | Change |
|---|---|
internal/domain/subscriptions_test.go |
Add IELTS lifetime expiry test; optional table-driven IsLifetimeSubscriptionCategory |
internal/services/learnernotifications/subscription_test.go |
Expect IELTS lifetime=true / empty date label (today expects date) |
Admin (Yimaru-Admin)
1. Shared helpers
File: src/lib/subscriptionPlans.ts
isLifetimePlanCategory(category)→ true forIELTS/DUOLINGOLIFETIME_DURATION_DEFAULT = { duration_value: 1, duration_unit: "YEAR" }formatPlanDuration: ifplan.categoryis lifetime →"One-time"(widen signature to accept optionalcategory)
2. Plan dialogs
| File | Change |
|---|---|
CreateSubscriptionPlanDialog.tsx |
When lifetime category: hide duration inputs; show “One-time · Never expires”; force default duration in payload |
EditSubscriptionPlanDialog.tsx |
Same (category already read-only) |
3. User subscription UX
| File | Change |
|---|---|
UserSubscriptionsSection.tsx |
Lifetime expiry → Never expires; suppress days-left; hide/disable Extend when isLifetimePlanCategory(plan_category) |
ExtendSubscriptionDialog.tsx |
Safety copy if opened for lifetime (optional) |
Call sites of formatPlanDuration |
Pass category so lists/dashboard/grant show “One-time” |
Out of scope
- Nullable
expires_at - New
LIFETIME/ONE_TIMEduration unit or DB CHECK change - Reactivating historically
EXPIREDIELTS rows (migration only updatesexpires_at, notstatus) - Changing exam-prep access gate flag
Verification
go test ./internal/domain/... ./internal/services/learnernotifications/...sqlc generate+go build ./...- Run migration up; IELTS rows show
expires_at = 9999-12-31 - New IELTS/DUOLINGO subscribe/grant → sentinel expiry; LEARN_ENGLISH → real duration date
- Admin create IELTS plan → duration hidden, save succeeds
- User subscriptions panel → “Never expires”, no Extend for lifetime active sub
- 7-day reminder / GetExpiring still only LEARN_ENGLISH