Phase 21.6: pg_cron teacher email-digest infrastructure#300
Conversation
New scheduled-digest edge function + migration 059 wire pg_net's net.http_post into a nightly cron.schedule job, the first pg_cron job in this repo to call out to an edge function rather than run plain SQL. Adds a Settings opt-in (digestEmailEnabled) and a get_pending_moderation_count() SQL helper as the first digest payload (pending second-marker disputes on the Moderation Queue), reusing notify-student-graded/-message's generateLink placeholder mailer since no real transactional-email template exists yet. Regenerates supabase/bootstrap.sql, which had drifted out of sync with migrations since 035. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds an opt-in nightly teacher email digest using ChangesTeacher email digest
Supabase bootstrap consolidation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Sequence Diagram(s)sequenceDiagram
participant pg_cron
participant pg_net
participant scheduled-digest
participant Supabase
participant Auth
pg_cron->>pg_net: Trigger teacher-email-digest at 06:00 UTC
pg_net->>scheduled-digest: POST with service-role token
scheduled-digest->>Supabase: Fetch opted-in profiles
scheduled-digest->>Supabase: Call get_pending_moderation_count
scheduled-digest->>Auth: Generate magic link for qualifying recipients
scheduled-digest-->>pg_net: Return sent, skipped, and errors
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/SELF_HOSTING_OPS.md`:
- Around line 104-118: In the “Teacher email digest job” section, add a blank
line immediately before the opening sql fence and immediately after its closing
fence, keeping the SQL content and surrounding prose unchanged.
- Around line 49-57: Update the Docker command code blocks in the self-hosting
operations instructions by adding blank lines immediately before and after each
fenced block, including those under the db_migrate and “Restart remaining
services” sections, to satisfy MD031.
- Around line 82-94: Update the fenced code blocks in the self-hosting
operations documentation: label the PostgreSQL configuration block with the ini
language and add a blank line before the SQL fence under “Grant usage,”
preserving the existing contents.
In `@supabase/functions/scheduled-digest/index.ts`:
- Around line 44-68: Update the scheduled digest flow around generateLink and
the sent counter so it does not treat link generation as email delivery: either
add the actual digest mail-delivery step and increment sent only after it
succeeds, or revise the Settings/README copy and counter semantics to describe
link generation rather than delivered notifications.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 3f3bac18-eee1-4818-a5e4-adfb2e6df560
📒 Files selected for processing (13)
README.mddocs/SELF_HOSTING_OPS.mdsrc/locales/de.jsonsrc/locales/en.jsonsrc/locales/es.jsonsrc/locales/fr.jsonsrc/locales/nl.jsonsrc/pages/DocsPage.tsxsrc/pages/SettingsPage.tsxsrc/types/index.tssupabase/bootstrap.sqlsupabase/functions/scheduled-digest/index.tssupabase/migrations/059_scheduled_digest.sql
Blank lines around fenced code blocks, language tag on the postgresql.conf snippet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Summary
scheduled-digestedge function + migration059_scheduled_digest.sqlwirepg_net'snet.http_postinto a nightlycron.schedulejob — the firstpg_cronjob in this repo that calls out to an edge function rather than running plain SQL.get_pending_moderation_count()SQL helper approximates the Moderation Queue's pending-dispute count as the first digest payload.digestEmailEnabled), same UX pattern as the existing student-notification toggles.generateLinkmagiclink placeholder mailer already used bynotify-student-graded/notify-student-message(no real transactional-email template exists in this repo yet for any recipient).DocsPage.tsx,README.md,docs/SELF_HOSTING_OPS.md(new GUC setup steps fornet.http_post's project URL/service-role key).supabase/bootstrap.sql, which had drifted out of sync with migrations since 035 — this pulls in every migration since then, not just this PR's.Test plan
npx tsc --noEmitcleannpm run lintclean (0 errors, pre-existing warnings only)npx prettier --checkclean on all touched filesnpx vitest run— 2435/2435 passinguser_settings.settings.digestEmailEnabledpersists (Supabase-connected only)app.settings.*GUCs, deployscheduled-digest, confirmcron.job_run_detailsshows a successful nightly run🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation