Skip to content

Phase 21.6: pg_cron teacher email-digest infrastructure#300

Merged
NesiciCoding merged 2 commits into
mainfrom
claude/phase-21-planning-64b67b
Jul 13, 2026
Merged

Phase 21.6: pg_cron teacher email-digest infrastructure#300
NesiciCoding merged 2 commits into
mainfrom
claude/phase-21-planning-64b67b

Conversation

@NesiciCoding

@NesiciCoding NesiciCoding commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Last item of Phase 21 (see wiki Roadmap.md's 21.6): a new scheduled-digest edge function + migration 059_scheduled_digest.sql wire pg_net's net.http_post into a nightly cron.schedule job — the first pg_cron job in this repo that calls out to an edge function rather than running plain SQL.
  • New get_pending_moderation_count() SQL helper approximates the Moderation Queue's pending-dispute count as the first digest payload.
  • New Settings → Email Digest opt-in (digestEmailEnabled), same UX pattern as the existing student-notification toggles.
  • Reuses the generateLink magiclink placeholder mailer already used by notify-student-graded/notify-student-message (no real transactional-email template exists in this repo yet for any recipient).
  • Docs updated per the repo's docs-maintenance rule: DocsPage.tsx, README.md, docs/SELF_HOSTING_OPS.md (new GUC setup steps for net.http_post's project URL/service-role key).
  • Regenerated 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.
  • i18n keys added to all 5 locales.

Test plan

  • npx tsc --noEmit clean
  • npm run lint clean (0 errors, pre-existing warnings only)
  • npx prettier --check clean on all touched files
  • npx vitest run — 2435/2435 passing
  • Manual: enable Settings → Email Digest, verify user_settings.settings.digestEmailEnabled persists (Supabase-connected only)
  • Manual (self-hosted/Cloud SQL editor): set the two app.settings.* GUCs, deploy scheduled-digest, confirm cron.job_run_details shows a successful nightly run

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added an optional nightly teacher email digest for pending second-marker moderation disputes.
    • Added a Teaching settings option to enable or disable the digest.
    • Added localized settings and guidance across supported languages.
    • Added scheduled digest support for self-hosted deployments with SMTP and server configuration.
  • Documentation

    • Expanded self-hosting and upgrade guidance for scheduled jobs, database setup, verification, and troubleshooting.

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>
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@NesiciCoding, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d9fe4fc7-9f55-496f-88ce-67e656bdc08d

📥 Commits

Reviewing files that changed from the base of the PR and between 29bff0b and 8174edb.

📒 Files selected for processing (1)
  • docs/SELF_HOSTING_OPS.md
📝 Walkthrough

Walkthrough

Adds an opt-in nightly teacher email digest using pg_cron, pg_net, a Supabase Edge Function, and pending-moderation queries. It also updates UI translations and self-hosting documentation, while expanding bootstrap.sql with consolidated schema, authorization, backup, realtime, and migration bookkeeping changes.

Changes

Teacher email digest

Layer / File(s) Summary
Digest setting and guidance
src/types/index.ts, src/pages/SettingsPage.tsx, src/pages/DocsPage.tsx, src/locales/*.json
Adds the optional digest setting, Teaching-tab checkbox, localized descriptions, and updated co-grading guidance.
Digest count and scheduling
supabase/migrations/059_scheduled_digest.sql, supabase/bootstrap.sql
Adds the service-role-only pending moderation count function and schedules the 06:00 UTC pg_cron job that calls scheduled-digest.
Digest recipient processing
supabase/functions/scheduled-digest/index.ts
Validates authorization, loads opted-in profiles, checks pending disputes, generates magic links, and returns sent/skipped/error counts.
Deployment and operations guidance
README.md, docs/SELF_HOSTING_OPS.md
Documents digest deployment, required database settings, pg_cron/pg_net configuration, migration execution, and verification steps.

Supabase bootstrap consolidation

Layer / File(s) Summary
Authentication and diagnostic schema
supabase/bootstrap.sql
Adds diagnostic and audit tables, updates profile role handling, tightens policies, and restricts migration visibility.
Marketplace and assignment schema
supabase/bootstrap.sql
Adds marketplace, grading, assignment, template, CEFR, policy, grant, and realtime changes.
Messaging, flashcards, and tests
supabase/bootstrap.sql
Adds messaging and flashcard tables, ownership helpers, assignment tracking, backup exports, grants, and realtime entries.
News flashes and rubric versions
supabase/bootstrap.sql
Adds news-flash ownership/policies, student helpers, rubric versions, and backup export support.
Bootstrap migration bookkeeping
supabase/bootstrap.sql
Extends the recorded migration filename list through the latest migration.

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
Loading

Poem

A bunny hops where cron jobs run,
At dawn the digest greets the sun.
Disputes are counted, links take flight,
Teachers get reminders through the night.
The settings checkbox joins the show—
And self-hosting docs now glow!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding pg_cron-based teacher email-digest infrastructure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/phase-21-planning-64b67b

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 69.39% (🎯 65%) 7931 / 11428
🔵 Statements 67.61% (🎯 65%) 9039 / 13369
🔵 Functions 60.32% (🎯 60%) 2781 / 4610
🔵 Branches 59.99% (🎯 58%) 6623 / 11039
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/pages/DocsPage.tsx 100% 100% 100% 100%
src/pages/SettingsPage.tsx 31.07% 36.89% 32.45% 33.59% 49, 119, 159, 166, 168-171, 183-302, 314-317, 321, 327-341, 353, 367, 454-455, 525, 560-618, 686-735, 813-911, 1044, 1071-1197, 1260-1679, 1791-2089
Generated in workflow #865 for commit 8174edb by the Vitest Coverage Report Action

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 722fd00 and 29bff0b.

📒 Files selected for processing (13)
  • README.md
  • docs/SELF_HOSTING_OPS.md
  • src/locales/de.json
  • src/locales/en.json
  • src/locales/es.json
  • src/locales/fr.json
  • src/locales/nl.json
  • src/pages/DocsPage.tsx
  • src/pages/SettingsPage.tsx
  • src/types/index.ts
  • supabase/bootstrap.sql
  • supabase/functions/scheduled-digest/index.ts
  • supabase/migrations/059_scheduled_digest.sql

Comment thread docs/SELF_HOSTING_OPS.md
Comment thread docs/SELF_HOSTING_OPS.md
Comment thread docs/SELF_HOSTING_OPS.md
Comment thread supabase/functions/scheduled-digest/index.ts
Blank lines around fenced code blocks, language tag on the postgresql.conf
snippet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@NesiciCoding
NesiciCoding merged commit 94a57ff into main Jul 13, 2026
9 checks passed
@NesiciCoding
NesiciCoding deleted the claude/phase-21-planning-64b67b branch July 13, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant